Skip to content

Commit

Permalink
Implementing manual flexure shift
Browse files Browse the repository at this point in the history
  • Loading branch information
Adolfo1519 committed Nov 6, 2023
1 parent 99b0478 commit ef2e377
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
31 changes: 24 additions & 7 deletions pypeit/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, spectrograph, par, files=None, data=None, usrdata=None,
self.merge(usrdata)

# Impose types on specific columns
self._impose_types(['comb_id', 'bkg_id', 'manual'], [int, int, str])
self._impose_types(['comb_id', 'bkg_id', 'manual', 'shift'], [int, int, str, float])

# Initialize internal attributes
self.configs = None
Expand Down Expand Up @@ -354,7 +354,7 @@ def remove_rows(self, rows, regroup=False):
"""
self.table.remove_rows(np.atleast_1d(rows))
if regroup:
for col in ['setup', 'calib', 'calibbit', 'comb_id', 'bkg_id']:
for col in ['setup', 'calib', 'calibbit', 'comb_id', 'bkg_id', 'shift']:
if col in self.keys():
del self.table[col]
self.set_configurations()
Expand Down Expand Up @@ -1446,7 +1446,7 @@ def get_frame_types(self, flag_unknown=False, user=None, merge=True):
msgs.info("Typing completed!")
return self.set_frame_types(type_bits, merge=merge)

def set_pypeit_cols(self, write_bkg_pairs=False, write_manual=False):
def set_pypeit_cols(self, write_bkg_pairs=False, write_manual=False, write_shift = False):
"""
Generate the list of columns to be included in the fitstbl
(nearly the complete list).
Expand All @@ -1457,6 +1457,9 @@ def set_pypeit_cols(self, write_bkg_pairs=False, write_manual=False):
and bkg_id
write_manual (:obj:`bool`, optional):
Add additional ``PypeIt`` columns for manual extraction
write_shift (:obj:`bool`, optional):
Add additional ``PypeIt`` columns for manual flexure
correction
Returns:
Expand All @@ -1474,12 +1477,18 @@ def set_pypeit_cols(self, write_bkg_pairs=False, write_manual=False):
# manual
if write_manual:
extras += ['manual']
if write_shift:
print('')
print('Adding Shift Column')
print('')
extras += ['shift']
for key in extras:
if key not in columns:
columns += [key]

print('Column list is: ', columns)
# Take only those present
output_cols = np.array(columns)
print('Output cols will be ', output_cols[np.isin(output_cols, self.keys())].tolist())
return output_cols[np.isin(output_cols, self.keys())].tolist()

def set_combination_groups(self, assign_objects=True):
Expand Down Expand Up @@ -1510,6 +1519,8 @@ def set_combination_groups(self, assign_objects=True):
self['comb_id'] = -1
if 'bkg_id' not in self.keys():
self['bkg_id'] = -1
if 'shift' not in self.keys():
self['shift'] = 0

# NOTE: Importantly, this if statement means that, if the user has
# defined any non-negative combination IDs in their pypeit file, none of
Expand Down Expand Up @@ -1544,6 +1555,8 @@ def set_user_added_columns(self):
"""
if 'manual' not in self.keys():
self['manual'] = ''
if 'shift' not in self.keys():
self['shift'] = 0

def write_sorted(self, ofile, overwrite=True, ignore=None,
write_bkg_pairs=False, write_manual=False):
Expand Down Expand Up @@ -1586,7 +1599,7 @@ def write_sorted(self, ofile, overwrite=True, ignore=None,
# Grab output columns
output_cols = self.set_pypeit_cols(write_bkg_pairs=write_bkg_pairs,
write_manual=write_manual)

print('Columns being used are: ', output_cols)
cfgs = self.unique_configurations(copy=ignore is not None)
if ignore is not None:
for key in cfgs.keys():
Expand Down Expand Up @@ -1628,6 +1641,7 @@ def write_sorted(self, ofile, overwrite=True, ignore=None,

def write_pypeit(self, output_path=None, cfg_lines=None,
write_bkg_pairs=False, write_manual=False,
write_shift = False,
configs=None, config_subdir=True,
version_override=None, date_override=None):
"""
Expand Down Expand Up @@ -1656,6 +1670,9 @@ def write_pypeit(self, output_path=None, cfg_lines=None,
object and background frame pairs.
write_manual (:obj:`bool`, optional):
Add additional ``PypeIt`` columns for manual extraction
write_shift (:obj:`bool`, optional):
Add additional ``PypeIt`` columns for manual spatial flexure
correction
configs (:obj:`str`, :obj:`list`, optional):
One or more strings used to select the configurations
to include in the returned objects. If ``'all'``,
Expand Down Expand Up @@ -1703,7 +1720,8 @@ def write_pypeit(self, output_path=None, cfg_lines=None,

# Grab output columns
output_cols = self.set_pypeit_cols(write_bkg_pairs=write_bkg_pairs,
write_manual=write_manual)
write_manual=write_manual,
write_shift = write_shift)

# Write the pypeit files
ofiles = [None]*len(cfg_keys)
Expand Down Expand Up @@ -1746,7 +1764,6 @@ def write_pypeit(self, output_path=None, cfg_lines=None,
#with io.StringIO() as ff:
# subtbl.write(ff, format='ascii.fixed_width')
# data_lines = ff.getvalue().split('\n')[:-1]

# Config lines
if cfg_lines is None:
cfg_lines = ['[rdx]']
Expand Down
13 changes: 11 additions & 2 deletions pypeit/pypeit.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,19 @@ def objfind_one(self, frames, det, bg_frames=None, std_outfile=None):

# Flexure
spat_flexure = None
# use the flexure correction in the "shift" column
manual_flexure = self.fitstbl[frames[0]]['shift']
if (self.objtype == 'science' and self.par['scienceframe']['process']['spat_flexure_correct']) or \
(self.objtype == 'standard' and self.par['calibrations']['standardframe']['process']['spat_flexure_correct']):
spat_flexure = sciImg.spat_flexure
(self.objtype == 'standard' and self.par['calibrations']['standardframe']['process']['spat_flexure_correct']) or \
manual_flexure:
if manual_flexure:
msgs.info(f'Implementing manual flexure of {manual_flexure}')
spat_flexure = manual_flexure
sciImg.spat_flexure = spat_flexure
else:
spat_flexure = sciImg.spat_flexure
# Build the initial sky mask
msgs.info(f'Flexure being used is: {spat_flexure}')
initial_skymask = self.load_skyregions(initial_slits=self.spectrograph.pypeline != 'SlicerIFU',
scifile=sciImg.files[0], frame=frames[0], spat_flexure=spat_flexure)

Expand Down
3 changes: 3 additions & 0 deletions pypeit/scripts/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def get_parser(cls, width=None):
'\'A,B\' or \'B,D,E\' or \'E\'.')
parser.add_argument('-b', '--background', default=False, action='store_true',
help='Include the background-pair columns for the user to edit')
parser.add_argument('-f', '--flexure', default=False, action='store_true',
help='Include the manual spatial shift (flexure) column for the user to edit')
parser.add_argument('-m', '--manual_extraction', default=False, action='store_true',
help='Include the manual extraction column for the user to edit')
parser.add_argument('-v', '--verbosity', type=int, default=1,
Expand Down Expand Up @@ -122,6 +124,7 @@ def main(args):
pypeit_files = ps.fitstbl.write_pypeit(output_path=output_path, cfg_lines=ps.user_cfg,
write_bkg_pairs=args.background,
write_manual=args.manual_extraction,
write_shift = args.flexure,
configs=configs,
version_override=args.version_override,
date_override=args.date_override)
Expand Down
4 changes: 2 additions & 2 deletions pypeit/spectrographs/keck_nirspec_high.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def pypeit_file_keys(self):
pypeit_keys = super().pypeit_file_keys()
# TODO: Why are these added here? See
# pypeit.metadata.PypeItMetaData.set_pypeit_cols
pypeit_keys += ['comb_id', 'bkg_id']
pypeit_keys += ['comb_id', 'bkg_id', 'shift']
return pypeit_keys

def get_echelle_angle_files(self, lamps_list, filter1, filter2):
Expand Down Expand Up @@ -593,7 +593,7 @@ def config_specific_par(self, scifile, inp_par=None):
par['calibrations']['wavelengths']['xcorr_offset_minmax'] = 0.25
par['calibrations']['wavelengths']['xcorr_percent_ceil'] = 99.9
par['calibrations']['wavelengths']['echelle_pad'] = 1
par['calibrations']['slitedges']['rm_slits'] = '1:'
#par['calibrations']['slitedges']['rm_slits'] = '1:'


if decker == '0.144x12':
Expand Down

0 comments on commit ef2e377

Please sign in to comment.