def test_init(): # Init files = get_files() setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue') assert len(setupc.steps) == 0 assert setupc.nfiles == 0
def test_setup_keck_deimos_multiconfig_clean(): root = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA', 'keck_deimos') files = glob.glob(os.path.join(root, '830G_L_8100', '*fits*')) files += glob.glob(os.path.join(root, '830G_L_8400', '*fits*')) ps = pypeitsetup.PypeItSetup(files, spectrograph_name='keck_deimos') ps.build_fitstbl(strict=False) ps.get_frame_types(flag_unknown=True) # Test that the correct number of configurations are found cfgs = ps.fitstbl.unique_configurations() assert len(cfgs) == 2, 'Should find 2 configurations' # Test that the bias is assigned to the correct configuration ps.fitstbl.set_configurations(cfgs) biases = np.where(ps.fitstbl.find_frames('bias'))[0] assert biases.size == 1, 'Should only be 1 bias' assert ps.fitstbl['setup'][biases[0]] == 'B', 'Bias should be in configuration group B' # Table should have 25 rows assert len(ps.fitstbl) == 25, 'Incorrect number of table rows.' # All frames should be from valid configurations ps.fitstbl.clean_configurations() assert len(ps.fitstbl) == 25, 'Incorrect number of table rows.' # Artificially set the amplifier and mode of two frames to be # invalid ps.fitstbl['amp'][0] = 'SINGLE:A' ps.fitstbl['mode'][1] = 'Direct' ps.fitstbl.clean_configurations() # Those two frames should have been removed assert len(ps.fitstbl) == 23, 'Incorrect number of table rows.'
def test_run_setup(): files = get_files() # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue') # Run par, spectrograph, fitstbl = setupc.run(setup_only=True) # Test assert par is None
def test_run_calcheck(): # Check for files files = get_files() # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue') # Run par, spectrograph, fitstbl = setupc.run(calibration_check=True) # Test assert isinstance(par, pypeitpar.PypeItPar)
def test_setup_keck_deimos_multiconfig(): root = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA', 'keck_deimos') files = glob.glob(os.path.join(root, '830G_L_8100', '*fits*')) files += glob.glob(os.path.join(root, '830G_L_8400', '*fits*')) output_path = os.path.join(os.getcwd(), 'output') if os.path.isdir(output_path): shutil.rmtree(output_path) os.makedirs(output_path) ps = pypeitsetup.PypeItSetup(files, spectrograph_name='keck_deimos') ps.run(setup_only=True, sort_dir=output_path) # Write the automatically generated pypeit data pypeit_files = ps.fitstbl.write_pypeit(output_path, cfg_lines=ps.user_cfg, write_bkg_pairs=True) assert len(pypeit_files) == 2, 'Should have created two pypeit files' # Test the pypeit files for the correct configuration and # calibration group results for f, s, c in zip(pypeit_files, ['A', 'B'], ['0', '1']): # TODO: All of this front-end stuff, pulled from pypeit.py, should # be put into a function. # Read the pypeit file cfg_lines, data_files, frametype, usrdata, setups = parse_pypeit_file( f, runtime=True) # Spectrograph cfg = ConfigObj(cfg_lines) spectrograph = load_spectrograph(cfg['rdx']['spectrograph']) # Configuration-specific parameters for idx, row in enumerate(usrdata): if 'science' in row['frametype'] or 'standard' in row['frametype']: break spectrograph_cfg_lines = spectrograph.config_specific_par( data_files[idx]).to_config() # PypeIt parameters par = PypeItPar.from_cfg_lines(cfg_lines=spectrograph_cfg_lines, merge_with=cfg_lines) # Metadata fitstbl = PypeItMetaData(spectrograph, par, files=data_files, usrdata=usrdata, strict=True) fitstbl.finalize_usr_build(frametype, setups[0]) assert np.all(fitstbl['setup'] == s), 'Setup is wrong' assert np.all(fitstbl['calib'] == c), 'Calibration group is wrong' # Clean-up shutil.rmtree(output_path)
def test_run(): # Check for files files = get_files() # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue') # Run par, spectrograph, fitstbl = setupc.run() # Test assert isinstance(par, pypeitpar.PypeItPar) assert isinstance(fitstbl, PypeItMetaData)
def test_build_fitstbl(): # Check for files file_root = os.path.join(os.getenv('PYPEIT_DEV'), 'RAW_DATA/shane_kast_blue/600_4310_d55/b') files = glob.glob(file_root + '*') assert len(files) > 0 # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue', path=data_path('')) # fitstbl = setupc.build_fitstbl(files) assert isinstance(fitstbl, Table) assert setupc.nfiles == 26
def test_run_setup(): files = get_files() # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue', path=data_path('')) # Run par, spectrograph, fitstbl = setupc.run(setup_only=True, sort_dir=data_path('')) # Test assert par is None # Cleanup os.remove(data_path('shane_kast_blue.sorted'))
def test_run_calcheck(): # Check for files files = get_files() # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue', path=data_path('')) # Run par, spectrograph, fitstbl = setupc.run(calibration_check=True, sort_dir=data_path('')) # Test assert isinstance(par, pypeitpar.PypeItPar) # Cleanup os.remove(data_path('shane_kast_blue.calib'))
def test_type(): # Check for files files = get_files() # Init cfg_lines = [ '[rdx]', 'spectrograph = shane_kast_blue', '[calibrations]', '[[standardframe]]', 'exprng = None,60', '[scienceframe]', 'exprng = 60,None' ] setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue', cfg_lines=cfg_lines) setupc.build_fitstbl(files) setupc.get_frame_types(flag_unknown=True) assert np.sum(setupc.fitstbl.find_frames('science')) == 2
def test_run(): # Check for files files = get_files() # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue', path=data_path('')) # Run par, spectrograph, fitstbl = setupc.run(sort_dir=data_path('')) # Test assert isinstance(par, pypeitpar.PypeItPar) assert isinstance(fitstbl, PypeItMetaData) #assert isinstance(setup_dict, dict) # Cleanup os.remove(data_path('shane_kast_blue.calib'))
def test_image_type(): # Check for files files = get_files() # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue') fitstbl = setupc.build_fitstbl(files) # Type setupc.get_frame_types(flag_unknown=True) assert 'framebit' in setupc.fitstbl.keys() assert np.sum(setupc.fitstbl.find_frames('arc')) == 1 assert np.sum(setupc.fitstbl.find_frames('None')) == 0 assert np.sum( setupc.fitstbl.find_frames('pixelflat') & setupc.fitstbl.find_frames('trace')) == 12
def test_run_on_bad_headers(): files = get_lrisr_files() # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='keck_lris_red', path=data_path('')) # Run par, spectrograph, fitstbl = setupc.run(setup_only=True, sort_dir=data_path('')) # Test idx = np.where( setupc.fitstbl['filename'] == 'LR.20160216.05709.fits.gz')[0] assert par is None assert setupc.fitstbl['ra'][idx][0] is None assert len(setupc.fitstbl) == 23 # Cleanup os.remove(data_path('keck_lris_red.sorted'))
def test_build_fitstbl(): # Check for files file_root = os.path.join(os.getenv('PYPEIT_DEV'), 'RAW_DATA/Shane_Kast_blue/600_4310_d55/b') files = glob.glob(file_root + '*') assert len(files) > 0 # Init setupc = pypeitsetup.PypeItSetup(files, spectrograph_name='shane_kast_blue') # fitstbl = setupc.build_fitstbl(files) assert isinstance(fitstbl, Table) assert setupc.nfiles == 26 # I/O setupc.write_metadata(ofile=data_path('fitstbl.fits')) tmp = setupc.load_metadata(data_path('fitstbl.fits')) assert len(tmp) == 26
def make_example_sorted_file(): root = os.path.join(os.environ['PYPEIT_DEV'], 'RAW_DATA', 'keck_deimos') files = glob.glob(os.path.join(root, '830G_L_8100', '*fits*')) files += glob.glob(os.path.join(root, '830G_L_8400', '*fits*')) ps = pypeitsetup.PypeItSetup(files, spectrograph_name='keck_deimos') ps.run(setup_only=True) sfile = os.path.abspath('keck_deimos.sorted') oroot = os.path.join( os.path.split(os.path.abspath(resource_filename('pypeit', '')))[0], 'doc', 'include') ofile = os.path.join(oroot, 'keck_deimos.sorted.rst') with open(ofile, 'w') as f: with open(sfile, 'r') as p: lines = p.readlines() f.write('.. code-block:: console\n') f.write('\n') for l in lines: f.write(' ' + l) f.write('\n\n') os.remove(sfile)
def main(args): import os import sys import numpy as np from IPython import embed from pypeit import pypeit from pypeit import pypeitsetup from pypeit.core import framematch from pypeit import msgs # Setup data_files = [os.path.join(args.full_rawpath, args.fileA), os.path.join(args.full_rawpath,args.fileB)] ps = pypeitsetup.PypeItSetup(data_files, path='./', spectrograph_name='keck_nires') ps.build_fitstbl() # TODO -- Get the type_bits from 'science' bm = framematch.FrameTypeBitMask() file_bits = np.zeros(2, dtype=bm.minimum_dtype()) file_bits[0] = bm.turn_on(file_bits[0], ['arc', 'science', 'tilt']) file_bits[1] = bm.turn_on(file_bits[0], ['arc', 'science', 'tilt']) ps.fitstbl.set_frame_types(file_bits) ps.fitstbl.set_combination_groups() # Extras ps.fitstbl['setup'] = 'A' # A-B ps.fitstbl['bkg_id'] = [2,1] # Calibrations master_dir = os.getenv('NIRES_MASTERS') if master_dir is None: msgs.error('You need to set an Environmental variable NIRES_MASTERS that points at the ' 'Master Calibs') # Config the run cfg_lines = ['[rdx]'] cfg_lines += [' spectrograph = {0}'.format('keck_nires')] cfg_lines += [' redux_path = {0}'.format(os.path.join(os.getcwd(),'keck_nires_A'))] # Calibrations cfg_lines += ['[baseprocess]'] cfg_lines += [' use_biasimage = False'] cfg_lines += [' use_overscan = False'] cfg_lines += [' use_pixelflat = False'] cfg_lines += ['[calibrations]'] cfg_lines += [' master_dir = {0}'.format(master_dir)] cfg_lines += [' raise_chk_error = False'] cfg_lines += ['[scienceframe]'] cfg_lines += [' [[process]]'] cfg_lines += [' mask_cr = False'] cfg_lines += ['[reduce]'] cfg_lines += [' [[extraction]]'] cfg_lines += [' skip_optimal = True'] if args.box_radius is not None: # Boxcar radius cfg_lines += [' boxcar_radius = {0}'.format(args.box_radius)] cfg_lines += [' [[findobj]]'] cfg_lines += [' skip_second_find = True'] # Write ofiles = ps.fitstbl.write_pypeit(configs='A', write_bkg_pairs=True, cfg_lines=cfg_lines) if len(ofiles) > 1: msgs.error("Bad things happened..") # Instantiate the main pipeline reduction object pypeIt = pypeit.PypeIt(ofiles[0], verbosity=2, reuse_masters=True, overwrite=True, logname='nires_proc_AB.log', show=False) # Run pypeIt.reduce_all() msgs.info('Data reduction complete') # QA HTML msgs.info('Generating QA HTML') pypeIt.build_qa() return 0
def main(args): # Build the fitstable since we currently need it for output. This should not be the case! A_files = [os.path.join(args.full_rawpath, file) for file in args.Afiles] B_files = [os.path.join(args.full_rawpath, file) for file in args.Bfiles] data_files = A_files + B_files ps = pypeitsetup.PypeItSetup(A_files, path='./', spectrograph_name='keck_mosfire') ps.build_fitstbl() fitstbl = ps.fitstbl # Read in the spectrograph, config the parset spectrograph = load_spectrograph('keck_mosfire') spectrograph_def_par = spectrograph.default_pypeit_par() parset = par.PypeItPar.from_cfg_lines( cfg_lines=spectrograph_def_par.to_config(), merge_with=config_lines(args)) science_path = os.path.join(parset['rdx']['redux_path'], parset['rdx']['scidir']) # Calibration Master directory if args.master_dir is None: msgs.error( "You need to set an Environmental variable MOSFIRE_MASTERS that points at the Master Calibs" ) # Define some hard wired master files here to be later parsed out of the directory slit_masterframe_name = os.path.join(args.master_dir, 'MasterSlits_E_15_01.fits.gz') tilts_masterframe_name = os.path.join(args.master_dir, 'MasterTilts_E_1_01.fits') wvcalib_masterframe_name = os.path.join(args.master_dir, 'MasterWaveCalib_E_1_01.fits') # For now don't require a standard std_outfile = None #std_outfile = os.path.join('/Users/joe/Dropbox/PypeIt_Redux/MOSFIRE/Nov19/quicklook/Science/', # 'spec1d_m191118_0064-GD71_MOSFIRE_2019Nov18T104704.507.fits') # make the get_std from pypeit a utility function or class method det = 1 # MOSFIRE has a single detector if std_outfile is not None: # Get the standard trace if need be sobjs = specobjs.SpecObjs.from_fitsfile(std_outfile) this_det = sobjs.DET == det if np.any(this_det): sobjs_det = sobjs[this_det] sobjs_std = sobjs_det.get_std() std_trace = None if sobjs_std is None else sobjs_std.TRACE_SPAT.flatten( ) else: std_trace = None else: std_trace = None # Read in the msbpm sdet = get_dnum(det, prefix=False) msbpm = spectrograph.bpm(A_files[0], det) # Read in the slits slits = slittrace.SlitTraceSet.from_file(slit_masterframe_name) # Reset the bitmask slits.mask = slits.mask_init.copy() # Read in the wv_calib wv_calib = wavecalib.WaveCalib.from_file(wvcalib_masterframe_name) wv_calib.is_synced(slits) slits.mask_wvcalib(wv_calib) # Read in the tilts tilts_obj = wavetilts.WaveTilts.from_file(tilts_masterframe_name) tilts_obj.is_synced(slits) slits.mask_wavetilts(tilts_obj) # Build Science image sciImg = buildimage.buildimage_fromlist(spectrograph, det, parset['scienceframe'], A_files, bpm=msbpm, slits=slits, ignore_saturation=False) # Background Image? sciImg = sciImg.sub( buildimage.buildimage_fromlist(spectrograph, det, parset['scienceframe'], B_files, bpm=msbpm, slits=slits, ignore_saturation=False), parset['scienceframe']['process']) # Build the Calibrate object caliBrate = calibrations.Calibrations(None, parset['calibrations'], spectrograph, None) caliBrate.slits = slits caliBrate.wavetilts = tilts_obj caliBrate.wv_calib = wv_calib # Instantiate Reduce object # Required for pypeline specific object # At instantiaton, the fullmask in self.sciImg is modified redux = reduce.Reduce.get_instance(sciImg, spectrograph, parset, caliBrate, 'science', ir_redux=True, show=args.show, det=det, std_outfile=std_outfile) manual_extract_dict = None skymodel, objmodel, ivarmodel, outmask, sobjs, waveImg, tilts = redux.run( std_trace=std_trace, return_negative=True, manual_extract_dict=manual_extract_dict, show_peaks=args.show) # TODO -- Do this upstream # Tack on detector for sobj in sobjs: sobj.DETECTOR = sciImg.detector # Construct the Spec2DObj with the positive image spec2DObj_A = spec2dobj.Spec2DObj(det=det, sciimg=sciImg.image, ivarraw=sciImg.ivar, skymodel=skymodel, objmodel=objmodel, ivarmodel=ivarmodel, waveimg=waveImg, bpmmask=outmask, detector=sciImg.detector, sci_spat_flexure=sciImg.spat_flexure, tilts=tilts, slits=copy.deepcopy(caliBrate.slits)) spec2DObj_A.process_steps = sciImg.process_steps all_spec2d = spec2dobj.AllSpec2DObj() all_spec2d['meta']['ir_redux'] = True all_spec2d[det] = spec2DObj_A # Save image A but with all the objects extracted, i.e. positive and negative #outfile2d, outfile1d = save_exposure(fitstbl, 0, spectrograph, science_path, parset, caliBrate, all_spec2d, sobjs) # Construct the Spec2DObj with the negative image spec2DObj_B = spec2dobj.Spec2DObj(det=det, sciimg=-sciImg.image, ivarraw=sciImg.ivar, skymodel=-skymodel, objmodel=-objmodel, ivarmodel=ivarmodel, waveimg=waveImg, bpmmask=outmask, detector=sciImg.detector, sci_spat_flexure=sciImg.spat_flexure, tilts=tilts, slits=copy.deepcopy(caliBrate.slits)) # Parse the offset information out of the headers. TODO in the future get this out of fitstable dither_pattern_A, dither_id_A, offset_arcsec_A = parse_dither_pattern( A_files, spectrograph.primary_hdrext) dither_pattern_B, dither_id_B, offset_arcsec_B = parse_dither_pattern( B_files, spectrograph.primary_hdrext) # Print out a report on the offsets msg_string = msgs.newline( ) + '****************************************************' msg_string += msgs.newline( ) + ' Summary of offsets for dither pattern: {:s}'.format( dither_pattern_A[0]) msg_string += msgs.newline( ) + '****************************************************' msg_string += msgs.newline( ) + 'Position filename arcsec pixels ' msg_string += msgs.newline( ) + '----------------------------------------------------' for iexp, file in enumerate(A_files): msg_string += msgs.newline( ) + ' A {:s} {:6.2f} {:6.2f}'.format( os.path.basename(file), offset_arcsec_A[iexp], offset_arcsec_A[iexp] / sciImg.detector.platescale) for iexp, file in enumerate(B_files): msg_string += msgs.newline( ) + ' B {:s} {:6.2f} {:6.2f}'.format( os.path.basename(file), offset_arcsec_B[iexp], offset_arcsec_B[iexp] / sciImg.detector.platescale) msg_string += msgs.newline( ) + '****************************************************' msgs.info(msg_string) #offset_dith_pix = offset_dith_pix = offset_arcsec_A[0]/sciImg.detector.platescale offsets_dith_pix = (np.array([ 0.0, np.mean(offset_arcsec_B) - np.mean(offset_arcsec_A) ])) / sciImg.detector.platescale if args.offset is not None: offsets_pixels = np.array([0.0, args.offset]) msgs.info('Using user specified offsets instead: {:5.2f}'.format( args.offset)) else: offsets_pixels = offsets_dith_pix spec2d_list = [spec2DObj_A, spec2DObj_B] # Instantiate Coadd2d coadd = coadd2d.CoAdd2D.get_instance(spec2d_list, spectrograph, parset, det=det, offsets=offsets_pixels, weights='uniform', ir_redux=True, debug=args.show, samp_fact=args.samp_fact) # Coadd the slits coadd_dict_list = coadd.coadd( only_slits=None, interp_dspat=False) # TODO implement only_slits later # Create the pseudo images pseudo_dict = coadd.create_pseudo_image(coadd_dict_list) ########################## # Now display the images # ########################## display.display.connect_to_ginga(raise_err=True, allow_new=True) # Bug in ginga prevents me from using cuts here for some reason #mean, med, sigma = sigma_clipped_stats(pseudo_dict['imgminsky'][pseudo_dict['inmask']], sigma_lower=5.0,sigma_upper=5.0) #cut_min = mean - 4.0 * sigma #cut_max = mean + 4.0 * sigma chname_skysub = 'skysub-det{:s}'.format(sdet) # Clear all channels at the beginning # TODO: JFH For some reason Ginga crashes when I try to put cuts in here. viewer, ch = ginga.show_image(pseudo_dict['imgminsky'], chname=chname_skysub, waveimg=pseudo_dict['waveimg'], clear=True) # cuts=(cut_min, cut_max), slit_left, slit_righ, _ = pseudo_dict['slits'].select_edges() slit_id = slits.slitord_id[0] ginga.show_slits(viewer, ch, slit_left, slit_righ, slit_ids=slit_id) # SKRESIDS chname_skyresids = 'sky_resid-det{:s}'.format(sdet) image = pseudo_dict['imgminsky'] * np.sqrt( pseudo_dict['sciivar']) * pseudo_dict['inmask'] # sky residual map viewer, ch = ginga.show_image( image, chname_skyresids, waveimg=pseudo_dict['waveimg'], cuts=(-5.0, 5.0), ) ginga.show_slits(viewer, ch, slit_left, slit_righ, slit_ids=slits.slitord_id[0]) shell = viewer.shell() out = shell.start_global_plugin('WCSMatch') out = shell.call_global_plugin_method('WCSMatch', 'set_reference_channel', [chname_skyresids], {}) if args.embed: embed() return 0
def main(pargs): import os import numpy as np from IPython import embed from pypeit import pypeit from pypeit import pypeitsetup from pypeit.core import framematch spec = pargs.spectrograph # Config the run cfg_lines = ['[rdx]'] cfg_lines += [' spectrograph = {0}'.format(spec)] cfg_lines += [ ' redux_path = {0}_A'.format(os.path.join(os.getcwd(), spec)) ] cfg_lines += [' detnum = {0}'.format(pargs.det)] if pargs.ignore_headers: cfg_lines += [' ignore_bad_headers = True'] cfg_lines += ['[scienceframe]'] cfg_lines += [' [[process]]'] cfg_lines += [' cr_reject = False'] if pargs.user_pixflat is not None: cfg_lines += ['[calibrations]'] cfg_lines += [' [[flatfield]]'] cfg_lines += [' frame = {0}'.format(pargs.user_pixflat)] cfg_lines += ['[reduce]'] cfg_lines += [' [[extraction]]'] cfg_lines += [' skip_optimal = True'] if pargs.box_radius is not None: # Boxcar radius cfg_lines += [' boxcar_radius = {0}'.format(pargs.box_radius)] cfg_lines += [' [[findobj]]'] cfg_lines += [' skip_second_find = True'] # Data files data_files = [ os.path.join(pargs.full_rawpath, pargs.arc), os.path.join(pargs.full_rawpath, pargs.flat), os.path.join(pargs.full_rawpath, pargs.science) ] # Setup ps = pypeitsetup.PypeItSetup(data_files, path='./', spectrograph_name=spec, cfg_lines=cfg_lines) ps.build_fitstbl() # TODO -- Get the type_bits from 'science' bm = framematch.FrameTypeBitMask() file_bits = np.zeros(3, dtype=bm.minimum_dtype()) file_bits[0] = bm.turn_on(file_bits[0], ['arc', 'tilt']) file_bits[1] = bm.turn_on( file_bits[1], ['pixelflat', 'trace'] if pargs.user_pixflat is None else 'trace') file_bits[2] = bm.turn_on(file_bits[2], 'science') # PypeItSetup sorts according to MJD # Deal with this asrt = [] for ifile in data_files: bfile = os.path.basename(ifile) idx = ps.fitstbl['filename'].data.tolist().index(bfile) asrt.append(idx) asrt = np.array(asrt) # Set bits ps.fitstbl.set_frame_types(file_bits[asrt]) ps.fitstbl.set_combination_groups() # Extras ps.fitstbl['setup'] = 'A' # Write ofiles = ps.fitstbl.write_pypeit('', configs=['A'], write_bkg_pairs=True, cfg_lines=cfg_lines) if len(ofiles) > 1: msgs.error("Bad things happened..") # Instantiate the main pipeline reduction object pypeIt = pypeit.PypeIt(ofiles[0], verbosity=2, reuse_masters=True, overwrite=True, logname='mos.log', show=False) # Run pypeIt.reduce_all() msgs.info('Data reduction complete') # QA HTML msgs.info('Generating QA HTML') pypeIt.build_qa() return 0
def main(pargs): import os import numpy as np from IPython import embed from pypeit import pypeit from pypeit import pypeitsetup from pypeit.core import framematch spec = 'keck_deimos' # Setup data_files = [ os.path.join(pargs.full_rawpath, pargs.arc), os.path.join(pargs.full_rawpath, pargs.flat), os.path.join(pargs.full_rawpath, pargs.science) ] ps = pypeitsetup.PypeItSetup(data_files, path='./', spectrograph_name=spec) ps.build_fitstbl() # TODO -- Get the type_bits from 'science' bm = framematch.FrameTypeBitMask() bits = [ bm.bits[iftype] for iftype in ['arc', 'pixelflat', 'trace', 'science', 'tilt'] ] ps.fitstbl.set_frame_types( np.array( [2**bits[0] + 2**bits[4], 2**bits[1] + 2**bits[2], 2**bits[3]])) # 1=arc, 16=pixelflat, 32=science, trace=128 ps.fitstbl.set_combination_groups() # Extras ps.fitstbl['setup'] = 'A' # Config the run rdx_path = '{0}_A'.format(os.path.join(os.getcwd(), spec)) cfg_lines = ['[rdx]'] cfg_lines += [' spectrograph = {0}'.format(spec)] cfg_lines += [' redux_path = {0}'.format(rdx_path)] cfg_lines += [' detnum = {0}'.format(pargs.det)] cfg_lines += ['[calibrations]'] cfg_lines += [' [[scienceframe]]'] cfg_lines += [' [[process]]'] cfg_lines += [' cr_reject = False'] cfg_lines += ['[scienceimage]'] cfg_lines += [' boxcar_only = True'] cfg_lines += [' skip_second_find = True'] # Boxcar radius if pargs.box_radius is not None: cfg_lines += [' boxcar_radius = {0}'.format(pargs.box_radius)] # Write ofiles = ps.fitstbl.write_pypeit('', configs=['A'], write_bkg_pairs=True, cfg_lines=cfg_lines) if len(ofiles) > 1: msgs.error("Bad things happened..") # Instantiate the main pipeline reduction object pypeIt = pypeit.PypeIt(ofiles[0], verbosity=2, reuse_masters=True, overwrite=True, logname='deimos.log', show=False) # Run pypeIt.reduce_all() msgs.info('Data reduction complete') # QA HTML msgs.info('Generating QA HTML') pypeIt.build_qa() return 0