class astropy.nddata.NDSlicingMixin[source]

Bases: object

Mixin to provide slicing on objects using the NDData interface.

The data, mask, uncertainty and wcs will be sliced, if set and sliceable. The unit and meta will be untouched. The return will be a reference and not a copy, if possible.


Using this Mixin with NDData:

>>> from astropy.nddata import NDData, NDSlicingMixin
>>> class NDDataSliceable(NDSlicingMixin, NDData):
...     pass

Slicing an instance containing data:

>>> nd = NDDataSliceable([1,2,3,4,5])
>>> nd[1:3]
NDDataSliceable([2, 3])

Also the other attributes are sliced for example the mask:

>>> import numpy as np
>>> mask = np.array([True, False, True, True, False])
>>> nd2 = NDDataSliceable(nd, mask=mask)
>>> nd2slc = nd2[1:3]
>>> nd2slc[nd2slc.mask]

Be aware that changing values of the sliced instance will change the values of the original:

>>> nd3 = nd2[1:3]
>>> nd3.data[0] = 100
>>> nd2
NDDataSliceable([  1, 100,   3,   4,   5])