NDCube

class ndcube.NDCube(data, wcs, uncertainty=None, mask=None, meta=None, unit=None, extra_coords=None, copy=False, missing_axis=None, **kwargs)[source] [edit on github]

Bases: ndcube.mixins.NDCubeSlicingMixin, ndcube.mixins.NDCubePlotMixin, astropy.nddata.mixins.ndarithmetic.NDArithmeticMixin, ndcube.ndcube.NDCubeBase

Class representing N dimensional cubes. Extra arguments are passed on to NDData.

Parameters:
  • data (numpy.ndarray) – The array holding the actual data in this object.
  • wcs (ndcube.wcs.wcs.WCS) – The WCS object containing the axes’ information
  • uncertainty (any type, optional) – Uncertainty in the dataset. Should have an attribute uncertainty_type that defines what kind of uncertainty is stored, for example “std” for standard deviation or “var” for variance. A metaclass defining such an interface is NDUncertainty - but isn’t mandatory. If the uncertainty has no such attribute the uncertainty is stored as UnknownUncertainty. Defaults to None.
  • mask (any type, optional) – Mask for the dataset. Masks should follow the numpy convention that valid data points are marked by False and invalid ones with True. Defaults to None.
  • meta (dict-like object, optional) – Additional meta information about the dataset. If no meta is provided an empty collections.OrderedDict is created. Default is None.
  • unit (Unit-like or str, optional) – Unit for the dataset. Strings that can be converted to a Unit are allowed. Default is None.
  • extra_coords (iterable of tuple, each with three entries) – (str, int, astropy.units.quantity or array-like) Gives the name, axis of data, and values of coordinates of a data axis not included in the WCS object.
  • copy (bool, optional) – Indicates whether to save the arguments as copy. True copies every attribute before saving it while False tries to save every parameter as reference. Note however that it is not always possible to save the input as reference. Default is False.
  • missing_axis (list of bool) – Designates which axes in wcs object do not have a corresponding axis is the data. True means axis is “missing”, False means axis corresponds to a data axis. Ordering corresponds to the axis ordering in the WCS object, i.e. reverse of data. For example, say the data’s y-axis corresponds to latitude and x-axis corresponds to wavelength. In order the convert the y-axis to latitude the WCS must contain a “missing” longitude axis as longitude and latitude are not separable.

Attributes Summary

dimensions Returns a named tuple with two attributes – ‘shape’ gives the shape of the data dimensions; ‘axis_types’ gives the WCS axis type of each dimension, e.g.
extra_coords Dictionary of extra coords where each key is the name of an extra coordinate supplied by user during instantiation of the NDCube.
world_axis_physical_types Returns an iterable of strings describing the physical type for each world axis.

Methods Summary

axis_world_coords(*axes) Returns WCS coordinate values of all pixels for all axes.
crop_by_coords(min_coord_values, interval_widths) Crops an NDCube given minimum values and interval widths along axes.
crop_by_extra_coord(min_coord_value, …) Crops an NDCube given a minimum value and interval width along an extra coord.
pixel_to_world(*quantity_axis_list) Convert a pixel coordinate to a data (world) coordinate by using all_pix2world.
world_to_pixel(*quantity_axis_list) Convert a world coordinate to a data (pixel) coordinate by using all_world2pix.

Attributes Documentation

dimensions

Returns a named tuple with two attributes – ‘shape’ gives the shape of the data dimensions; ‘axis_types’ gives the WCS axis type of each dimension, e.g. WAVE or HPLT-TAN for wavelength of helioprojected latitude.

extra_coords

Dictionary of extra coords where each key is the name of an extra coordinate supplied by user during instantiation of the NDCube.

The value of each key is itself a dictionary with the following keys:
‘axis’: int
The number of the data axis to which the extra coordinate corresponds.
‘value’: astropy.units.Quantity or array-like
The value of the extra coordinate at each pixel/array element along the
corresponding axis (given by the ‘axis’ key, above). Note this means
that the length of ‘value’ must be equal to the length of the data axis
to which is corresponds.
world_axis_physical_types

Returns an iterable of strings describing the physical type for each world axis.

The strings conform to the International Virtual Observatory Alliance standard, UCD1+ controlled Vocabulary. For a description of the standard and definitions of the different strings and string components, see http://www.ivoa.net/documents/latest/UCDlist.html.

Methods Documentation

axis_world_coords(*axes)[source] [edit on github]

Returns WCS coordinate values of all pixels for all axes.

Parameters:axes (int or str, or multiple int or str) – Axis number in numpy ordering or unique substring of world_axis_physical_types of axes for which real world coordinates are desired. axes=None implies all axes will be returned.
Returns:axes_coords (list of astropy.units.Quantity) – Real world coords for axes in order requested by user.

Example

>>> NDCube.all_world_coords(('lat', 'lon')) 
>>> NDCube.all_world_coords(2) 
crop_by_coords(min_coord_values, interval_widths)[source] [edit on github]

Crops an NDCube given minimum values and interval widths along axes.

Parameters:
  • min_coord_values (iterable of astropy.units.Quantity) – The minimum desired values along each relevant axis after cropping described in physical units consistent with the NDCube’s wcs object. The length of the iterable must equal the number of data dimensions and must have the same order as the data.
  • interval_widths (iterable of astropy.units.Quantity) – The width of the region of interest in each dimension in physical units consistent with the NDCube’s wcs object. The length of the iterable must equal the number of data dimensions and must have the same order as the data.
Returns:

result (NDCube)

crop_by_extra_coord(min_coord_value, interval_width, coord_name)[source] [edit on github]

Crops an NDCube given a minimum value and interval width along an extra coord.

Parameters:
  • min_coord_value (Single value astropy.units.Quantity) – The minimum desired value of the extra coord after cropping. Unit must be consistent with the extra coord on which cropping is based.
  • interval_width (Single value astropy.units.Quantity) – The width of the interval along the extra coord axis in physical units consistent with the extra coord. Unit must be consistent with the extra coord on which cropping is based.
  • extra_coord (str) – Name of extra coordinate.
Returns:

result (ndcube.NDCube)

pixel_to_world(*quantity_axis_list)[source] [edit on github]

Convert a pixel coordinate to a data (world) coordinate by using all_pix2world.

Parameters:
  • quantity_axis_list (iterable) – An iterable of Quantity with unit as pixel pix. Note that these quantities must be entered as separate arguments, not as one list.
  • origin (int.) – Origin of the top-left corner. i.e. count from 0 or 1. Normally, origin should be 0 when passing numpy indices, or 1 if passing values from FITS header or map attributes. See wcs_pix2world for more information. Default is 0.
Returns:

coord (list) – A list of arrays containing the output coordinates reverse of the wcs axis order.

world_to_pixel(*quantity_axis_list)[source] [edit on github]

Convert a world coordinate to a data (pixel) coordinate by using all_world2pix.

Parameters:
  • quantity_axis_list (iterable) – A iterable of Quantity. Note that these quantities must be entered as separate arguments, not as one list.
  • origin (int) – Origin of the top-left corner. i.e. count from 0 or 1. Normally, origin should be 0 when passing numpy indices, or 1 if passing values from FITS header or map attributes. See wcs_world2pix for more information. Default is 0.
Returns:

coord (list) – A list of arrays containing the output coordinates reverse of the wcs axis order.