Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Nov 22, 2023
1 parent 5c33943 commit d6991f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 13 additions & 1 deletion specreduce/tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pytest

from astropy.modeling import models
from astropy.nddata import NDData
import astropy.units as u
from specreduce.utils.synth_data import make_2d_trace_image
from specreduce.tracing import Trace, FlatTrace, ArrayTrace, FitTrace

Expand Down Expand Up @@ -148,4 +150,14 @@ def test_fit_trace():
with pytest.raises(ValueError, match=r'image is fully masked'):
FitTrace(img_all_nans)

# could try to catch warning thrown for all-nan bins
# test that warning is raised when many bins are masked
mask = np.zeros(img.shape)
mask[:, 75:76] = 1
nddat = NDData(data=img, mask=mask, unit=u.DN)
warn_bins = np.arange(20)
warn_bins = ', '.join([str(x) for x in warn_bins])
msg = f"All pixels in bin 75 are masked. Falling to trace value from all-bin fit."
with pytest.warns(UserWarning, match=msg):
FitTrace(nddat)

# could try to catch warning thrown for all-nan bins
8 changes: 4 additions & 4 deletions specreduce/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,13 @@ def __post_init__(self):

# warn about fully-masked bins
if len(warn_bins) > 0:
plural = 's' if len(warn_bins) == 1 else ''
plural = 's' if len(warn_bins) > 1 else ''
# if there are a ton of bins, we don't want to print them all out
print(warn_bins)
if len(warn_bins) > 20:
warn_bins = warn_bins[0: 10] + ['...'] + warn_bins[10: 19]

warnings.warn(f"All pixels in bin{plural} {', '.join([str(x) for x in warn_bins])} are masked. Falling "
'to trace value from all-bin fit.')
warnings.warn(f"All pixels in bin{plural} {', '.join([str(x) for x in warn_bins])}"
" are masked. Falling to trace value from all-bin fit.")

# recenter bin positions
x_bins = (x_bins[:-1] + x_bins[1:]) / 2
Expand Down

0 comments on commit d6991f1

Please sign in to comment.