NDCubeSlicingMixin#
- class ndcube.mixins.NDCubeSlicingMixin[source]#
Bases:
NDSlicingMixinMixin to provide slicing on objects using the
NDDatainterface.The
data,mask,uncertaintyandwcswill be sliced, if set and sliceable. Theunitandmetawill be untouched. The return will be a reference and not a copy, if possible.Examples
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] NDDataSliceable([—])
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([———, 100, ———, ———, 5])
See also
NDDataRef,NDDataArray