def test_instantiate(fitstbl): par = pypeitpar.PypeItPar() spectrograph = load_kast_blue_masters(get_spectrograph=True)[0] caliBrate = calibrations.MultiSlitCalibrations(fitstbl, par['calibrations'], spectrograph) print(caliBrate)
def test_instantiate(fitstbl): par = pypeitpar.PypeItPar() spectrograph = load_spectrograph('shane_kast_blue') caliBrate = calibrations.MultiSlitCalibrations(fitstbl, par['calibrations'], spectrograph, data_path('Masters'))
def multi_caliBrate(fitstbl): det = 1 spectrograph = load_kast_blue_masters(get_spectrograph=True)[0] # Par def_par = spectrograph.default_pypeit_par() # Grab a science file for configuration specific parameters for idx, row in enumerate(fitstbl): if 'science' in row['frametype']: sci_file = os.path.join(row['directory'], row['filename']) break par = spectrograph.config_specific_par(def_par, sci_file) # calib_par = par['calibrations'] calib_par['badpix'] = False calib_par['biasframe']['useframe'] = 'overscan' redux_path = data_path('') if os.getenv('PYPEIT_DEV') is None \ else os.path.join(os.getenv('PYPEIT_DEV'), 'Cooked') multi_caliBrate = calibrations.MultiSlitCalibrations(fitstbl, calib_par, spectrograph, redux_path=redux_path, save_masters=False, write_qa=False) # Find the first science row frame = fitstbl.find_frames('science', index=True)[0] # Set multi_caliBrate.set_config(frame, det, par=calib_par) return multi_caliBrate
def multi_caliBrate(fitstbl): spectrograph = load_spectrograph('shane_kast_blue') # Grab a science file for configuration specific parameters for idx, row in enumerate(fitstbl): if 'science' in row['frametype']: sci_file = os.path.join(row['directory'], row['filename']) break # Par par = spectrograph.config_specific_par(sci_file) # calib_par = par['calibrations'] calib_par['badpix'] = False calib_par['biasframe']['useframe'] = 'none' # Only use overscan multi_caliBrate = calibrations.MultiSlitCalibrations( fitstbl, calib_par, spectrograph) return reset_calib(multi_caliBrate)
def multi_caliBrate(fitstbl): # Grab a science file for configuration specific parameters for idx, row in enumerate(fitstbl): if 'science' in row['frametype']: sci_file = os.path.join(row['directory'], row['filename']) break # Par spectrograph = load_spectrograph('shane_kast_blue') par = spectrograph.config_specific_par(sci_file) turn_off = dict(use_biasimage=False) par.reset_all_processimages_par(**turn_off) # calib_par = par['calibrations'] calib_par['bpm_usebias'] = False #calib_par['biasframe']['useframe'] = 'none' # Only use overscan calib_par['slitedges']['sync_predict'] = 'nearest' multi_caliBrate = calibrations.MultiSlitCalibrations( fitstbl, calib_par, spectrograph, data_path('Masters')) return reset_calib(multi_caliBrate)
def __init__(self, pypeit_file, verbosity=2, overwrite=True, reuse_masters=False, logname=None, show=False, redux_path=None): # Load cfg_lines, data_files, frametype, usrdata, setups = parse_pypeit_file(pypeit_file, runtime=True) self.pypeit_file = pypeit_file # Spectrograph cfg = ConfigObj(cfg_lines) spectrograph_name = cfg['rdx']['spectrograph'] self.spectrograph = load_spectrograph(spectrograph_name) # Par # Defaults spectrograph_def_par = self.spectrograph.default_pypeit_par() # Grab a science file for configuration specific parameters sci_file = None for idx, row in enumerate(usrdata): if 'science' in row['frametype']: sci_file = data_files[idx] break # Set spectrograph_cfg_lines = self.spectrograph.config_specific_par(spectrograph_def_par, sci_file).to_config() self.par = PypeItPar.from_cfg_lines(cfg_lines=spectrograph_cfg_lines, merge_with=cfg_lines) # Fitstbl self.fitstbl = PypeItMetaData(self.spectrograph, self.par, file_list=data_files, usrdata=usrdata, strict=True) # The following could be put in a prepare_to_run() method in PypeItMetaData if 'setup' not in self.fitstbl.keys(): self.fitstbl['setup'] = setups[0] self.fitstbl.get_frame_types(user=frametype) # This sets them using the user inputs self.fitstbl.set_defaults() # Only does something if values not set in PypeIt file self.fitstbl._set_calib_group_bits() self.fitstbl._check_calib_groups() # Write .calib file (For QA naming amongst other things) calib_file = pypeit_file.replace('.pypeit', '.calib') self.fitstbl.write_calib(calib_file) # Other Internals self.logname = logname self.overwrite = overwrite # Currently the runtime argument determines the behavior for reuse_masters. There is also a reuse_masters # parameter in the parset but it is currently ignored. self.reuse_masters=reuse_masters self.show = show # Make the output directories self.par['rdx']['redux_path'] = os.getcwd() if redux_path is None else redux_path msgs.info("Setting reduction path to {:s}".format(self.par['rdx']['redux_path'])) paths.make_dirs(self.spectrograph.spectrograph, self.par['calibrations']['caldir'], self.par['rdx']['scidir'], self.par['rdx']['qadir'], overwrite=self.overwrite, redux_path=self.par['rdx']['redux_path']) # Instantiate Calibrations class self.caliBrate \ = calibrations.MultiSlitCalibrations(self.fitstbl, self.par['calibrations'], self.spectrograph, redux_path=self.par['rdx']['redux_path'], reuse_masters=self.reuse_masters, save_masters=True, write_qa=True, show=self.show) # Init self.verbosity = verbosity # TODO: I don't think this ever used self.frame = None self.det = None self.tstart = None self.basename = None self.sciI = None self.obstime = None
def __init__(self, pypeit_file, verbosity=2, overwrite=True, reuse_masters=False, logname=None, show=False, redux_path=None): # Load cfg_lines, data_files, frametype, usrdata, setups \ = parse_pypeit_file(pypeit_file, runtime=True) self.pypeit_file = pypeit_file # Spectrograph cfg = ConfigObj(cfg_lines) spectrograph_name = cfg['rdx']['spectrograph'] self.spectrograph = load_spectrograph(spectrograph_name, ifile=data_files[0]) msgs.info('Loaded spectrograph {0}'.format( self.spectrograph.spectrograph)) # -------------------------------------------------------------- # Get the full set of PypeIt parameters # - Grab a science or standard file for configuration specific parameters scistd_file = None for idx, row in enumerate(usrdata): if ('science' in row['frametype']) or ('standard' in row['frametype']): scistd_file = data_files[idx] break # - Configuration specific parameters for the spectrograph if scistd_file is not None: msgs.info( 'Setting configuration-specific parameters using {0}'.format( os.path.split(scistd_file)[1])) spectrograph_cfg_lines = self.spectrograph.config_specific_par( scistd_file).to_config() # - Build the full set, merging with any user-provided # parameters self.par = PypeItPar.from_cfg_lines(cfg_lines=spectrograph_cfg_lines, merge_with=cfg_lines) msgs.info('Built full PypeIt parameter set.') # Check the output paths are ready if redux_path is not None: self.par['rdx']['redux_path'] = redux_path # TODO: Write the full parameter set here? # -------------------------------------------------------------- # -------------------------------------------------------------- # Build the meta data # - Re-initilize based on the file data msgs.info('Compiling metadata') self.fitstbl = PypeItMetaData(self.spectrograph, self.par, files=data_files, usrdata=usrdata, strict=True) # - Interpret automated or user-provided data from the PypeIt # file self.fitstbl.finalize_usr_build(frametype, setups[0]) # -------------------------------------------------------------- # - Write .calib file (For QA naming amongst other things) calib_file = pypeit_file.replace('.pypeit', '.calib') self.fitstbl.write_calib(calib_file) # Other Internals self.logname = logname self.overwrite = overwrite # Currently the runtime argument determines the behavior for # reuse_masters. self.reuse_masters = reuse_masters self.show = show # Set paths if self.par['calibrations']['caldir'] == 'default': self.calibrations_path = os.path.join( self.par['rdx']['redux_path'], 'Masters') else: self.calibrations_path = self.par['calibrations']['caldir'] # Report paths msgs.info('Setting reduction path to {0}'.format( self.par['rdx']['redux_path'])) msgs.info('Master calibration data output to: {0}'.format( self.calibrations_path)) msgs.info('Science data output to: {0}'.format(self.science_path)) msgs.info('Quality assessment plots output to: {0}'.format( self.qa_path)) # TODO: Is anything written to the qa dir or only to qa/PNGs? # Should we have separate calibration and science QA # directories? # Instantiate Calibrations class self.caliBrate \ = calibrations.MultiSlitCalibrations(self.fitstbl, self.par['calibrations'], self.spectrograph, caldir=self.calibrations_path, qadir=self.qa_path, reuse_masters=self.reuse_masters, show=self.show) # Init self.verbosity = verbosity # TODO: I don't think this ever used self.frame = None self.det = None self.tstart = None self.basename = None self.sciI = None self.obstime = None
def test_reuse(multi_caliBrate, fitstbl): """ Test that Calibrations appropriately reuses existing calibrations frames. """ # In case of previous data or failures if os.path.isdir(multi_caliBrate.master_dir): shutil.rmtree(multi_caliBrate.master_dir) os.makedirs(multi_caliBrate.master_dir) # Perform the calibrations and check that the data are correctly # stored in memory multi_caliBrate.shape = (2048, 350) multi_caliBrate.get_bpm() # Make them all # assert list(multi_caliBrate_reuse.calib_dict.keys()) == ['A_1_01'], 'Incorrect master key' # assert list(multi_caliBrate_reuse.calib_dict['A_1_01'].keys()) == ['bpm'], \ # 'Incorrect list of master types in memory' msarc = multi_caliBrate.get_arc() # assert list(multi_caliBrate_reuse.calib_dict['A_1_01'].keys()) == ['bpm', 'arc'], \ # 'Incorrect list of master types in memory' msarc = multi_caliBrate.get_tiltimg() # assert list(multi_caliBrate_reuse.calib_dict['A_1_01'].keys()) == ['bpm', 'arc', 'tiltimg'], \ # 'Incorrect list of master types in memory' multi_caliBrate.get_slits() # assert list(multi_caliBrate_reuse.calib_dict['A_1_01'].keys()) == ['bpm', 'arc', 'tiltimg', 'trace'], \ # 'Incorrect list of master types in memory' multi_caliBrate.get_wv_calib() # assert list(multi_caliBrate_reuse.calib_dict['A_1_01'].keys()) \ # == ['bpm', 'arc', 'tiltimg','trace', 'wavecalib'], \ # 'Incorrect list of master types in memory' multi_caliBrate.get_tilts() # assert list(multi_caliBrate_reuse.calib_dict['A_1_01'].keys()) \ # == ['bpm', 'arc', 'tiltimg', 'trace', 'wavecalib', 'wavetilts'], \ # 'Incorrect list of master types in memory' multi_caliBrate.get_flats() # assert list(multi_caliBrate_reuse.calib_dict['A_1_01'].keys()) \ # == ['bpm', 'arc', 'tiltimg', 'trace', 'wavecalib', 'wavetilts', # 'flatimages'], \ # 'Incorrect list of master types in memory' # Reset #reset_calib(multi_caliBrate_reuse) spectrograph = load_spectrograph('shane_kast_blue') par = spectrograph.default_pypeit_par() multi_caliBrate_reuse = calibrations.MultiSlitCalibrations( fitstbl, par['calibrations'], spectrograph, data_path('Masters')) multi_caliBrate_reuse.reuse_masters = True reset_calib(multi_caliBrate_reuse) # Read the calibrations # - These don't source a master file multi_caliBrate_reuse.shape = (2048, 350) multi_caliBrate_reuse.get_bpm() # - The arc is the first sourced master assert 'arc' not in multi_caliBrate_reuse.master_key_dict.keys(), \ 'arc master key should not be defined yet' _msarc = multi_caliBrate_reuse.get_arc() assert multi_caliBrate_reuse.msarc is not None, 'Should find cached data.' _msarc = multi_caliBrate_reuse.get_tiltimg() assert multi_caliBrate_reuse.mstilt is not None, 'Should find cached data.' # JXP took these out of the class #assert os.path.isfile(multi_caliBrate_reuse.arcImage.master_file_path), \ # 'Should find master file.' #assert multi_caliBrate_reuse.arcImage.load() is not None, \ # 'Load should not return None' # - Make sure the rest of the steps complete multi_caliBrate_reuse.get_slits() multi_caliBrate_reuse.get_wv_calib() multi_caliBrate_reuse.get_tilts() multi_caliBrate_reuse.get_flats() # Clean-up shutil.rmtree(multi_caliBrate_reuse.master_dir)