NDData

class astropy.nddata.nddata.NDData(data, uncertainty=None, mask=None, flags=None, wcs=None, meta=None, units=None, copy=True) [edit on github][source]

Bases: object

A Superclass for array-based data in Astropy.

The key distinction from raw numpy arrays is the presence of additional metadata such as uncertainties, a mask, units, flags, and/or a coordinate system.

Parameters :

data : ndarray or NDData

The actual data contained in this NDData object.

uncertainty : NDUncertainty, optional

Uncertainties on the data.

mask : ndarray, optional

Mask for the data, given as a boolean Numpy array with a shape matching that of the data. The values must be False where the data is valid and True when it is not (as for Numpy masked arrays).

flags : ndarray or FlagCollection, optional

Flags giving information about each pixel. These can be specified either as a Numpy array of any type with a shape matching that of the data, or as a FlagCollection instance which has a shape matching that of the data.

wcs : undefined, optional

WCS-object containing the world coordinate system for the data.

Warning

This is not yet defind because the discussion of how best to represent this class’s WCS system generically is still under consideration. For now just leave it as None

meta : dict-like object, optional

Metadata for this object. “Metadata” here means all information that is included with this object but not part of any other attribute of this particular object. e.g., creation date, unique identifier, simulation parameters, exposure time, telescope name, etc.

units : astropy.units.UnitBase instance or str, optional

The units of the data.

copy : bool, optional

If True, the array will be copied from the provided data, otherwise it will be referenced if possible (see numpy.array copy argument for details).

Raises :

ValueError :

If the uncertainty or mask inputs cannot be broadcast (e.g., match shape) onto data.

Notes

NDData objects can be easily converted to a regular Numpy array using numpy.asarray

For example:

>>> from astropy.nddata import NDData
>>> import numpy as np
>>> x = NDData([1,2,3])
>>> np.asarray(x)
array([1, 2, 3])

If the NDData object has a mask, numpy.asarray will return a Numpy masked array.

This is useful, for example, when plotting a 2D image using matplotlib:

>>> from astropy.nddata import NDData
>>> from matplotlib import pyplot as plt
>>> x = NDData([[1,2,3], [4,5,6]])
>>> plt.imshow(x)

Attributes Summary

ndim integer dimensions of this object’s data
dtype numpy.dtype of this object’s data.
units
shape shape tuple of this object’s data.
meta
size integer size of this object’s data.
uncertainty
mask
flags

Methods Summary

divide(operand[, propagate_uncertainties]) Divide another dataset (operand) to this dataset.
convert_units_to(unit[, equivalencies]) Returns a new NDData object whose values have been converted to a new unit.
multiply(operand[, propagate_uncertainties]) Multiply another dataset (operand) to this dataset.
subtract(operand[, propagate_uncertainties]) Subtract another dataset (operand) to this dataset.
add(operand[, propagate_uncertainties]) Add another dataset (operand) to this dataset.

Attributes Documentation

ndim[source]

integer dimensions of this object’s data

dtype[source]

numpy.dtype of this object’s data.

units[source]
shape[source]

shape tuple of this object’s data.

meta[source]
size[source]

integer size of this object’s data.

uncertainty[source]
mask[source]
flags[source]

Methods Documentation

divide(operand, propagate_uncertainties=True) [edit on github][source]

Divide another dataset (operand) to this dataset.

Parameters :

operand : NDData

The second operand in the operation a / b

propagate_uncertainties : bool

Whether to propagate uncertainties following the propagation rules defined by the class used for the uncertainty attribute.

Returns :

result : NDData

The resulting dataset

Notes

This method requires the datasets to have identical WCS properties, equivalent units, and identical shapes. Flags and meta-data get set to None in the resulting dataset. The unit in the result is the same as the unit in self. Uncertainties are propagated, although correlated errors are not supported by any of the built-in uncertainty classes. If uncertainties are assumed to be correlated, a warning is issued by default (though this can be disabled via the WARN_UNSUPPORTED_CORRELATED configuration item). Values masked in either dataset before the operation are masked in the resulting dataset.

convert_units_to(unit, equivalencies=[]) [edit on github][source]

Returns a new NDData object whose values have been converted to a new unit.

Parameters :

unit : astropy.units.UnitBase instance or str

The unit to convert to.

equivalencies : list of equivalence pairs, optional

A list of equivalence pairs to try if the units are not directly convertible. See Equivalencies.

Returns :

result : NDData

The resulting dataset

Raises :

UnitsException :

If units are inconsistent.

multiply(operand, propagate_uncertainties=True) [edit on github][source]

Multiply another dataset (operand) to this dataset.

Parameters :

operand : NDData

The second operand in the operation a * b

propagate_uncertainties : bool

Whether to propagate uncertainties following the propagation rules defined by the class used for the uncertainty attribute.

Returns :

result : NDData

The resulting dataset

Notes

This method requires the datasets to have identical WCS properties, equivalent units, and identical shapes. Flags and meta-data get set to None in the resulting dataset. The unit in the result is the same as the unit in self. Uncertainties are propagated, although correlated errors are not supported by any of the built-in uncertainty classes. If uncertainties are assumed to be correlated, a warning is issued by default (though this can be disabled via the WARN_UNSUPPORTED_CORRELATED configuration item). Values masked in either dataset before the operation are masked in the resulting dataset.

subtract(operand, propagate_uncertainties=True) [edit on github][source]

Subtract another dataset (operand) to this dataset.

Parameters :

operand : NDData

The second operand in the operation a - b

propagate_uncertainties : bool

Whether to propagate uncertainties following the propagation rules defined by the class used for the uncertainty attribute.

Returns :

result : NDData

The resulting dataset

Notes

This method requires the datasets to have identical WCS properties, equivalent units, and identical shapes. Flags and meta-data get set to None in the resulting dataset. The unit in the result is the same as the unit in self. Uncertainties are propagated, although correlated errors are not supported by any of the built-in uncertainty classes. If uncertainties are assumed to be correlated, a warning is issued by default (though this can be disabled via the WARN_UNSUPPORTED_CORRELATED configuration item). Values masked in either dataset before the operation are masked in the resulting dataset.

add(operand, propagate_uncertainties=True) [edit on github][source]

Add another dataset (operand) to this dataset.

Parameters :

operand : NDData

The second operand in the operation a + b

propagate_uncertainties : bool

Whether to propagate uncertainties following the propagation rules defined by the class used for the uncertainty attribute.

Returns :

result : NDData

The resulting dataset

Notes

This method requires the datasets to have identical WCS properties, equivalent units, and identical shapes. Flags and meta-data get set to None in the resulting dataset. The unit in the result is the same as the unit in self. Uncertainties are propagated, although correlated errors are not supported by any of the built-in uncertainty classes. If uncertainties are assumed to be correlated, a warning is issued by default (though this can be disabled via the WARN_UNSUPPORTED_CORRELATED configuration item). Values masked in either dataset before the operation are masked in the resulting dataset.

Page Contents