NDArithmeticMixin¶
-
class
astropy.nddata.
NDArithmeticMixin
[source] [edit on github]¶ Bases:
object
Mixin class to add arithmetic to an NDData object.
When subclassing, be sure to list the superclasses in the correct order so that the subclass sees NDData as the main superclass. See
NDDataArray
for an example.Notes
- It is not tried to decompose the units, mainly due to the internal
mechanics of
Quantity
, so the resulting data might have units likekm/m
if you divided for example 100km by 5m. So this Mixin has adopted this behaviour.
Examples
Using this Mixin with
NDData
:>>> from astropy.nddata import NDData, NDArithmeticMixin >>> class NDDataWithMath(NDArithmeticMixin, NDData): ... pass
Using it with one operand on an instance:
>>> ndd = NDDataWithMath(100) >>> ndd.add(20) NDDataWithMath(120)
Using it with two operand on an instance:
>>> ndd = NDDataWithMath(5) >>> ndd.divide(1, ndd) NDDataWithMath(0.2)
Using it as classmethod requires two operands:
>>> NDDataWithMath.subtract(5, 4) NDDataWithMath(1)
Methods Summary
add
(operand[, operand2])Performs addition by evaluating self
+operand
.divide
(operand[, operand2])Performs division by evaluating self
/operand
.multiply
(operand[, operand2])Performs multiplication by evaluating self
*operand
.subtract
(operand[, operand2])Performs subtraction by evaluating self
-operand
.Methods Documentation
-
classmethod
add
(operand, operand2=None, **kwargs)[source] [edit on github]¶ Performs addition by evaluating
self
+operand
.Parameters: operand, operand2 :
NDData
-like instance or convertible to one.If
operand2
isNone
or not given it will perform the operationself
+operand
. Ifoperand2
is given it will performoperand
+operand2
. If the method was called on a class rather than on the instanceoperand2
must be given.propagate_uncertainties :
bool
orNone
, optionalIf
None
the result will have no uncertainty. IfFalse
the result will have a copied version of the first operand that has an uncertainty. IfTrue
the result will have a correctly propagated uncertainty from the uncertainties of the operands but this assumes that the uncertainties areNDUncertainty
-like. Default isTrue
.Changed in version 1.2: This parameter must be given as keyword-parameter. Using it as positional parameter is deprecated.
None
was added as valid parameter value.handle_mask : callable,
'first_found'
orNone
, optionalIf
None
the result will have no mask. If'first_found'
the result will have a copied version of the first operand that has a mask). If it is a callable then the specified callable must create the resultsmask
and if necessary provide a copy. Default isnumpy.logical_or
.New in version 1.2.
handle_meta : callable,
'first_found'
orNone
, optionalIf
None
the result will have no meta. If'first_found'
the result will have a copied version of the first operand that has a (not empty) meta. If it is a callable then the specified callable must create the resultsmeta
and if necessary provide a copy. Default isNone
.New in version 1.2.
compare_wcs : callable,
'first_found'
orNone
, optionalIf
None
the result will have no wcs and no comparison between the wcs of the operands is made. If'first_found'
the result will have a copied version of the first operand that has a wcs. If it is a callable then the specified callable must compare thewcs
. The resultingwcs
will be like ifFalse
was given otherwise it raises aValueError
if the comparison was not successful. Default is'first_found'
.New in version 1.2.
uncertainty_correlation : number or
ndarray
, optionalThe correlation between the two operands is used for correct error propagation for correlated data as given in: https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas Default is 0.
New in version 1.2.
kwargs :
Any other parameter that should be passed to the callables used.
Returns: result :
NDData
-likeThe resulting dataset
Notes
If a
callable
is used formask
,wcs
ormeta
the callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargs
and must start with"wcs_"
(for wcs callable) or"meta_"
(for meta callable). This startstring is removed before the callable is called."first_found"
can also be abbreviated with"ff"
.
-
classmethod
divide
(operand, operand2=None, **kwargs)[source] [edit on github]¶ Performs division by evaluating
self
/operand
.Parameters: operand, operand2 :
NDData
-like instance or convertible to one.If
operand2
isNone
or not given it will perform the operationself
/operand
. Ifoperand2
is given it will performoperand
/operand2
. If the method was called on a class rather than on the instanceoperand2
must be given.propagate_uncertainties :
bool
orNone
, optionalIf
None
the result will have no uncertainty. IfFalse
the result will have a copied version of the first operand that has an uncertainty. IfTrue
the result will have a correctly propagated uncertainty from the uncertainties of the operands but this assumes that the uncertainties areNDUncertainty
-like. Default isTrue
.Changed in version 1.2: This parameter must be given as keyword-parameter. Using it as positional parameter is deprecated.
None
was added as valid parameter value.handle_mask : callable,
'first_found'
orNone
, optionalIf
None
the result will have no mask. If'first_found'
the result will have a copied version of the first operand that has a mask). If it is a callable then the specified callable must create the resultsmask
and if necessary provide a copy. Default isnumpy.logical_or
.New in version 1.2.
handle_meta : callable,
'first_found'
orNone
, optionalIf
None
the result will have no meta. If'first_found'
the result will have a copied version of the first operand that has a (not empty) meta. If it is a callable then the specified callable must create the resultsmeta
and if necessary provide a copy. Default isNone
.New in version 1.2.
compare_wcs : callable,
'first_found'
orNone
, optionalIf
None
the result will have no wcs and no comparison between the wcs of the operands is made. If'first_found'
the result will have a copied version of the first operand that has a wcs. If it is a callable then the specified callable must compare thewcs
. The resultingwcs
will be like ifFalse
was given otherwise it raises aValueError
if the comparison was not successful. Default is'first_found'
.New in version 1.2.
uncertainty_correlation : number or
ndarray
, optionalThe correlation between the two operands is used for correct error propagation for correlated data as given in: https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas Default is 0.
New in version 1.2.
kwargs :
Any other parameter that should be passed to the callables used.
Returns: result :
NDData
-likeThe resulting dataset
Notes
If a
callable
is used formask
,wcs
ormeta
the callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargs
and must start with"wcs_"
(for wcs callable) or"meta_"
(for meta callable). This startstring is removed before the callable is called."first_found"
can also be abbreviated with"ff"
.
-
classmethod
multiply
(operand, operand2=None, **kwargs)[source] [edit on github]¶ Performs multiplication by evaluating
self
*operand
.Parameters: operand, operand2 :
NDData
-like instance or convertible to one.If
operand2
isNone
or not given it will perform the operationself
*operand
. Ifoperand2
is given it will performoperand
*operand2
. If the method was called on a class rather than on the instanceoperand2
must be given.propagate_uncertainties :
bool
orNone
, optionalIf
None
the result will have no uncertainty. IfFalse
the result will have a copied version of the first operand that has an uncertainty. IfTrue
the result will have a correctly propagated uncertainty from the uncertainties of the operands but this assumes that the uncertainties areNDUncertainty
-like. Default isTrue
.Changed in version 1.2: This parameter must be given as keyword-parameter. Using it as positional parameter is deprecated.
None
was added as valid parameter value.handle_mask : callable,
'first_found'
orNone
, optionalIf
None
the result will have no mask. If'first_found'
the result will have a copied version of the first operand that has a mask). If it is a callable then the specified callable must create the resultsmask
and if necessary provide a copy. Default isnumpy.logical_or
.New in version 1.2.
handle_meta : callable,
'first_found'
orNone
, optionalIf
None
the result will have no meta. If'first_found'
the result will have a copied version of the first operand that has a (not empty) meta. If it is a callable then the specified callable must create the resultsmeta
and if necessary provide a copy. Default isNone
.New in version 1.2.
compare_wcs : callable,
'first_found'
orNone
, optionalIf
None
the result will have no wcs and no comparison between the wcs of the operands is made. If'first_found'
the result will have a copied version of the first operand that has a wcs. If it is a callable then the specified callable must compare thewcs
. The resultingwcs
will be like ifFalse
was given otherwise it raises aValueError
if the comparison was not successful. Default is'first_found'
.New in version 1.2.
uncertainty_correlation : number or
ndarray
, optionalThe correlation between the two operands is used for correct error propagation for correlated data as given in: https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas Default is 0.
New in version 1.2.
kwargs :
Any other parameter that should be passed to the callables used.
Returns: result :
NDData
-likeThe resulting dataset
Notes
If a
callable
is used formask
,wcs
ormeta
the callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargs
and must start with"wcs_"
(for wcs callable) or"meta_"
(for meta callable). This startstring is removed before the callable is called."first_found"
can also be abbreviated with"ff"
.
-
classmethod
subtract
(operand, operand2=None, **kwargs)[source] [edit on github]¶ Performs subtraction by evaluating
self
-operand
.Parameters: operand, operand2 :
NDData
-like instance or convertible to one.If
operand2
isNone
or not given it will perform the operationself
-operand
. Ifoperand2
is given it will performoperand
-operand2
. If the method was called on a class rather than on the instanceoperand2
must be given.propagate_uncertainties :
bool
orNone
, optionalIf
None
the result will have no uncertainty. IfFalse
the result will have a copied version of the first operand that has an uncertainty. IfTrue
the result will have a correctly propagated uncertainty from the uncertainties of the operands but this assumes that the uncertainties areNDUncertainty
-like. Default isTrue
.Changed in version 1.2: This parameter must be given as keyword-parameter. Using it as positional parameter is deprecated.
None
was added as valid parameter value.handle_mask : callable,
'first_found'
orNone
, optionalIf
None
the result will have no mask. If'first_found'
the result will have a copied version of the first operand that has a mask). If it is a callable then the specified callable must create the resultsmask
and if necessary provide a copy. Default isnumpy.logical_or
.New in version 1.2.
handle_meta : callable,
'first_found'
orNone
, optionalIf
None
the result will have no meta. If'first_found'
the result will have a copied version of the first operand that has a (not empty) meta. If it is a callable then the specified callable must create the resultsmeta
and if necessary provide a copy. Default isNone
.New in version 1.2.
compare_wcs : callable,
'first_found'
orNone
, optionalIf
None
the result will have no wcs and no comparison between the wcs of the operands is made. If'first_found'
the result will have a copied version of the first operand that has a wcs. If it is a callable then the specified callable must compare thewcs
. The resultingwcs
will be like ifFalse
was given otherwise it raises aValueError
if the comparison was not successful. Default is'first_found'
.New in version 1.2.
uncertainty_correlation : number or
ndarray
, optionalThe correlation between the two operands is used for correct error propagation for correlated data as given in: https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas Default is 0.
New in version 1.2.
kwargs :
Any other parameter that should be passed to the callables used.
Returns: result :
NDData
-likeThe resulting dataset
Notes
If a
callable
is used formask
,wcs
ormeta
the callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargs
and must start with"wcs_"
(for wcs callable) or"meta_"
(for meta callable). This startstring is removed before the callable is called."first_found"
can also be abbreviated with"ff"
.
- It is not tried to decompose the units, mainly due to the internal
mechanics of