NDUncertainty#

class astropy.nddata.NDUncertainty(array=None, copy=True, unit=None)[source]#

Bases: object

This is the metaclass for uncertainty classes used with NDData.

Parameters:
arrayany type, optional

The array or value (the parameter name is due to historical reasons) of the uncertainty. numpy.ndarray, Quantity or NDUncertainty subclasses are recommended. If the array is list-like or numpy.ndarray-like it will be cast to a plain numpy.ndarray. Default is None.

unitastropy:unit-like, optional

Unit for the uncertainty array. Strings that can be converted to a Unit are allowed. Default is None.

copybool, optional

Indicates whether to save the array as a copy. True copies it before saving, while False tries to save every parameter as reference. Note however that it is not always possible to save the input as reference. Default is True.

Raises:
IncompatibleUncertaintiesException

If given another NDUncertainty-like class as array if their uncertainty_type is different.

Attributes Summary

array

numpy.ndarray : the uncertainty's value.

parent_nddata

NDData : reference to NDData instance with this uncertainty.

quantity

This uncertainty as an Quantity object.

supports_correlated

bool : Supports uncertainty propagation with correlated uncertainties?

uncertainty_type

str : Short description of the type of uncertainty.

unit

Unit : The unit of the uncertainty, if any.

Methods Summary

propagate(operation, other_nddata, ...[, axis])

Calculate the resulting uncertainty given an operation on the data.

represent_as(other_uncert)

Convert this uncertainty to a different uncertainty type.

Attributes Documentation

array#

numpy.ndarray : the uncertainty’s value.

parent_nddata#

NDData : reference to NDData instance 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.

quantity#

This uncertainty as an Quantity object.

supports_correlated#

bool : Supports uncertainty propagation with correlated uncertainties?

Added 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.

Methods Documentation

propagate(operation, other_nddata, result_data, correlation, axis=None)[source]#

Calculate the resulting uncertainty given an operation on the data.

Added in version 1.2.

Parameters:
operationcallable()

The operation that is performed on the NDData. Supported are numpy.add, numpy.subtract, numpy.multiply and numpy.true_divide (or numpy.divide).

other_nddataNDData instance

The second operand in the arithmetic operation.

result_dataQuantity or ndarray

The result of the arithmetic operations on the data.

correlationnumpy.ndarray or number

The correlation (rho) is defined between the uncertainties in sigma_AB = sigma_A * sigma_B * rho. A value of 0 means uncorrelated operands.

axisint or tuple of int, optional

Axis over which to perform a collapsing operation.

Returns:
resulting_uncertaintyNDUncertainty instance

Another instance of the same NDUncertainty subclass containing the uncertainty of the result.

Raises:
ValueError

If the operation is 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.

represent_as(other_uncert)[source]#

Convert this uncertainty to a different uncertainty type.

Parameters:
other_uncertNDUncertainty subclass

The NDUncertainty subclass to convert to.

Returns:
resulting_uncertaintyNDUncertainty instance

An instance of other_uncert subclass containing the uncertainty converted to the new uncertainty type.

Raises:
TypeError

If either the initial or final subclasses do not support conversion, a TypeError is raised.