NDDataRef#

class astropy.nddata.NDDataRef(data, uncertainty=None, mask=None, wcs=None, meta=None, unit=None, copy=False, psf=None)[source]#

Bases: NDArithmeticMixin, NDIOMixin, NDSlicingMixin, NDData

Implements NDData with all Mixins.

This class implements a NDData-like container that supports reading and writing as implemented in the astropy.io.registry and also slicing (indexing) and simple arithmetic (add, subtract, divide and multiply).

Notes

A key distinction from NDDataArray is that this class does not attempt to provide anything that was not defined in any of the parent classes.

Examples

The mixins allow operation that are not possible with NDData or NDDataBase, i.e. simple arithmetic:

>>> from astropy.nddata import NDDataRef, StdDevUncertainty
>>> import numpy as np

>>> data = np.ones((3,3), dtype=float)
>>> ndd1 = NDDataRef(data, uncertainty=StdDevUncertainty(data))
>>> ndd2 = NDDataRef(data, uncertainty=StdDevUncertainty(data))

>>> ndd3 = ndd1.add(ndd2)
>>> ndd3.data  
array([[2., 2., 2.],
       [2., 2., 2.],
       [2., 2., 2.]])
>>> ndd3.uncertainty.array  
array([[1.41421356, 1.41421356, 1.41421356],
       [1.41421356, 1.41421356, 1.41421356],
       [1.41421356, 1.41421356, 1.41421356]])

see NDArithmeticMixin for a complete list of all supported arithmetic operations.

But also slicing (indexing) is possible:

>>> ndd4 = ndd3[1,:]
>>> ndd4.data  
array([2., 2., 2.])
>>> ndd4.uncertainty.array  
array([1.41421356, 1.41421356, 1.41421356])

See NDSlicingMixin for a description how slicing works (which attributes) are sliced.