NDData

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

Bases: astropy.nddata.NDDataBase

A container for numpy.ndarray-based datasets, using the NDDataBase interface.

The key distinction from raw numpy.ndarray is the presence of additional metadata such as uncertainty, mask, unit, a coordinate system and/or a dictionary containing further meta information. This class only provides a container for storing such datasets. For further functionality take a look at the See also section.

Parameters:
data : numpy.ndarray-like or NDData-like

The dataset.

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.

wcs : any type, optional

World coordinate system (WCS) for the dataset. Default is 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.

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.

New in version 1.2.

Raises:
TypeError

In case data or meta don’t meet the restrictions.

Notes

Each attribute can be accessed through the homonymous instance attribute: data in a NDData object can be accessed through the data attribute:

>>> from astropy.nddata import NDData
>>> nd = NDData([1,2,3])
>>> nd.data
array([1, 2, 3])

Given a conflicting implicit and an explicit parameter during initialization, for example the data is a Quantity and the unit parameter is not None, then the implicit parameter is replaced (without conversion) by the explicit one and a warning is issued:

>>> import numpy as np
>>> import astropy.units as u
>>> q = np.array([1,2,3,4]) * u.m
>>> nd2 = NDData(q, unit=u.cm)
INFO: overwriting Quantity's current unit with specified unit. [astropy.nddata.nddata]
>>> nd2.data  
array([1., 2., 3., 4.])
>>> nd2.unit
Unit("cm")

Attributes Summary

data ndarray-like : The stored dataset.
mask any type : Mask for the dataset, if any.
meta dict-like : Additional meta information about the dataset.
uncertainty any type : Uncertainty in the dataset, if any.
unit Unit : Unit for the dataset, if any.
wcs any type : A world coordinate system (WCS) for the dataset, if any.

Attributes Documentation

data

ndarray-like : The stored dataset.

mask

any type : Mask for the dataset, if any.

Masks should follow the numpy convention that valid data points are marked by False and invalid ones with True.

meta

dict-like : Additional meta information about the dataset.

uncertainty

any type : Uncertainty in the dataset, if any.

Should have an attribute uncertainty_type that defines what kind of uncertainty is stored, such as 'std' for standard deviation or 'var' for variance. A metaclass defining such an interface is NDUncertainty but isn’t mandatory.

unit

Unit : Unit for the dataset, if any.

wcs

any type : A world coordinate system (WCS) for the dataset, if any.