Skip to content

Commit

Permalink
add internal choice of which width of wavelet-transformed array to us…
Browse files Browse the repository at this point in the history
…e for pinpointing peaks
  • Loading branch information
chris-simpson committed Mar 22, 2021
1 parent 11b43e3 commit db508ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion geminidr/core/primitives_spect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,11 +1706,13 @@ def findSourceApertures(self, adinputs=None, **params):
else:
# TODO: find_peaks might not be best considering we have no
# idea whether sources will be extended or not
# We only use the lightly-smoothed profile to pinpoint
# the peak positions
widths = np.arange(3, 20)
peaks_and_snrs = tracing.find_peaks(
profile, widths, mask=prof_mask & DQ.not_signal,
variance=1.0 if this_use_snr else None, reject_bad=False,
min_snr=3, min_frac=0.2)
min_snr=3, min_frac=0.2, pinpoint_index=0)

if peaks_and_snrs.size == 0:
log.warning("Found no sources")
Expand Down
9 changes: 7 additions & 2 deletions gempy/library/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def estimate_peak_width(data, mask=None):
return sigma_clip(widths).mean()

def find_peaks(data, widths, mask=None, variance=None, min_snr=1, min_sep=1,
min_frac=0.25, reject_bad=True):
min_frac=0.25, reject_bad=True, pinpoint_index=-1):
"""
Find peaks in a 1D array. This uses scipy.signal routines, but requires some
duplication of that code since the _filter_ridge_lines() function doesn't
Expand All @@ -412,6 +412,10 @@ def find_peaks(data, widths, mask=None, variance=None, min_snr=1, min_sep=1,
minimum fraction of *widths* values at which a peak must be found
reject_bad : bool
clip lines using the reject_bad() function?
pinpoint_index : int / None
which index (in the wavelet-transformed array, ordered by "widths")
should be used for determining more the more accurate peak positions
(None => use untransformed data)
Returns
-------
Expand Down Expand Up @@ -443,7 +447,8 @@ def find_peaks(data, widths, mask=None, variance=None, min_snr=1, min_sep=1,
# not affected by noise or problems with broad, flat-topped features.
# There appears to be a bias with narrow Ricker transforms, so we use the
# broadest one for this purpose.
pinpoint_data = wavelet_transformed_data[-1]
pinpoint_data = (data if pinpoint_index is None else
wavelet_transformed_data[pinpoint_index])

# If no variance is supplied we estimate S/N from pixel-to-pixel variations
if variance is not None:
Expand Down

0 comments on commit db508ce

Please sign in to comment.