Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Jan 23, 2024
1 parent b8c65c3 commit dbd79b0
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions specreduce/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,14 @@ def _fit_trace(self, img):
warn_bins = []
for i in range(self.bins):

# binned column (sum) if bins < ncols. otherwise, just columns.
# binned columns, summed along disp. axis.
# or just a single, unbinned column if no bins
z_i = img[ilum2, x_bins[i]:x_bins[i+1]].sum(axis=self._disp_axis)

if self.peak_method == 'gaussian':
# if binned column is fully masked for peak_method='gaussian',
# the fit value for this bin should be nan, then continue to next
warn_msg = 'nan'

if z_i.mask.all():
warn_bins.append(i)
y_bins[i] = np.nan
Expand Down Expand Up @@ -355,26 +356,23 @@ def _fit_trace(self, img):
if z_i.mask.all(): # all-masked bins when peak_method is 'centroid' or 'max'
warn_bins.append(i)

elif self.peak_method == 'centroid':
if self.peak_method == 'centroid':
z_i_cumsum = np.cumsum(z_i)
# find the interpolated index where the cumulative array reaches
# half the total cumulative values
y_bins[i] = np.interp(z_i_cumsum[-1]/2., z_i_cumsum, ilum2)

# warning message for fully masked bin
# NOTE this reflects current behavior, should eventually be changed
# to set to nan by default (or zero fill / interpoate option once
# available) and warn accordingly.
warn_msg = f'largest bin index ({str(z_i_cumsum.shape[0])})'
# available)

elif self.peak_method == 'max':
# TODO: implement smoothing with provided width
y_bins[i] = ilum2[z_i.argmax()]

# warning message for fully masked bin
# NOTE: should eventually be changed to set to nan by default
# (or zero fill / interpoate option onceavailable) and warn.
warn_msg = 'zero'
# NOTE: a fully masked should eventually be changed to set to
# nan by default (or zero fill / interpoate option once available)


# warn about fully-masked bins
if len(warn_bins) > 0:
Expand All @@ -383,10 +381,14 @@ def _fit_trace(self, img):
if len(warn_bins) > 20:
warn_bins = warn_bins[0: 10] + ['...'] + [warn_bins[-1]]

# warning message printed out depends on `peak_method`
warn_msgs = {'gaussian': 'nan', 'max': 'zero',
'centroid': f'largest bin index ({str(img.shape[0])})'}

warnings.warn(f"All pixels in {'bins' if len(warn_bins) else 'bin'} "
f"{', '.join([str(x) for x in warn_bins])}"
" are fully masked. Setting bin"
f" peak{'s' if len(warn_bins) else ''} to {warn_msg}.")
f" peak{'s' if len(warn_bins) else ''} to {warn_msgs[self.peak_method]}.")

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

0 comments on commit dbd79b0

Please sign in to comment.