From 9f206a48d6eeae482e8db57ca2e6a2226a2801e8 Mon Sep 17 00:00:00 2001 From: Debora Pelliccia Date: Tue, 4 Feb 2025 15:57:14 -1000 Subject: [PATCH 1/2] added the masking with params --- pypeit/edgetrace.py | 26 ++++++++++++++++++++++++++ pypeit/par/pypeitpar.py | 9 +++++++-- pypeit/spectrographs/keck_hires.py | 1 + 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/pypeit/edgetrace.py b/pypeit/edgetrace.py index be6d75d9fe..6cdd9e6a1f 100644 --- a/pypeit/edgetrace.py +++ b/pypeit/edgetrace.py @@ -5655,6 +5655,32 @@ def get_slits(self): specmin = specmin[indx]/binspec specmax = specmax[indx]/binspec + if self.par['mask_off_detector']: + # check and mask portions of the slits/orders that are more than 50% off the detector + _slits = self.edge_fit[:,gpm].reshape(self.nspec, -1, 2) + # for each left and right edge + for s in range(_slits.shape[1]): + # get the median slit length, calculated using also the off-detector edges + med_slit_len = np.median(_slits[:,s,1] - _slits[:,s,0]) + # bool arrays for slits that are off the detector on the left and right side + off_det_left = _slits[:, s, 0] < 0 + off_det_right = _slits[:, s, 1] > self.nspat + # now measure the actual slit lengths, i.e., using the detector edges + # as the slit edges if they are off the detector + slits_actual = _slits.copy() + if np.any(off_det_left): + slits_actual[off_det_left, s, 0] = 0 + if np.any(off_det_right): + slits_actual[off_det_right, s, 1] = self.nspat + # actual slit lengths + slit_lens_actual = slits_actual[:, s, 1] - slits_actual[:, s, 0] + # find where the actual slit length is less than 50% of the median slit length + off_det_indx = np.where(np.logical_not((slit_lens_actual < 0.5 * med_slit_len)))[0] + # set the specmin and specmax for the off-detector regions + if off_det_indx.size > 0: + specmin[s] = np.maximum(specmin[s], off_det_indx[0]) + specmax[s] = np.minimum(specmax[s], off_det_indx[-1]) + # Define spat_id (in the same way is done in SlitTraceSet) to add it in the astropy table. It # is useful to have spat_id in that table. center = (left + right) / 2 diff --git a/pypeit/par/pypeitpar.py b/pypeit/par/pypeitpar.py index cbd4e27d04..4792e0c899 100644 --- a/pypeit/par/pypeitpar.py +++ b/pypeit/par/pypeitpar.py @@ -3284,7 +3284,7 @@ def __init__(self, filt_iter=None, sobel_mode=None, edge_thresh=None, sobel_enha order_gap_poly=None, order_fitrej=None, order_outlier=None, order_spat_range=None, overlap=None, max_overlap=None, use_maskdesign=None, maskdesign_maxsep=None, maskdesign_step=None, maskdesign_sigrej=None, pad=None, add_slits=None, - add_predict=None, rm_slits=None, maskdesign_filename=None): + add_predict=None, rm_slits=None, maskdesign_filename=None, mask_off_detector=None): # Grab the parameter names and values from the function # arguments @@ -3351,6 +3351,11 @@ def __init__(self, filt_iter=None, sobel_mode=None, edge_thresh=None, sobel_enha 'Should be two integers, e.g. 100,150 trims 100 pixels from the ' \ 'short wavelength end and 150 pixels from the long wavelength ' \ 'end of the spectral axis of the detector.' + + defaults['mask_off_detector'] = False + dtypes['mask_off_detector'] = bool + descr['mask_off_detector'] = 'Mask off the portions of the slits/orders that are' \ + 'more that 50% off the detector.' defaults['max_shift_abs'] = 0.5 dtypes['max_shift_abs'] = [int, float] @@ -3841,7 +3846,7 @@ def from_dict(cls, cfg): 'order_gap_poly', 'order_fitrej', 'order_outlier', 'order_spat_range','overlap', 'max_overlap', 'use_maskdesign', 'maskdesign_maxsep', 'maskdesign_step', 'maskdesign_sigrej', 'maskdesign_filename', 'pad', 'add_slits', 'add_predict', - 'rm_slits'] + 'rm_slits', 'mask_off_detector'] badkeys = np.array([pk not in parkeys for pk in k]) if np.any(badkeys): diff --git a/pypeit/spectrographs/keck_hires.py b/pypeit/spectrographs/keck_hires.py index 7ba80d00be..a87fed5766 100644 --- a/pypeit/spectrographs/keck_hires.py +++ b/pypeit/spectrographs/keck_hires.py @@ -114,6 +114,7 @@ def default_pypeit_par(cls): par['calibrations']['slitedges']['max_nudge'] = 0. par['calibrations']['slitedges']['overlap'] = True par['calibrations']['slitedges']['dlength_range'] = 0.25 + par['calibrations']['slitedges']['mask_off_detector'] = True par['calibrations']['slitedges']['add_missed_orders'] = True par['calibrations']['slitedges']['order_width_poly'] = 2 From d453a885ef725019fc5583cd8369bec84a799ad6 Mon Sep 17 00:00:00 2001 From: Debora Pelliccia Date: Tue, 4 Feb 2025 16:30:17 -1000 Subject: [PATCH 2/2] small typo --- pypeit/par/pypeitpar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypeit/par/pypeitpar.py b/pypeit/par/pypeitpar.py index 4792e0c899..24c15c33a9 100644 --- a/pypeit/par/pypeitpar.py +++ b/pypeit/par/pypeitpar.py @@ -3354,7 +3354,7 @@ def __init__(self, filt_iter=None, sobel_mode=None, edge_thresh=None, sobel_enha defaults['mask_off_detector'] = False dtypes['mask_off_detector'] = bool - descr['mask_off_detector'] = 'Mask off the portions of the slits/orders that are' \ + descr['mask_off_detector'] = 'Mask off the portions of the slits/orders that are ' \ 'more that 50% off the detector.' defaults['max_shift_abs'] = 0.5