NDArithmeticMixin¶
-
class
astropy.nddata.NDArithmeticMixin[source] [edit on github]¶ Bases:
objectMixin 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
NDDataArrayfor 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/mif 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
operand2isNoneor not given it will perform the operationself+operand. Ifoperand2is given it will performoperand+operand2. If the method was called on a class rather than on the instanceoperand2must be given.propagate_uncertainties :
boolorNone, optionalIf
Nonethe result will have no uncertainty. IfFalsethe result will have a copied version of the first operand that has an uncertainty. IfTruethe 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.
Nonewas added as valid parameter value.handle_mask : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultsmaskand if necessary provide a copy. Default isnumpy.logical_or.New in version 1.2.
handle_meta : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultsmetaand if necessary provide a copy. Default isNone.New in version 1.2.
compare_wcs : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultingwcswill be like ifFalsewas given otherwise it raises aValueErrorif 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
callableis used formask,wcsormetathe callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargsand 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
operand2isNoneor not given it will perform the operationself/operand. Ifoperand2is given it will performoperand/operand2. If the method was called on a class rather than on the instanceoperand2must be given.propagate_uncertainties :
boolorNone, optionalIf
Nonethe result will have no uncertainty. IfFalsethe result will have a copied version of the first operand that has an uncertainty. IfTruethe 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.
Nonewas added as valid parameter value.handle_mask : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultsmaskand if necessary provide a copy. Default isnumpy.logical_or.New in version 1.2.
handle_meta : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultsmetaand if necessary provide a copy. Default isNone.New in version 1.2.
compare_wcs : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultingwcswill be like ifFalsewas given otherwise it raises aValueErrorif 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
callableis used formask,wcsormetathe callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargsand 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
operand2isNoneor not given it will perform the operationself*operand. Ifoperand2is given it will performoperand*operand2. If the method was called on a class rather than on the instanceoperand2must be given.propagate_uncertainties :
boolorNone, optionalIf
Nonethe result will have no uncertainty. IfFalsethe result will have a copied version of the first operand that has an uncertainty. IfTruethe 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.
Nonewas added as valid parameter value.handle_mask : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultsmaskand if necessary provide a copy. Default isnumpy.logical_or.New in version 1.2.
handle_meta : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultsmetaand if necessary provide a copy. Default isNone.New in version 1.2.
compare_wcs : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultingwcswill be like ifFalsewas given otherwise it raises aValueErrorif 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
callableis used formask,wcsormetathe callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargsand 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
operand2isNoneor not given it will perform the operationself-operand. Ifoperand2is given it will performoperand-operand2. If the method was called on a class rather than on the instanceoperand2must be given.propagate_uncertainties :
boolorNone, optionalIf
Nonethe result will have no uncertainty. IfFalsethe result will have a copied version of the first operand that has an uncertainty. IfTruethe 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.
Nonewas added as valid parameter value.handle_mask : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultsmaskand if necessary provide a copy. Default isnumpy.logical_or.New in version 1.2.
handle_meta : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultsmetaand if necessary provide a copy. Default isNone.New in version 1.2.
compare_wcs : callable,
'first_found'orNone, optionalIf
Nonethe 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 resultingwcswill be like ifFalsewas given otherwise it raises aValueErrorif 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
callableis used formask,wcsormetathe callable must accept the corresponding attributes as first two parameters. If the callable also needs additional parameters these can be defined askwargsand 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