Navigation

The nddata package provides classes to represent images and other
gridded data, some essential functions for manipulating images, and the
infrastructure for package developers who wish to include support for the
image classes.

Though the nddata package supports any kind of gridded data, this
introduction will focus on the use of nddata for two-dimensional
images. To get started, we’ll construct a two-dimensional image with a few
sources, some Gaussian noise, and a “cosmic ray” which we will later mask out:

Methods are provided for basic arithmetic operations between images, including
propagation of uncertainties. Support for uncertainties is currently limited
to standard deviation. The example below creates an uncertainty that is simply
Poisson error; note that the masked version of the square root is used:

>>> ccd.uncertainty=np.ma.sqrt(np.ma.abs(ccd.data))INFO: array provided for uncertainty; assuming it is a StdDevUncertainty. [astropy.nddata.ccddata]

If we make a copy of the image and add that to the original, the uncertainty
changes as expected:

Though slicing directly is one way to extract a subframe,
Cutout2D provides more convenient access to cutouts from the
data. The example below pulls out the large “galaxy” in the lower left of the
image, with the center of the cutout at position:

The functions block_reduce and
block_replicate resize images. The example below reduces the
size of the image by a factor of 4. Note that the result is a numpy.ndarray;
the mask, metadata, etc are discarded:

There are two less restrictive classes, NDDataArray and
NDDataRef, that can be used to hold image data. They are
primarily of interest to those who may want to create their own image class by
subclassing from one of the classes in the nddata package. The main
differences between them are:

NDDataRef can be sliced and has methods for basic
arithmetic operations, but the user needs to use one of the uncertainty
classes to define an uncertainty. See NDDataRef for more detail.
Most of its properties must be set when the object is created because they
are not mutable.

NDDataArray extends NDDataRef by adding
the methods necessary to all it to behave like a numpy array in expressions
and adds setters for several properties. It lacks the ability to
automatically recognize and read data from FITS files and does not attempt
to automatically set the WCS property.

CCDData extends NDDataArray by setting
up a default uncertainty class, sets up straightforward read/write to FITS
files, automatically sets up a WCS property.

There are two additional classes in the nddata package that are of
interest primarily to people that either need a custom image class that goes
beyond the classes discussed so far or who are working with gridded data that
is not an image.

NDData is a container class for holding general gridded
data. It includes a handful of basic attributes, but no slicing or arithmetic.
More information about this class is in NDData.

NDDataBase is an abstract base class that developers of new
gridded data classes can subclass to declare that the new class follows the
NDData interface. More details are in
Subclassing.

The list of packages below that use the nddata framework is intended to be
useful to either people writing their own image classes or for those looking
for an image class that goes beyond what CCDData does.

The astropy.nddata subpackage provides the NDData
class and related tools to manage n-dimensional array-based data (e.g.
CCD images, IFU Data, grid-based simulation data, …). This is more than
just numpy.ndarray objects, because it provides metadata that cannot
be easily provided by a single array.