Arithmetic mixin¶
Overview¶
The NDArithmeticMixin adds methods for performing basic
operations on NDData objects:
add(),
subtract(),
multiply() and
divide().
The operations are permitted only if the two operands have the same WCS and shape and the units, if any, consistent with the operation performed. The result is masked at a particular grid point if either of the operands is masked at that point.
The operations include a framework to propagate uncertainties that are based
on the classes NDUncertainty.
Warning
Uncertainty propagation is still experimental, and does not take into account correlated uncertainties.
Usage¶
As with other mixins, using the arithmetic mixin starts with defining your own class:
>>> from astropy.nddata import NDData, NDArithmeticMixin
>>> class MyNDDataArithmetic(NDArithmeticMixin, NDData): pass
Then, create instances of this new object with your data the way you would
with a plain NDData object:
>>> ndd1 = MyNDDataArithmetic([1, 2])
>>> ndd2 = MyNDDataArithmetic([3, 4])
The mixin adds methods on these instances for combining them:
>>> ndd1.add(ndd2)
MyNDDataArithmetic([ 4., 6.])
>>> ndd2.multiply(ndd1)
MyNDDataArithmetic([ 3., 8.])
One important note: the order you list the mixins and NDData
matters; the base class, NDData should be on the far
right.