NDUncertainty¶
-
class
astropy.nddata.NDUncertainty(array=None, copy=True, unit=None)[source] [edit on github]¶ Bases:
objectThis is the metaclass for uncertainty classes used with
NDData.Parameters: array : any type, optional
The array or value (the parameter name is due to historical reasons) of the uncertainty.
numpy.ndarray,QuantityorNDUncertaintysubclasses are recommended. If thearrayislist-like ornumpy.ndarray-like it will be cast to a plainnumpy.ndarray. Default isNone.unit :
Unitor str, optionalUnit for the uncertainty
array. Strings that can be converted to aUnitare allowed. Default isNone.copy :
bool, optionalIndicates whether to save the
arrayas a copy.Truecopies it before saving, whileFalsetries to save every parameter as reference. Note however that it is not always possible to save the input as reference. Default isTrue.Raises: IncompatibleUncertaintiesException
If given another
NDUncertainty-like class asarrayif theiruncertainty_typeis different.Attributes Summary
arraynumpy.ndarray: the uncertainty’s value.parent_nddataNDData: reference toNDDatainstance with this uncertainty.supports_correlatedbool: Supports uncertainty propagation with correlated uncertainties?uncertainty_typestr: Short description of the type of uncertainty.unitUnit: The unit of the uncertainty, if any.Methods Summary
propagate(operation, other_nddata, …)Calculate the resulting uncertainty given an operation on the data. Attributes Documentation
-
array¶ numpy.ndarray: the uncertainty’s value.
-
parent_nddata¶ NDData: reference toNDDatainstance with this uncertainty.In case the reference is not set uncertainty propagation will not be possible since propagation might need the uncertain data besides the uncertainty.
bool: Supports uncertainty propagation with correlated uncertainties?New in version 1.2.
-
uncertainty_type¶ str: Short description of the type of uncertainty.Defined as abstract property so subclasses have to override this.
-
unit¶ Unit: The unit of the uncertainty, if any.Even though it is not enforced the unit should be convertible to the
parent_nddataunit. Otherwise uncertainty propagation might give wrong results.If the unit is not set the unit of the parent will be returned.
Methods Documentation
-
propagate(operation, other_nddata, result_data, correlation)[source] [edit on github]¶ Calculate the resulting uncertainty given an operation on the data.
New in version 1.2.
Parameters: operation : callable
The operation that is performed on the
NDData. Supported arenumpy.add,numpy.subtract,numpy.multiplyandnumpy.true_divide(ornumpy.divide).other_nddata :
NDDatainstanceThe second operand in the arithmetic operation.
result_data :
Quantityornumpy.ndarrayThe result of the arithmetic operations on the data.
correlation :
numpy.ndarrayor numberThe correlation (rho) is defined between the uncertainties in sigma_AB = sigma_A * sigma_B * rho. A value of
0means uncorrelated operands.Returns: resulting_uncertainty :
NDUncertaintyinstanceAnother instance of the same
NDUncertaintysubclass containing the uncertainty of the result.Raises: ValueError
If the
operationis not supported or if correlation is not zero but the subclass does not support correlated uncertainties.Notes
First this method checks if a correlation is given and the subclass implements propagation with correlated uncertainties. Then the second uncertainty is converted (or an Exception is raised) to the same class in order to do the propagation. Then the appropriate propagation method is invoked and the result is returned.
-