Skip to content

Commit

Permalink
fix warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Nov 21, 2023
1 parent 648c861 commit 5c33943
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions specreduce/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,17 @@ def __post_init__(self):
self.bins + 1, dtype=int)
y_bins = np.tile(np.nan, self.bins)

warn_bins = []
for i in range(self.bins):
# repeat earlier steps to create gaussian fit for each bin
z_i = img[ilum2, x_bins[i]:x_bins[i+1]].sum(axis=self._disp_axis)
if not z_i.mask.all():
peak_y_i = ilum2[z_i.argmax()]
else:
warnings.warn(f"All pixels in bin {i} are masked. Falling "
'to trace value from all-bin fit.')
warn_bins.append(i)
peak_y_i = peak_y


if self.peak_method == 'gaussian':
yy_i_above_half_max = np.sum(z_i > (z_i.max() / 2))
width_guess_i = yy_i_above_half_max / gaussian_sigma_to_fwhm
Expand Down Expand Up @@ -346,6 +347,16 @@ def __post_init__(self):
# TODO: implement smoothing with provided width
y_bins[i] = ilum2[z_i.argmax()]

# warn about fully-masked bins
if len(warn_bins) > 0:
plural = 's' if len(warn_bins) == 1 else ''
# if there are a ton of bins, we don't want to print them all out
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.')

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

Expand Down

0 comments on commit 5c33943

Please sign in to comment.