Spreading Uncertainties with Astropy

In previous versions of astrometry, it was possible to handle the propagation of uncertainties along the following lines:

from astropy.nddata import NDData, StdDevUncertainty

x = NDData( 16.0, uncertainty=StdDevUncertainty( 4.0 ))
y = NDData( 361.0, uncertainty=StdDevUncertainty( 19.0 ))

print x.add(y)

Changes to NDData seem to have removed this feature. I get an AttributeError object: 'NDData' does not have an 'add' attribute, and I cannot find useful advice in the documentation. How is the error handled now?

+4
source share
1 answer

It looks like this functionality has been moved to mixin, NDArithmeticMixin.

An example in the documentation for arithmetic mixing suggests creating one own class and using it.

Thus, your example will be as follows:

from astropy.nddata import NDData, StdDevUncertainty, NDArithmeticMixin
class MyData(NDData, NDArithmeticMixin):
    pass
x = MyData( 16.0, uncertainty=StdDevUncertainty( 4.0 ))
y = MyData( 361.0, uncertainty=StdDevUncertainty( 19.0 ))
z = x.add(y)
print(z)
print(z.uncertainty.array)

which gives:

MyData(377.0)
19.416487838947599

NDDataArray , MyData: (, io ).
:

from astropy.nddata import StdDevUncertainty, NDDataArray
x = NDDataArray(16, uncertainty=StdDevUncertainty(4.0))
y = NDDataArray(361, uncertainty=StdDevUncertainty(19.0))
z = x.add(y)
print(z)
print(z.uncertainty.array)

, . , , ,

z = x + y
print(z)

377.0 +/- 19.416487838947599
+3

Source: https://habr.com/ru/post/1619709/


All Articles