NDCubeBase#
- class ndcube.NDCubeBase(
- data,
- wcs=None,
- uncertainty=None,
- mask=None,
- meta=None,
- unit=None,
- copy=False,
- **kwargs,
- Bases: - NDCubeABC,- NDData,- NDCubeSlicingMixin- Class representing N-D data described by a single array and set of WCS transformations. - Parameters:
- data (array-like or - astropy.nddata.NDData) – The array holding the actual data in this object.
- wcs ( - astropy.wcs.wcsapi.BaseLowLevelWCS,- astropy.wcs.wcsapi.BaseHighLevelWCS, optional) – The WCS object containing the axes’ information, optional only if- datais an- astropy.nddata.NDDataobject.
- uncertainty (Any, 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, optional) – Mask for the dataset. Masks should follow the numpy convention that valid data points are marked by - Falseand 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 dictionary is created. 
- unit (Unit-like or - str, optional) – Unit for the dataset. Strings that can be converted to a- Unitare allowed. Default is- Nonewhich results in dimensionless units.
- copy (bool, optional) – Indicates whether to save the arguments as copy. - Truecopies every attribute before saving it while- Falsetries to save every parameter as reference. Note however that it is not always possible to save the input as reference. Default is- False.
 
 - Attributes Summary - Returns the WCS physical types that vary along each array axis. - The WCS transform for the NDCube, including the coordinates specified in - .extra_coords.- ndarray- like- Coordinates not described by - NDCubeABC.wcswhich vary along one or more axes.- Coordinate metadata which applies to the whole cube. - Mask for the dataset, if any. - Image representation of the PSF for the dataset. - Unitful representation of the NDCube data. - Uncertainty in the dataset, if any. - Unit for the dataset, if any. - A world coordinate system (WCS) for the dataset, if any. - Methods Summary - axis_world_coords(*axes[, pixel_corners, wcs])- Returns objects representing the world coordinates of pixel centers for a desired axes. - axis_world_coords_values(*axes[, ...])- Returns the world coordinate values of all pixels for desired axes. - crop(*points[, wcs, keepdims])- Crop using real world coordinates. - crop_by_values(*points[, units, wcs, keepdims])- Crop using real world coordinates. - explode_along_axis(axis)- Separates slices of NDCubes along a given axis into an NDCubeSequence of (N-1)DCubes. - reproject_to(target_wcs[, algorithm, ...])- Reprojects the instance to the coordinates described by another WCS object. - Attributes Documentation - array_axis_physical_types#
 - combined_wcs#
 - data#
- ndarray- like
- The stored dataset. 
 - Notes - It is possible to set the - .dataattribute on a- NDCubewith an array-like object of the same shape. However, this is really only intended for replacing the data with a different object representing the same physical data as no other properties of the cube will be changed, such as uncertainty or unit.
 - dimensions#
 - extra_coords#
 - global_coords#
 - mask#
- Mask for the dataset, if any. - Masks should follow the - numpyconvention that valid data points are marked by- Falseand invalid ones with- True.- Type:
- any type 
 
 - meta = None#
 - psf#
 - quantity#
- Unitful representation of the NDCube data. 
 - shape#
 - uncertainty#
- Uncertainty in the dataset, if any. - Should have an attribute - uncertainty_typethat defines what kind of uncertainty is stored, such as- 'std'for standard deviation or- 'var'for variance. A metaclass defining such an interface is- NDUncertaintybut isn’t mandatory.- Type:
- any type 
 
 - wcs#
- A world coordinate system (WCS) for the dataset, if any. - Type:
- any type 
 
 - Methods Documentation - axis_world_coords(*axes, pixel_corners=False, wcs=None)[source]#
- Returns objects representing the world coordinates of pixel centers for a desired axes. - Parameters:
- axes ( - intor- str, or multiple- intor- str, optional) – Axis number in numpy ordering or unique substring of- ndcube.NDCube.wcs.world_axis_physical_typesof axes for which real world coordinates are desired. Not specifying axes inputs causes results for all axes to be returned.
- pixel_corners ( - bool, optional) – If- Truethen instead of returning the coordinates at the centers of the pixels, the coordinates at the pixel corners will be returned. This increases the size of the output by 1 in all dimensions as all corners are returned.
- wcs ( - astropy.wcs.wcsapi.BaseHighLevelWCS, optional) – The WCS object to used to calculate the world coordinates. Although technically this can be any valid WCS, it will typically be- self.wcs,- self.extra_coords, or- self.combined_wcscombining both the WCS and extra coords. Default=self.wcs
 
- Returns:
- axes_coords (iterable) – An iterable of “high level” objects giving the real world coords for the axes requested by user. For example, a tuple of - SkyCoordobjects. The types returned are determined by the WCS object. The dimensionality of these objects should match that of their corresponding array dimensions, unless- pixel_corners=Truein which case the length along each axis will be 1 greater than the number of pixels.
 - Examples - >>> NDCube.axis_world_coords('lat', 'lon') >>> NDCube.axis_world_coords(2) 
 - axis_world_coords_values(*axes, pixel_corners=False, wcs=None)[source]#
- Returns the world coordinate values of all pixels for desired axes. In contrast to - ndcube.NDCube.axis_world_coords(), this method returns- Quantityobjects. Which only provide units rather than full coordinate metadata provided by high-level coordinate objects.- Parameters:
- axes ( - intor- str, or multiple- intor- str, optional) – Axis number in numpy ordering or unique substring of- ndcube.NDCube.wcs.world_axis_physical_typesof axes for which real world coordinates are desired. axes=None implies all axes will be returned.
- pixel_corners ( - bool, optional) – If- Truethen coordinates at pixel corners will be returned rather than at pixel centers. This increases the size of the output along each dimension by 1 as all corners are returned.
- wcs ( - BaseHighLevelWCSor- ExtraCoordsABC, optional) – The WCS object to be used to calculate the world coordinates. Although technically this can be any valid WCS, it will typically be- self.wcs,- self.extra_coords, or- self.combined_wcs, combing both the WCS and extra coords. Defaults to the- .wcsproperty.
 
- Returns:
- axes_coords ( - tupleof- Quantity) – An iterable of raw coordinate values for all pixels for the requested axes. The returned units are determined by the WCS object. The dimensionality of these objects should match that of their corresponding array dimensions, unless- pixel_corners=Truein which case the length along each axis will be 1 greater than the number of pixels.
 - Examples - >>> NDCube.axis_world_coords_values('lat', 'lon') >>> NDCube.axis_world_coords_values(2) 
 - crop(*points, wcs=None, keepdims=False)[source]#
- Crop using real world coordinates. This method crops the NDCube to the smallest bounding box in pixel space that contains all the provided world coordinate points. - This function takes the points defined as high-level astropy coordinate objects such as - SkyCoord,- SpectralCoord, etc.- Parameters:
- points (iterable of iterables) – Tuples of high level coordinate objects e.g. - SkyCoord. Each iterable of coordinate objects represents a single location in the data array in real world coordinates.- The coordinates of the points as they are passed to - world_to_array_index. Therefore their number and order must be compatible with the API of that method, i.e. they must be passed in world order.
- wcs ( - BaseHighLevelWCSor- ExtraCoordsABC) – The WCS to use to calculate the pixel coordinates based on the input. Will default to the- .wcsproperty if not given. While any valid WCS could be used it is expected that either the- .wcsor- .extra_coordsproperties will be used.
- keepdims ( - bool, optional) – If- Falseand if cropping results in length-1 dimensions, these are sliced away in output cube. If- True, length-1 dimensions are kept. Default=False
 
- Returns:
 - Examples - >>> # An example of cropping a region of interest on the Sun from a 3-D image-time cube >>> point1 = [SkyCoord(-50*u.deg, -40*u.deg, frame=frames.HeliographicStonyhurst), None] >>> point2 = [SkyCoord(0*u.deg, -6*u.deg, frame=frames.HeliographicStonyhurst), None] >>> NDCube.crop(point1, point2) 
 - crop_by_values(*points, units=None, wcs=None, keepdims=False)[source]#
- Crop using real world coordinates. This method crops the NDCube to the smallest bounding box in pixel space that contains all the provided world coordinate points. - This function takes points as iterables of low-level coordinate objects, i.e. - Quantityobjects. This differs from- crop()which takes high-level coordinate objects requiring all the relevant coordinate information such as coordinate frame etc. Hence this method’s API is more basic but less explicit.- Parameters:
- points (iterable) – Tuples of coordinate values, the length of the tuples must be equal to the number of world dimensions. These points are passed to - wcs.world_to_array_index_valuesso their units and order must be compatible with that method.
- units ( - stror- Unit) – If the inputs are set without units, the user must set the units inside this argument as- stror- Unitobjects. The length of the iterable must equal the number of world dimensions and must have the same order as the coordinate points.
- wcs ( - BaseHighLevelWCSor- ExtraCoordsABC) – The WCS to use to calculate the pixel coordinates based on the input. Will default to the- .wcsproperty if not given. While any valid WCS could be used it is expected that either the- .wcsor- .extra_coordsproperties will be used.
- keepdims ( - bool, optional) – If- Falseand if cropping results in length-1 dimensions, these are sliced away in output cube. If- True, length-1 dimensions are kept. Default=False
 
- Returns:
 - Examples - >>> # An example of cropping a region of interest on the Sun from a 3-D image-time cube >>> NDCube.crop_by_values((-600, -600, 0), (0, 0, 0), units=(u.arcsec, u.arcsec, u.s)) 
 - explode_along_axis(axis)[source]#
- Separates slices of NDCubes along a given axis into an NDCubeSequence of (N-1)DCubes. - Parameters:
- axis ( - int) – The array axis along which the data is to be changed.
- Returns:
- result ( - ndcube.NDCubeSequence)
 
 - reproject_to(
- target_wcs,
- algorithm='interpolation',
- shape_out=None,
- return_footprint=False,
- **reproject_args,
- Reprojects the instance to the coordinates described by another WCS object. - Parameters:
- target_wcs ( - astropy.wcs.wcsapi.BaseHighLevelWCS,- astropy.wcs.wcsapi.BaseLowLevelWCS,) – or- astropy.io.fits.HeaderThe WCS object to which the- ndcube.NDCubeis to be reprojected.
- algorithm ({‘interpolation’ | ‘adaptive’ | ‘exact’}) – The algorithm to use for reprojecting. When set to “interpolation” - reproject_interpis used, when set to “adaptive”- reproject_adaptiveis used and when set to “exact”- reproject_exactis used.
- shape_out ( - tuple, optional) – The shape of the output data array. The ordering of the dimensions must follow NumPy ordering and not the WCS pixel shape. If not specified,- array_shapeattribute (if available) from the low level API of the- target_wcsis used.
- return_footprint ( - bool) – If- Truethe footprint is returned in addition to the new- NDCube. Defaults to- False.
- **reproject_args – All other arguments are passed through to the reproject function being called. The function being called depends on the - algorithm=keyword argument, see that for more details.
 
- Returns:
- reprojected_cube ( - ndcube.NDCube) – A new resultant NDCube object, the supplied- target_wcswill be the- .wcsattribute of the output- NDCube.
- footprint ( - numpy.ndarray) – Footprint of the input array in the output array. Values of 0 indicate no coverage or valid values in the input image, while values of 1 indicate valid values.
 
 - Notes - This method doesn’t support handling of the - mask,- extra_coords, and- uncertaintyattributes yet. However,- metaand- global_coordsare copied to the output- ndcube.NDCube.
 
