Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask off-detector slits/orders #1897

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pypeit/edgetrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5723,6 +5723,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
Expand Down
9 changes: 7 additions & 2 deletions pypeit/par/pypeitpar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3294,7 +3294,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
Expand Down Expand Up @@ -3361,6 +3361,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]
Expand Down Expand Up @@ -3883,7 +3888,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']

# Find the list of keywords provded in `cfg` that are *not* valid
badkeys = np.array([pk not in parkeys for pk in k])
Expand Down
1 change: 1 addition & 0 deletions pypeit/spectrographs/keck_hires.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down