diff --git a/pypeit/metadata.py b/pypeit/metadata.py index 22b4bd8890..1bb2358779 100644 --- a/pypeit/metadata.py +++ b/pypeit/metadata.py @@ -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 @@ -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() @@ -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). @@ -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: @@ -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): @@ -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 @@ -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): @@ -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(): @@ -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): """ @@ -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'``, @@ -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) @@ -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]'] diff --git a/pypeit/pypeit.py b/pypeit/pypeit.py index 103c539b69..458dc4ecac 100644 --- a/pypeit/pypeit.py +++ b/pypeit/pypeit.py @@ -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) diff --git a/pypeit/scripts/setup.py b/pypeit/scripts/setup.py index 257577c08a..8d61ca08ca 100644 --- a/pypeit/scripts/setup.py +++ b/pypeit/scripts/setup.py @@ -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, @@ -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) diff --git a/pypeit/spectrographs/keck_nirspec_high.py b/pypeit/spectrographs/keck_nirspec_high.py index 6e42758ebd..80941742ea 100644 --- a/pypeit/spectrographs/keck_nirspec_high.py +++ b/pypeit/spectrographs/keck_nirspec_high.py @@ -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): @@ -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':