Skip to content

Commit

Permalink
small improv
Browse files Browse the repository at this point in the history
  • Loading branch information
debora-pe committed Nov 22, 2024
1 parent 9f05c66 commit da9e7a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions pypeit/core/flexure.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def spat_flexure_shift(sciimg, slits, bpm=None, maxlag=20, sigdetect=10., debug=
slits_sobel, _ = trace.detect_slit_edges(slitmask, bpm=bpm)
# collapse both sobel images along the spectral direction
sci_smash, _, _ = sigma_clipped_stats(sci_sobel, axis=0, mask=bpm)
slits_smash, _, _ = sigma_clipped_stats(slits_sobel, axis=0, mask=bpm)
# no need for sigma clipping for the slitmask
slits_smash = np.mean(slits_sobel, axis=0)
# remove nan values
sci_smash[np.isnan(sci_smash)] = 0
slits_smash[np.isnan(slits_smash)] = 0
# invert the negative values
sci_smash[sci_smash < 0] *= -1
slits_smash[slits_smash < 0] *= -1
Expand All @@ -106,6 +106,11 @@ def spat_flexure_shift(sciimg, slits, bpm=None, maxlag=20, sigdetect=10., debug=
corr_sci = wvutils.get_xcorr_arc(sci_smash, cont_sub=True, percent_ceil=10., sigdetect=sigdetect, debug=debug)
corr_slits = wvutils.get_xcorr_arc(slits_smash, cont_sub=False, percent_ceil=None, input_thresh=1., debug=debug)

if np.all(corr_sci == 0) or np.all(corr_slits == 0):
msgs.warn('No peak detected in the collapsed sobel images. Assuming there is NO SPATIAL FLEXURE.'
+ msgs.newline() + 'If a flexure is expected, consider either changing the '
'"spat_flexure_sigdetect" parameter, or use the manual flexure correction.')

# run x-cross correlation
lags, xcorr = utils.cross_correlate(corr_sci, corr_slits, maxlag)
xcorr_denom = np.sqrt(np.sum(corr_sci*corr_sci)*np.sum(corr_slits*corr_slits))
Expand Down Expand Up @@ -171,6 +176,12 @@ def spat_flexure_qa(img, slits, shift, gpm=None, vrange=None, outfile=None):
"""
debug = True if outfile is None else False

# check that vrange is a tuple
if vrange is not None and not isinstance(vrange, tuple):
msgs.warn('vrange must be a tuple with the min and max values for the imshow plot. Ignoring vrange.')
vrange = None

# TODO: should we use initial or tweaked slits in this plot?
left_slits, right_slits, mask_slits = slits.select_edges(initial=True, flexure=None)
left_flex, right_flex, mask = slits.select_edges(initial=True, flexure=shift)
Expand Down
4 changes: 2 additions & 2 deletions pypeit/core/wavecal/wvutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def get_xcorr_arc(inspec1, sigdetect=5.0, input_thresh=None, sig_ceil=10.0, perc
ampl_clip = np.clip(ampl, None, ceil_upper)
if ampl_clip.size == 0:
msgs.warn('No lines were detected in the arc spectrum. Cannot create a synthetic arc spectrum for cross-correlation.')
return None
return np.zeros_like(inspec1)

# Make a fake arc by plopping down Gaussians at the location of every centroided line we found
xcorr_arc = np.zeros_like(inspec1)
Expand Down Expand Up @@ -756,7 +756,7 @@ def xcorr_shift_stretch(inspec1, inspec2, cc_thresh=-1.0, percent_ceil=50.0, use
y2 = get_xcorr_arc(inspec2, percent_ceil=percent_ceil, use_raw_arc=use_raw_arc, sigdetect=sigdetect,
sig_ceil=sig_ceil, fwhm=fwhm)

if y1 is None or y2 is None:
if np.all(y1 == 0) or np.all(y2 == 0):
msgs.warn('No lines detected punting on shift/stretch')
return 0, None, None, None, None, None, None

Expand Down

0 comments on commit da9e7a1

Please sign in to comment.