Skip to content

Commit 6fa01ff

Browse files
committed
refactored StandardDeviationUncertainty to StdDevUncertainty
1 parent 97e5a28 commit 6fa01ff

4 files changed

Lines changed: 30 additions & 30 deletions

File tree

astropy/nddata/nduncertainty.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44

55
__all__ = ['MissingDataAssociationException', 'IncompatibleUncertaintiesException', 'NDUncertainty',
6-
'StandardDeviationUncertainty']
6+
'StdDevUncertainty']
77

88

99
class IncompatibleUncertaintiesException(Exception):
@@ -135,15 +135,15 @@ def propagate_divide(self, other_nddata, result_data):
135135
pass
136136

137137

138-
class StandardDeviationUncertainty(NDUncertainty):
138+
class StdDevUncertainty(NDUncertainty):
139139
'''
140140
A class for standard deviation uncertaintys
141141
'''
142142

143143
def __init__(self, array=None, copy=True):
144144
if array is None:
145145
self.array = None
146-
elif isinstance(array, StandardDeviationUncertainty):
146+
elif isinstance(array, StdDevUncertainty):
147147
self.array = np.array(array.array, copy=copy, subok=True)
148148
else:
149149
self.array = np.array(array, copy=copy, subok=True)
@@ -204,7 +204,7 @@ def propagate_add(self, other_nddata, result_data):
204204
Raised if the method does not know how to propagate the uncertainties
205205
'''
206206

207-
if not isinstance(other_nddata.uncertainty, StandardDeviationUncertainty):
207+
if not isinstance(other_nddata.uncertainty, StdDevUncertainty):
208208
raise IncompatibleUncertaintiesException
209209

210210
if self.array is None:
@@ -213,7 +213,7 @@ def propagate_add(self, other_nddata, result_data):
213213
if other_nddata.uncertainty.array is None:
214214
raise ValueError("standard deviation values are not set in other_nddata")
215215

216-
result_uncertainty = StandardDeviationUncertainty()
216+
result_uncertainty = StdDevUncertainty()
217217
result_uncertainty.array = np.sqrt(self.array ** 2 + other_nddata.uncertainty.array ** 2)
218218

219219
return result_uncertainty
@@ -248,7 +248,7 @@ def propagate_subtract(self, other_nddata, result_data):
248248
Raised if the method does not know how to propagate the uncertainties
249249
'''
250250

251-
if not isinstance(other_nddata.uncertainty, StandardDeviationUncertainty):
251+
if not isinstance(other_nddata.uncertainty, StdDevUncertainty):
252252
raise IncompatibleUncertaintiesException
253253

254254
if self.array is None:
@@ -257,7 +257,7 @@ def propagate_subtract(self, other_nddata, result_data):
257257
if other_nddata.uncertainty.array is None:
258258
raise ValueError("standard deviation values are not set in other_nddata")
259259

260-
result_uncertainty = StandardDeviationUncertainty()
260+
result_uncertainty = StdDevUncertainty()
261261
result_uncertainty.array = np.sqrt(self.array ** 2 + other_nddata.uncertainty.array ** 2)
262262

263263
return result_uncertainty
@@ -284,7 +284,7 @@ def propagate_multiply(self, other_nddata, result_data):
284284
Raised if the method does not know how to propagate the uncertainties
285285
'''
286286

287-
if not isinstance(other_nddata.uncertainty, StandardDeviationUncertainty):
287+
if not isinstance(other_nddata.uncertainty, StdDevUncertainty):
288288
raise IncompatibleUncertaintiesException
289289

290290
if self.array is None:
@@ -293,7 +293,7 @@ def propagate_multiply(self, other_nddata, result_data):
293293
if other_nddata.uncertainty.array is None:
294294
raise ValueError("standard deviation values are not set in other_nddata")
295295

296-
result_uncertainty = StandardDeviationUncertainty()
296+
result_uncertainty = StdDevUncertainty()
297297
result_uncertainty.array = np.sqrt((self.array / self.data) ** 2
298298
+ (other_nddata.uncertainty.array / other_nddata.data) ** 2) \
299299
* result_data
@@ -322,7 +322,7 @@ def propagate_divide(self, other_nddata, result_data):
322322
Raised if the method does not know how to propagate the uncertainties
323323
'''
324324

325-
if not isinstance(other_nddata.uncertainty, StandardDeviationUncertainty):
325+
if not isinstance(other_nddata.uncertainty, StdDevUncertainty):
326326
raise IncompatibleUncertaintiesException
327327

328328
if self.array is None:
@@ -331,7 +331,7 @@ def propagate_divide(self, other_nddata, result_data):
331331
if other_nddata.uncertainty.array is None:
332332
raise ValueError("standard deviation values are not set in other_nddata")
333333

334-
result_uncertainty = StandardDeviationUncertainty()
334+
result_uncertainty = StdDevUncertainty()
335335
result_uncertainty.array = np.sqrt((self.array / self.data) ** 2
336336
+ (other_nddata.uncertainty.array / other_nddata.data) ** 2) \
337337
* result_data

astropy/nddata/tests/test_nddata.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55

66
from ..nddata import NDData
7-
from ..nduncertainty import StandardDeviationUncertainty, IncompatibleUncertaintiesException, NDUncertainty
7+
from ..nduncertainty import StdDevUncertainty, IncompatibleUncertaintiesException, NDUncertainty
88
from ...tests.helper import raises
99
from ...io import fits
1010

@@ -49,19 +49,19 @@ def test_nddata_mask_invalid_shape(shape):
4949

5050

5151
def test_nddata_uncertainty_init():
52-
u = StandardDeviationUncertainty(array=np.ones((5, 5)))
52+
u = StdDevUncertainty(array=np.ones((5, 5)))
5353
d = NDData(np.ones((5, 5)), uncertainty=u)
5454

5555

5656
def test_nddata_uncertainty_init_invalid_shape_1():
57-
u = StandardDeviationUncertainty(array=np.ones((6, 6)))
57+
u = StdDevUncertainty(array=np.ones((6, 6)))
5858
with pytest.raises(ValueError) as exc:
5959
NDData(np.ones((5, 5)), uncertainty=u)
6060
assert exc.value.args[0] == 'parent shape does not match array data shape'
6161

6262

6363
def test_nddata_uncertainty_init_invalid_shape_2():
64-
u = StandardDeviationUncertainty()
64+
u = StdDevUncertainty()
6565
NDData(np.ones((5, 5)), uncertainty=u)
6666
with pytest.raises(ValueError) as exc:
6767
u.array = np.ones((6, 6))
@@ -122,8 +122,8 @@ def test_nddata_add_mismatch_shape():
122122

123123

124124
def test_nddata_add_uncertainties():
125-
u1 = StandardDeviationUncertainty(array=np.ones((5, 5)) * 3)
126-
u2 = StandardDeviationUncertainty(array=np.ones((5, 5)))
125+
u1 = StdDevUncertainty(array=np.ones((5, 5)) * 3)
126+
u2 = StdDevUncertainty(array=np.ones((5, 5)))
127127
d1 = NDData(np.ones((5, 5)), uncertainty=u1)
128128
d2 = NDData(np.ones((5, 5)), uncertainty=u2)
129129
d3 = d1.add(d2)
@@ -132,14 +132,14 @@ def test_nddata_add_uncertainties():
132132

133133

134134
def test_nddata_add_uncertainties_mismatch():
135-
u1 = StandardDeviationUncertainty(array=np.ones((5, 5)) * 3)
135+
u1 = StdDevUncertainty(array=np.ones((5, 5)) * 3)
136136
u2 = FakeUncertainty()
137137
print u2.__class__
138138
d1 = NDData(np.ones((5, 5)), uncertainty=u1)
139139
d2 = NDData(np.ones((5, 5)), uncertainty=u2)
140140
with pytest.raises(IncompatibleUncertaintiesException) as exc:
141141
d3 = d1.add(d2)
142-
assert exc.value.args[0] == 'Cannot propagate uncertainties of type StandardDeviationUncertainty with uncertainties of type FakeUncertainty for addition'
142+
assert exc.value.args[0] == 'Cannot propagate uncertainties of type StdDevUncertainty with uncertainties of type FakeUncertainty for addition'
143143

144144

145145
def test_nddata_subtract():
@@ -174,8 +174,8 @@ def test_nddata_subtract_mismatch_shape():
174174

175175

176176
def test_nddata_subtract_uncertainties():
177-
u1 = StandardDeviationUncertainty(array=np.ones((5, 5)) * 3)
178-
u2 = StandardDeviationUncertainty(array=np.ones((5, 5)))
177+
u1 = StdDevUncertainty(array=np.ones((5, 5)) * 3)
178+
u2 = StdDevUncertainty(array=np.ones((5, 5)))
179179
d1 = NDData(np.ones((5, 5)), uncertainty=u1)
180180
d2 = NDData(np.ones((5, 5)) * 2., uncertainty=u2)
181181
d3 = d1.subtract(d2)
@@ -184,14 +184,14 @@ def test_nddata_subtract_uncertainties():
184184

185185

186186
def test_nddata_subtract_uncertainties_mismatch():
187-
u1 = StandardDeviationUncertainty(array=np.ones((5, 5)) * 3)
187+
u1 = StdDevUncertainty(array=np.ones((5, 5)) * 3)
188188
u2 = FakeUncertainty()
189189
print u2.__class__
190190
d1 = NDData(np.ones((5, 5)), uncertainty=u1)
191191
d2 = NDData(np.ones((5, 5)) * 2., uncertainty=u2)
192192
with pytest.raises(IncompatibleUncertaintiesException) as exc:
193193
d3 = d1.subtract(d2)
194-
assert exc.value.args[0] == 'Cannot propagate uncertainties of type StandardDeviationUncertainty with uncertainties of type FakeUncertainty for subtraction'
194+
assert exc.value.args[0] == 'Cannot propagate uncertainties of type StdDevUncertainty with uncertainties of type FakeUncertainty for subtraction'
195195

196196

197197
def test_convert_units_to():
@@ -206,14 +206,14 @@ def test_invalid_unit():
206206
d = NDData(np.ones((5, 5)), units="NotAValidUnit")
207207

208208
def test_simple_slicing():
209-
u1 = StandardDeviationUncertainty(array=np.ones((5, 5)) * 3)
209+
u1 = StdDevUncertainty(array=np.ones((5, 5)) * 3)
210210
d1 = NDData(np.ones((5, 5)), uncertainty=u1)
211211
assert d1.shape == (5,5)
212212
d2 = d1[2:3, 2:3]
213213
assert d2.shape == (1,1)
214214

215215
def test_slicing_reference():
216-
u1 = StandardDeviationUncertainty(array=np.ones((5, 5)) * 3)
216+
u1 = StdDevUncertainty(array=np.ones((5, 5)) * 3)
217217
d1 = NDData(np.ones((5, 5)), uncertainty=u1)
218218
d2 = d1[2:3, 2:3]
219219
#asserting that the new nddata contains references to the original nddata
@@ -229,8 +229,8 @@ def test_initializing_from_nddata():
229229

230230

231231
def test_initializing_from_nduncertainty():
232-
u1 = StandardDeviationUncertainty(np.ones((5, 5)) * 3)
233-
u2 = StandardDeviationUncertainty(u1, copy=False)
232+
u1 = StdDevUncertainty(np.ones((5, 5)) * 3)
233+
u2 = StdDevUncertainty(u1, copy=False)
234234

235235
assert u1.array is u2.array
236236

docs/nddata/nddata.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ used to set the uncertainty on the data values. This is done by using classes
7878
to represent the errors of a given type. For example, to set standard
7979
deviation errors on the pixel values, you can do::
8080

81-
>>> from astropy.nddata import StandardDeviationUncertainty
82-
>>> ndd.error = StandardDeviationUncertainty(np.ones((12, 12, 12)) * 0.1)
81+
>>> from astropy.nddata import StdDevUncertainty
82+
>>> ndd.error = StdDevUncertainty(np.ones((12, 12, 12)) * 0.1)
8383

8484
.. note:: For information on creating your own error classes,
8585
see :doc:`subclassing`.

docs/nddata/subclassing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ variables with more explicit names, e.g::
5555
Note that the above example assumes that the errors are stored in an ``array``
5656
attribute, but this does not have to be the case.
5757

58-
For an example of a complete implementation, see `~astropy.nddata.nderror.StandardDeviationUncertainty`.
58+
For an example of a complete implementation, see `~astropy.nddata.nderror.StdDevUncertainty`.

0 commit comments

Comments
 (0)