nddata_arith¶
- astroimtools.arithmetic.nddata_arith(nddata1, nddata2, operator, fill_value=0.0, keywords=None)[source]¶
Perform basic arithmetic on two
NDData
objects and return a newNDData
object.- Parameters:
- nddata1, nddata2
NDData
or scalar The
NDData
objects (or scalar) on which to perform the arithmetic operation. Note thatnddata1
andnddata2
cannot both be scalars.- operator{‘+’, ‘-’, ‘*’, ‘/’, ‘//’, ‘min’, ‘max’}
The operator to apply to the inputs.
- fill_valuefloat, optional
The fill value used in the output data when the resultant value is masked. The default is 0.
- keywordsstr or list of str, optional
List of keywords in the meta dictionaries of both input
NDData
objects to propagate the same as arithmetic.
- nddata1, nddata2
- Returns:
- result
NDData
NDData object resulting from the arithmetic operation.
- result
Examples
>>> from astroimtools import nddata_arith >>> from astropy.nddata import NDData >>> nd1 = NDData([0, 1, 2, 3, 4]) >>> nd2 = NDData([1, 7, 5, 4, 2])
>>> nd = nddata_arith(nd1, 5, '+') >>> nd.data array([5, 6, 7, 8, 9])
>>> nd = nddata_arith(nd1, 5, '*') >>> nd.data array([ 0, 5, 10, 15, 20])
>>> nd = nddata_arith(nd1, nd2, '+') >>> nd.data array([1, 8, 7, 7, 6])
>>> nd = nddata_arith(nd1, nd2, 'min') >>> nd.data array([0, 1, 2, 3, 2])
>>> nd = nddata_arith(nd1, 2, '/') >>> nd.data array([0., 0.5, 1., 1.5, 2. ])
>>> nd = nddata_arith(nd1, 2, '//') >>> nd.data array([0, 0, 1, 1, 2])
The operand can also be applied to NDData meta keywords:
>>> nd1.meta['exptime'] = 500 >>> nd2.meta['exptime'] = 1000 >>> nd = nddata_arith(nd1, nd2, '+', keywords='exptime') >>> nd.meta['exptime'] 1500
And the NDData masks are used in the operations:
>>> nd1.mask = (nd1.data > 3) >>> nd2.mask = (nd2.data < 2) >>> nd = nddata_arith(nd1, nd2, '+') >>> nd.data array([0, 8, 7, 7, 0]) >>> nd.mask array([ True, False, False, False, True]...)