Skip to content

Commit ddb0f7b

Browse files
committed
Use simpler checks for invalid values
1 parent 6b2ffb0 commit ddb0f7b

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

specreduce/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _parse_image(self, image, disp_axis=1):
6363
if getattr(image, 'mask', None) is not None:
6464
mask = image.mask
6565
else:
66-
mask = np.ma.masked_invalid(img).mask
66+
mask = ~np.isfinite(img)
6767

6868
if getattr(image, 'uncertainty', None) is not None:
6969
uncertainty = image.uncertainty

specreduce/extract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def _parse_image(self, image,
357357
elif mask is not None:
358358
pass
359359
else:
360-
mask = np.ma.masked_invalid(img).mask
360+
mask = ~np.isfinite(img)
361361

362362
if img.shape != mask.shape:
363363
raise ValueError('image and mask shapes must match.')
@@ -486,7 +486,7 @@ def __call__(self, image=None, trace_object=None,
486486

487487
# mask any previously uncaught invalid values
488488
or_mask = np.logical_or(mask,
489-
np.ma.masked_invalid(self.image.data).mask)
489+
~np.isfinite(self.image.data))
490490
img = np.ma.masked_array(self.image.data, or_mask)
491491
mask = img.mask
492492

specreduce/tests/test_image_parsing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from specreduce.tracing import FlatTrace
1010
from specutils import Spectrum1D, SpectralAxis
1111

12+
1213
# fetch test image
1314
fn = download_file('https://stsci.box.com/shared/static/exnkul627fcuhy5akf2gswytud5tazmw.fits',
1415
cache=True)
@@ -96,7 +97,7 @@ def test_parse_horne():
9697
# requires a variance, so it's chosen here to be on equal footing
9798
# with the general case
9899
defaults = {'variance': unc_def,
99-
'mask': np.ma.masked_invalid(img).mask,
100+
'mask': ~np.isfinite(img),
100101
'unit': getattr(img, 'unit', u.DN)}
101102

102103
col[key] = HorneExtract._parse_image(object, img, **defaults)

specreduce/tests/test_tracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ def test_fit_trace():
144144
try:
145145
FitTrace(img_win_nans, guess=guess, window=window)
146146
except ValueError as e:
147-
print(f"All-NaN window error message: {e}")
147+
print(f"(expected) All-NaN window error message: {e}")
148148
else:
149149
raise RuntimeError('Trace was erroneously calculated on all-NaN window')
150150

151151
# error on trace of all-nan image
152152
try:
153153
FitTrace(img_all_nans)
154154
except ValueError as e:
155-
print(f"All-NaN image error message: {e}")
155+
print(f"(expected) All-NaN image error message: {e}")
156156
else:
157157
raise RuntimeError('Trace was erroneously calculated on all-NaN image')
158158

specreduce/tracing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ def __post_init__(self):
212212
self.image = self._parse_image(self.image)
213213

214214
# mask any previously uncaught invalid values
215-
or_mask = np.logical_or(self.image.mask,
216-
np.ma.masked_invalid(self.image.data).mask)
215+
or_mask = np.logical_or(self.image.mask, ~np.isfinite(self.image.data))
217216
img = np.ma.masked_array(self.image.data, or_mask)
218217

219218
# validate arguments

0 commit comments

Comments
 (0)