def xidl_arcspec(xidl_file, slit): xidl_dict = readsav(xidl_file) if xidl_dict['archive_arc'].ndim == 2: nspec = xidl_dict['archive_arc'].shape[0] npix = xidl_dict['archive_arc'].shape[1] else: npix = xidl_dict['archive_arc'].shape[0] # This is the best one (well-centered) calib = xidl_dict['calib'][slit] # Generate the wavelengths if calib['FUNC'] == b'CHEBY': wv_air = cheby_val(calib['FFIT'], np.arange(npix), calib['NRM'], calib['NORD']) elif calib['FUNC'] == b'POLY': wv_air = poly_val(calib['FFIT'], np.arange(npix), calib['NRM']) wv_vac = airtovac(wv_air * units.AA) if xidl_dict['archive_arc'].ndim == 2: spec = xidl_dict['archive_arc'][slit] else: spec = xidl_dict['archive_arc'] # Flip to blue to red? if wv_vac[1] < wv_vac[0]: wv_vac = wv_vac[::-1] spec = spec[::-1] # Return return wv_vac.value, spec
def read_ascii(tbl_file, in_vac=True): """ The columns need to be wave, flux And the data should be monoonically increasing in wavelength Args: tbl_file (str): file of the table in_vac (bool, optional): If True, wavelenghts are already in vacuum Returns: tuple: np.ndarray, np.ndarray of wavelength, flux """ arc_spec = Table.read(tbl_file, format='ascii') # Wavelengths wv_vac = arc_spec['wave'] if not in_vac: wv_vac = airtovac(wv_vac * units.AA) # Return return wv_vac.value, arc_spec['flux']
def main(flg): # Keck LRISb if flg & (2**0): # B300, all lamps binspec = 1 slits = [15] xidl_file = os.path.join(template_path, 'Keck_LRIS', 'B300', 'lris_blue_300.sav') outroot = 'keck_lris_blue_300_d680.fits' build_template(xidl_file, slits, None, binspec, outroot, lowredux=True) if flg & (2**1): # B400, all lamps I think) binspec = 2 outroot='keck_lris_blue_400_d560.fits' slits = [19,14] lcut = [5500.] xidl_file = os.path.join(template_path, 'Keck_LRIS', 'B400', 'lris_blue_400_d560.sav') build_template(xidl_file, slits, lcut, binspec, outroot, lowredux=True) if flg & (2**2): # B600, all lamps binspec = 2 outroot='keck_lris_blue_600_d560.fits' slits = [0,7] lcut = [4500.] wfile = os.path.join(template_path, 'Keck_LRIS', 'B600', 'MasterWaveCalib_A_1_01.json') build_template(wfile, slits, lcut, binspec, outroot, lowredux=False) if flg & (2**3): # B1200, all lamps? binspec = 2 outroot='keck_lris_blue_1200_d460.fits' slits = [19,44] lcut = [3700.] xidl_file = os.path.join(template_path, 'Keck_LRIS', 'B1200', 'lris_blue_1200.sav') build_template(xidl_file, slits, lcut, binspec, outroot, lowredux=True) # Shane Kastb if flg & (2**4): # 452/3306 binspec = 1 slits = [0] xidl_file = os.path.join(template_path, 'Shane_Kast', '452_3306', 'kast_452_3306.sav') outroot = 'shane_kast_blue_452.fits' build_template(xidl_file, slits, None, binspec, outroot, lowredux=True) if flg & (2**5): # 600/4310 binspec = 1 slits = [0,3] lcut = [4550.] xidl_file = os.path.join(template_path, 'Shane_Kast', '600_4310', 'kast_600_4310.sav') outroot = 'shane_kast_blue_600.fits' build_template(xidl_file, slits, lcut, binspec, outroot, lowredux=True) if flg & (2**6): # 830/3460 binspec = 1 slits = [0] xidl_file = os.path.join(template_path, 'Shane_Kast', '830_3460', 'kast_830_3460.sav') outroot = 'shane_kast_blue_830.fits' build_template(xidl_file, slits, None, binspec, outroot, lowredux=True) # Keck/DEIMOS if flg & (2**7): # 600ZD :: Might not go red enough binspec = 1 slits = [0,1] lcut = [7192.] xidl_file = os.path.join(template_path, 'Keck_DEIMOS', '600ZD', 'deimos_600.sav') outroot = 'keck_deimos_600.fits' build_template(xidl_file, slits, lcut, binspec, outroot, lowredux=True) if flg & (2**8): # 830G binspec = 1 outroot='keck_deimos_830G.fits' # 3-12 = blue 6508 -- 8410 # 7-24 = blue 8497 -- 9925 (no lines after XeI) ifiles = [0, 0, 1] slits = [12, 14, 24] lcut = [8400., 8480] wfile1 = os.path.join(template_path, 'Keck_DEIMOS', '830G_M_8600', 'MasterWaveCalib_A_1_03.json') wfile2 = os.path.join(template_path, 'Keck_DEIMOS', '830G_M_8600', 'MasterWaveCalib_A_1_07.json') # det_dict det_cut = {} det_cut['dets'] = [[1,2,3,4], [5,6,7,8]] det_cut['wcuts'] = [[0,9000.], [8200,1e9]] # Significant overlap is fine # build_template([wfile1,wfile2], slits, lcut, binspec, outroot, lowredux=False, ifiles=ifiles, det_cut=det_cut) if flg & (2**9): # 1200 binspec = 1 outroot='keck_deimos_1200G.fits' # 3-3 = blue 6268.23 -- 7540 # 3-14 = red 6508 -- 7730 # 7-3 = blue 7589 -- 8821 # 7-17 = red 8000 - 9230 # 7c-0 = red 9120 -- 9950 ifiles = [0, 0, 1, 1, 2] slits = [3, 14, 3, 17, 0] lcut = [7450., 7730., 8170, 9120] wfile1 = os.path.join(template_path, 'Keck_DEIMOS', '1200G', 'MasterWaveCalib_A_1_03.json') wfile2 = os.path.join(template_path, 'Keck_DEIMOS', '1200G', 'MasterWaveCalib_A_1_07.json') wfile3 = os.path.join(template_path, 'Keck_DEIMOS', '1200G', 'MasterWaveCalib_A_1_07c.json') # det_dict det_cut = None #det_cut = {} #det_cut['dets'] = [[1,2,3,4], [5,6,7,8]] #det_cut['wcuts'] = [[0,9000.], [8200,1e9]] # Significant overlap is fine # build_template([wfile1,wfile2,wfile3], slits, lcut, binspec, outroot, lowredux=False, ifiles=ifiles, det_cut=det_cut, chk=True) # ###############################################3 # Keck/LRISr if flg & (2**10): # R400 binspec = 2 outroot='keck_lris_red_400.fits' slits = [7] # Quite blue, but not the bluest lcut = [] wfile = os.path.join(template_path, 'Keck_LRIS', 'R400', 'MasterWaveCalib_A_1_01.json') build_template(wfile, slits, lcut, binspec, outroot, lowredux=False) if flg & (2**11): # R1200 # slits = [2-3] # 7726 -- 9250 # slits = [1-4] # 9250 -- 9925 binspec = 1 outroot='keck_lris_red_1200_9000.fits' ifiles = [0, 1] slits = [3, 7] lcut = [9250.] wfile1 = os.path.join(template_path, 'Keck_LRIS', 'R1200_9000', 'MasterWaveCalib_A_1_02.json') # Original Dev wfile2 = os.path.join(template_path, 'Keck_LRIS', 'R1200_9000', 'MasterWaveCalib_A_1_01.json') # Dev suite 2x1 build_template([wfile1,wfile2], slits, lcut, binspec, outroot, lowredux=False, ifiles=ifiles) if flg & (2**12): # R600/5000 # slits = [1-4] # 5080 -- 7820 # slits = [1-7] # 7820 -- 9170 binspec = 2 outroot='keck_lris_red_600_5000.fits' slits = [4, 7] lcut = [7820.] wfile = os.path.join(template_path, 'Keck_LRIS', 'R600_5000', 'MasterWaveCalib_B_1_01.json') build_template(wfile, slits, lcut, binspec, outroot, lowredux=False) if flg & (2**27): # R600/7500 # slits = [1-10] # 5000 -- 7840 # slits = [1-4] # 7840 -- 9230 binspec = 2 outroot='keck_lris_red_600_7500.fits' slits = [10, 4] lcut = [7840.] wfile = os.path.join(template_path, 'Keck_LRIS', 'R600_7500', 'MasterWaveCalib_I_1_01.json') build_template(wfile, slits, lcut, binspec, outroot, lowredux=False, chk=True, normalize=True, subtract_conti=True) # ################################## # Magellan/MagE if flg & (2**13): # Load mase_path = os.path.join(os.getenv('XIDL_DIR'), 'Magellan', 'MAGE', 'mase', 'Calib') sav_file = os.path.join(mase_path, 'MagE_wvguess_jfh.idl') mase_dict = readsav(sav_file) mase_sol = Table(mase_dict['all_arcfit']) # Do it all_wave = np.zeros((2048, 15)) all_flux = np.zeros_like(all_wave) for order in np.arange(15): all_flux[:,order] = mase_dict['sv_aspec'][order] # Build the wavelengths wv_air = cheby_val(mase_sol['FFIT'][order], np.arange(2048), mase_sol['NRM'][order], mase_sol['NORD'][order]) all_wave[:,order] = airtovac(wv_air * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = np.arange(20, 5, -1, dtype=int) tbl.meta['BINSPEC'] = 1 # Write outroot='magellan_mage.fits' outfile = os.path.join(template_path, outroot) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**14): # Magellan/MagE Plots outpath = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'plots') new_mage_file = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv', 'magellan_mage.fits') # Load mage_wave = Table.read(new_mage_file) llist = waveio.load_line_lists(['ThAr_MagE']) # for kk in range(mage_wave['wave'].shape[1]): wv = mage_wave['wave'][:, kk] fx = mage_wave['flux'][:, kk] order = 20 - kk # Reidentify detections, spec_cont_sub, patt_dict = autoid.reidentify(fx, fx, wv, llist, 1) # Fit final_fit = fitting.fit_slit(fx, patt_dict, detections, llist) # Output outfile=os.path.join(outpath, 'MagE_order{:2d}_IDs.pdf'.format(order)) autoid.arc_fit_qa(final_fit, outfile=outfile, ids_only=True) print("Wrote: {}".format(outfile)) autoid.arc_fit_qa(final_fit, outfile=os.path.join(outpath, 'MagE_order{:2d}_full.pdf'.format(order))) if flg & (2**15): # VLT/X-Shooter reid_arxiv # VIS reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') for iroot, iout in zip(['vlt_xshooter_vis1x1.json', 'vlt_xshooter_nir.json'], ['vlt_xshooter_vis1x1.fits', 'vlt_xshooter_nir.fits']): # Load old_file = os.path.join(reid_path, iroot) odict, par = waveio.load_reid_arxiv(old_file) # Do it orders = odict['fit2d']['orders'][::-1].astype(int) # Flipped all_wave = np.zeros((odict['0']['nspec'], orders.size)) all_flux = np.zeros_like(all_wave) for kk,order in enumerate(orders): all_flux[:,kk] = odict[str(kk)]['spec'] if 'nir' in iroot: all_wave[:,kk] = odict[str(kk)]['wave_soln'] else: all_wave[:,kk] = airtovac(odict[str(kk)]['wave_soln'] * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**16): # VLT/X-Shooter line list line_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'lists') old_file = os.path.join(line_path, 'ThAr_XSHOOTER_VIS_air_lines.dat') # Load air_list = waveio.load_line_list(old_file) # Vacuum vac_wv = airtovac(air_list['wave']*units.AA).value vac_list = air_list.copy() vac_list['wave'] = vac_wv # Write new_file = os.path.join(line_path, 'ThAr_XSHOOTER_VIS_lines.dat') vac_list.write(new_file, format='ascii.fixed_width', overwrite=True) print("Wrote: {}".format(new_file)) if flg & (2**17): # NIRES reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = 'keck_nires.json' iout = 'keck_nires.fits' # Load old_file = os.path.join(reid_path, iroot) odict, par = waveio.load_reid_arxiv(old_file) # Do it orders = odict['fit2d']['orders'][::-1].astype(int) # Flipped all_wave = np.zeros((odict['0']['nspec'], orders.size)) all_flux = np.zeros_like(all_wave) for kk,order in enumerate(orders): all_flux[:,kk] = odict[str(kk)]['spec'] if 'nir' in iroot: all_wave[:,kk] = odict[str(kk)]['wave_soln'] else: all_wave[:,kk] = airtovac(odict[str(kk)]['wave_soln'] * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**18): # Gemini/GNIRS reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = 'gemini_gnirs.json' iout = 'gemini_gnirs.fits' # Load old_file = os.path.join(reid_path, iroot) odict, par = waveio.load_reid_arxiv(old_file) # Do it orders = odict['fit2d']['orders'][::-1].astype(int) # Flipped all_wave = np.zeros((odict['0']['nspec'], orders.size)) all_flux = np.zeros_like(all_wave) for kk,order in enumerate(orders): all_flux[:,kk] = odict[str(kk)]['spec'] if 'nir' in iroot: all_wave[:,kk] = odict[str(kk)]['wave_soln'] else: all_wave[:,kk] = airtovac(odict[str(kk)]['wave_soln'] * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) # ############################## if flg & (2**20): # GMOS R400 Hamamatsu binspec = 2 outroot='gemini_gmos_r400_ham.fits' # ifiles = [0, 1, 2, 3, 4] slits = [0, 2, 3, 0, 0] # Be careful with the order.. lcut = [5400., 6620., 8100., 9000.] wfile1 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_01_aa.json') wfile5 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_05_aa.json') # 5190 -- 6679 #wfile2 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_02_aa.json') wfile3 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_04_aa.json') wfile4 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_03_aa.json') wfile6 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_06_aa.json') # build_template([wfile1,wfile5,wfile3,wfile4, wfile6], slits, lcut, binspec, outroot, lowredux=False, ifiles=ifiles, chk=True, normalize=True, subtract_conti=True) # ############################## if flg & (2**21): # GMOS R400 E2V binspec = 2 outroot='gemini_gmos_r400_e2v.fits' # ifiles = [0, 1, 2] slits = [0, 0, 0] lcut = [6000., 7450] wfile1 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_1_01.json') wfile2 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_1_02.json') wfile3 = os.path.join(template_path, 'GMOS', 'R400', 'MasterWaveCalib_A_1_03.json') # build_template([wfile1,wfile2,wfile3], slits, lcut, binspec, outroot, lowredux=False, ifiles=ifiles, chk=True, normalize=True) # ############################## if flg & (2**22): # GMOS R400 Hamamatsu binspec = 2 outroot='gemini_gmos_b600_ham.fits' # ifiles = [0, 1, 2, 3, 4] slits = [0, 0, 0, 0, 0] lcut = [4250., 4547., 5250., 5615.] wfile1 = os.path.join(template_path, 'GMOS', 'B600', 'MasterWaveCalib_C_1_01.json') wfile5 = os.path.join(template_path, 'GMOS', 'B600', 'MasterWaveCalib_D_1_01.json') # - 4547 wfile2 = os.path.join(template_path, 'GMOS', 'B600', 'MasterWaveCalib_C_1_02.json') wfile4 = os.path.join(template_path, 'GMOS', 'B600', 'MasterWaveCalib_D_1_02.json') # 4610-5608 wfile3 = os.path.join(template_path, 'GMOS', 'B600', 'MasterWaveCalib_C_1_03.json') # build_template([wfile1,wfile5,wfile2,wfile4,wfile3], slits, lcut, binspec, outroot, lowredux=False, ifiles=ifiles, chk=True, normalize=True, subtract_conti=True, miny=-100.) if flg & (2**23): # WHT/ISIS iroot = 'wht_isis_blue_1200_4800.json' outroot = 'wht_isis_blue_1200_4800.fits' wfile = os.path.join(template_path, 'WHT_ISIS', '1200B', iroot) binspec = 2 slits = [0] lcut = [3200.] build_template(wfile, slits, lcut, binspec, outroot, lowredux=False) if flg & (2**24): # Magellan/FIRE reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = 'magellan_fire_echelle.json' iout = 'magellan_fire_echelle.fits' # Load old_file = os.path.join(reid_path, iroot) odict, par = waveio.load_reid_arxiv(old_file) # Do it orders = odict['fit2d']['orders'][::-1].astype(int) # Flipped all_wave = np.zeros((odict['0']['nspec'], orders.size)) all_flux = np.zeros_like(all_wave) for kk,order in enumerate(orders): all_flux[:,kk] = odict[str(kk)]['spec'] if 'nir' in iroot: all_wave[:,kk] = odict[str(kk)]['wave_soln'] else: all_wave[:,kk] = airtovac(odict[str(kk)]['wave_soln'] * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**25): # FIRE longslit binspec = 1 reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') outroot = 'magellan_fire_long.fits' xidl_file = os.path.join(os.getenv('FIRE_DIR'), 'LowDispersion', 'NeNeAr_archive_fit.fits') spec_file = os.path.join(os.getenv('FIRE_DIR'), 'LowDispersion', 'NeNeAr2.sav') fire_sol = Table.read(xidl_file) wave = cheby_val(fire_sol['FFIT'].data[0], np.arange(2048), fire_sol['NRM'].data[0], fire_sol['NORD'].data[0]) wv_vac = airtovac(wave * units.AA) xidl_dict = readsav(spec_file) flux = xidl_dict['arc1d'] write_template(wv_vac.value, flux, binspec, reid_path, outroot, det_cut=None) # Gemini/Flamingos2 if flg & (2**26): reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = ['Flamingos2_JH_JH.json','Flamingos2_HK_HK.json'] outroot=['Flamingos2_JH_JH.fits','Flamingos2_HK_HK.fits'] binspec = 1 slits = [0] lcut = [] for ii in range(len(iroot)): wfile = os.path.join(reid_path, iroot[ii]) build_template(wfile, slits, lcut, binspec, outroot[ii], lowredux=False) # MDM/OSMOS -- MDM4K if flg & (2 ** 28): # ArI 4159 -- 6800 wfile = os.path.join(template_path, 'MDM_OSMOS', 'MasterWaveCalib_MDM4K_01.json') outroot = 'mdm_osmos_mdm4k.fits' binspec = 1 slits = [0] lcut = [3200.] build_template(wfile, slits, lcut, binspec, outroot, lowredux=False, chk=True, subtract_conti=True)
def create_linelist(wavelength, spec, fwhm, sigdetec=2., cont_samp=10., line_name=None, file_root_name=None, iraf_frmt=False, debug=False, convert_air_to_vac=True): """ Create list of lines detected in a spectrum in a PypeIt compatible format. The name of the output file is file_root_name+'_lines.dat'. Parameters ---------- wavelength : np.array wavelength spec : np.array spectrum fwhm : float fwhm in pixels used for filtering out arc lines that are too wide and not considered in fits. Parameter of arc.detect_lines(). sigdetec : float sigma threshold above fluctuations for line detection. Parameter of arc.detect_lines(). Default = 2. cont_samp : float the number of samples across the spectrum used for continuum subtraction. Parameter of arc.detect_lines(). Default = 10. line_name : str name of the lines to listed in the file. file_root_name : str name of the file where the identified lines will be stored. The code automatically add '_lines.dat' at the end of the root name. iraf_frmt : bool if True, the file is written in the IRAF format (i.e. wavelength, ion name, amplitude). convert_air_to_vac (bool): If True, convert the wavelengths of the created linelist from air to vacuum """ msgs.info("Searching for peaks {} sigma above background".format(sigdetec)) tampl_true, tampl, tcent, twid, centerr, ww, arcnorm, nsig = arc.detect_lines( spec, sigdetect=sigdetec, fwhm=fwhm, cont_samp=cont_samp, debug=debug) peaks_good = tcent[ww] ampl_good = tampl[ww] # convert from pixel location to wavelength pixvec = np.arange(spec.size) wave_peak = scipy.interpolate.interp1d( pixvec, wavelength, bounds_error=False, fill_value='extrapolate')(peaks_good) # Convert to vacuum? if convert_air_to_vac: msgs.info("Converting wavelengths from air to vacuum") wave_peak = airtovac(wave_peak * units.AA).value npeak = len(wave_peak) ion = npeak * [str(line_name)] NIST = npeak * [1] Instr = npeak * [32] Source = npeak * ['wavemodel.py'] if iraf_frmt: msgs.info("Printing file in IRAF format: {}".format(file_root_name + '_iraf_lines.dat')) ion = np.array(ion) id_lines_iraf = np.vstack((np.round(wave_peak, 5), ion, np.round(ampl_good, 5))).T np.savetxt(file_root_name + '_iraf_lines.dat', id_lines_iraf, fmt="%15s %6s %15s", delimiter=" ") else: msgs.info("Printing file: {}".format(file_root_name + '_lines.dat')) dat = Table([wave_peak, ion, NIST, Instr, ampl_good, Source], names=('wave', 'ion', 'NIST', 'Instr', 'amplitude', 'Source')) dat.write(file_root_name + '_lines.dat', format='ascii.fixed_width')
def main(flg): # Keck LRISb if flg & (2**0): # B300, all lamps binspec = 1 slits = [15] xidl_file = os.path.join(template_path, 'Keck_LRIS', 'B300', 'lris_blue_300.sav') outroot = 'keck_lris_blue_300_d680.fits' build_template(xidl_file, slits, None, binspec, outroot, lowredux=True) if flg & (2**1): # B400, all lamps I think) binspec = 2 outroot = 'keck_lris_blue_400_d560.fits' slits = [19, 14] lcut = [5500.] xidl_file = os.path.join(template_path, 'Keck_LRIS', 'B400', 'lris_blue_400_d560.sav') build_template(xidl_file, slits, lcut, binspec, outroot, lowredux=True) if flg & (2**2): # B600, all lamps binspec = 2 outroot = 'keck_lris_blue_600_d560.fits' slits = [0, 7] lcut = [4500.] wfile = os.path.join(template_path, 'Keck_LRIS', 'B600', 'MasterWaveCalib_A_1_01.json') build_template(wfile, slits, lcut, binspec, outroot, lowredux=False) if flg & (2**3): # B1200, all lamps? binspec = 2 outroot = 'keck_lris_blue_1200_d460.fits' slits = [19, 44] lcut = [3700.] xidl_file = os.path.join(template_path, 'Keck_LRIS', 'B1200', 'lris_blue_1200.sav') build_template(xidl_file, slits, lcut, binspec, outroot, lowredux=True) # ###############################################3 # Keck/LRISr if flg & (2**10): # R400 binspec = 2 outroot = 'keck_lris_red_400.fits' slits = [7] # Quite blue, but not the bluest lcut = [] wfile = os.path.join(template_path, 'Keck_LRIS', 'R400', 'MasterWaveCalib_A_1_01.json') build_template(wfile, slits, lcut, binspec, outroot, lowredux=False) if flg & (2**11): # R1200 # slits = [2-3] # 7726 -- 9250 # slits = [1-4] # 9250 -- 9925 binspec = 1 outroot = 'keck_lris_red_1200_9000.fits' ifiles = [0, 1] slits = [3, 7] lcut = [9250.] wfile1 = os.path.join(template_path, 'Keck_LRIS', 'R1200_9000', 'MasterWaveCalib_A_1_02.json') # Original Dev wfile2 = os.path.join(template_path, 'Keck_LRIS', 'R1200_9000', 'MasterWaveCalib_A_1_01.json') # Dev suite 2x1 build_template([wfile1, wfile2], slits, lcut, binspec, outroot, lowredux=False, ifiles=ifiles) if flg & (2**12): # R600/5000 # slits = [1-4] # 5080 -- 7820 # slits = [1-7] # 7820 -- 9170 binspec = 2 outroot = 'keck_lris_red_600_5000.fits' slits = [4, 7] lcut = [7820.] wfile = os.path.join(template_path, 'Keck_LRIS', 'R600_5000', 'MasterWaveCalib_B_1_01.json') build_template(wfile, slits, lcut, binspec, outroot, lowredux=False) if flg & (2**27): # R600/7500 # slits = [1-10] # 5000 -- 7840 # slits = [1-4] # 7840 -- 9230 binspec = 2 outroot = 'keck_lris_red_600_7500.fits' slits = [10, 4] lcut = [7840.] wfile = os.path.join(template_path, 'Keck_LRIS', 'R600_7500', 'MasterWaveCalib_I_1_01.json') build_template(wfile, slits, lcut, binspec, outroot, lowredux=False, chk=True, normalize=True, subtract_conti=True) # ################################## # Magellan/MagE if flg & (2**13): # Load mase_path = os.path.join(os.getenv('XIDL_DIR'), 'Magellan', 'MAGE', 'mase', 'Calib') sav_file = os.path.join(mase_path, 'MagE_wvguess_jfh.idl') mase_dict = readsav(sav_file) mase_sol = Table(mase_dict['all_arcfit']) # Do it all_wave = np.zeros((2048, 15)) all_flux = np.zeros_like(all_wave) for order in np.arange(15): all_flux[:, order] = mase_dict['sv_aspec'][order] # Build the wavelengths wv_air = cheby_val(mase_sol['FFIT'][order], np.arange(2048), mase_sol['NRM'][order], mase_sol['NORD'][order]) all_wave[:, order] = airtovac(wv_air * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = np.arange(20, 5, -1, dtype=int) tbl.meta['BINSPEC'] = 1 # Write outroot = 'magellan_mage.fits' outfile = os.path.join(template_path, outroot) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**14): # Magellan/MagE Plots outpath = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'plots') new_mage_file = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv', 'magellan_mage.fits') # Load mage_wave = Table.read(new_mage_file) llist = waveio.load_line_lists(['ThAr_MagE']) # for kk in range(mage_wave['wave'].shape[1]): wv = mage_wave['wave'][:, kk] fx = mage_wave['flux'][:, kk] order = 20 - kk # Reidentify detections, spec_cont_sub, patt_dict = autoid.reidentify( fx, fx, wv, llist, 1) # Fit final_fit = wv_fitting.fit_slit(fx, patt_dict, detections, llist) # Output outfile = os.path.join(outpath, 'MagE_order{:2d}_IDs.pdf'.format(order)) autoid.arc_fit_qa(final_fit, outfile=outfile, ids_only=True) print("Wrote: {}".format(outfile)) autoid.arc_fit_qa(final_fit, outfile=os.path.join( outpath, 'MagE_order{:2d}_full.pdf'.format(order))) if flg & (2**15): # VLT/X-Shooter reid_arxiv # VIS reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') for iroot, iout in zip( ['vlt_xshooter_vis1x1.json', 'vlt_xshooter_nir.json'], ['vlt_xshooter_vis1x1.fits', 'vlt_xshooter_nir.fits']): # Load old_file = os.path.join(reid_path, iroot) odict, par = waveio.load_reid_arxiv(old_file) # Do it orders = odict['fit2d']['orders'][::-1].astype(int) # Flipped all_wave = np.zeros((odict['0']['nspec'], orders.size)) all_flux = np.zeros_like(all_wave) for kk, order in enumerate(orders): all_flux[:, kk] = odict[str(kk)]['spec'] if 'nir' in iroot: all_wave[:, kk] = odict[str(kk)]['wave_soln'] else: all_wave[:, kk] = airtovac(odict[str(kk)]['wave_soln'] * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**16): # VLT/X-Shooter line list line_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'lists') old_file = os.path.join(line_path, 'ThAr_XSHOOTER_VIS_air_lines.dat') # Load air_list = waveio.load_line_list(old_file) # Vacuum vac_wv = airtovac(air_list['wave'] * units.AA).value vac_list = air_list.copy() vac_list['wave'] = vac_wv # Write new_file = os.path.join(line_path, 'ThAr_XSHOOTER_VIS_lines.dat') vac_list.write(new_file, format='ascii.fixed_width', overwrite=True) print("Wrote: {}".format(new_file)) if flg & (2**17): # NIRES reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = 'keck_nires.json' iout = 'keck_nires.fits' # Load old_file = os.path.join(reid_path, iroot) odict, par = waveio.load_reid_arxiv(old_file) # Do it orders = odict['fit2d']['orders'][::-1].astype(int) # Flipped all_wave = np.zeros((odict['0']['nspec'], orders.size)) all_flux = np.zeros_like(all_wave) for kk, order in enumerate(orders): all_flux[:, kk] = odict[str(kk)]['spec'] if 'nir' in iroot: all_wave[:, kk] = odict[str(kk)]['wave_soln'] else: all_wave[:, kk] = airtovac(odict[str(kk)]['wave_soln'] * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**18): # Gemini/GNIRS reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = 'gemini_gnirs.json' iout = 'gemini_gnirs.fits' # Load old_file = os.path.join(reid_path, iroot) odict, par = waveio.load_reid_arxiv(old_file) # Do it orders = odict['fit2d']['orders'][::-1].astype(int) # Flipped all_wave = np.zeros((odict['0']['nspec'], orders.size)) all_flux = np.zeros_like(all_wave) for kk, order in enumerate(orders): all_flux[:, kk] = odict[str(kk)]['spec'] if 'nir' in iroot: all_wave[:, kk] = odict[str(kk)]['wave_soln'] else: all_wave[:, kk] = airtovac(odict[str(kk)]['wave_soln'] * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**23): # WHT/ISIS iroot = 'wht_isis_blue_1200_4800.json' outroot = 'wht_isis_blue_1200_4800.fits' wfile = os.path.join(template_path, 'WHT_ISIS', '1200B', iroot) binspec = 2 slits = [0] lcut = [3200.] build_template(wfile, slits, lcut, binspec, outroot, lowredux=False) if flg & (2**24): # Magellan/FIRE reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = 'magellan_fire_echelle.json' iout = 'magellan_fire_echelle.fits' # Load old_file = os.path.join(reid_path, iroot) odict, par = waveio.load_reid_arxiv(old_file) # Do it orders = odict['fit2d']['orders'][::-1].astype(int) # Flipped all_wave = np.zeros((odict['0']['nspec'], orders.size)) all_flux = np.zeros_like(all_wave) for kk, order in enumerate(orders): all_flux[:, kk] = odict[str(kk)]['spec'] if 'nir' in iroot: all_wave[:, kk] = odict[str(kk)]['wave_soln'] else: all_wave[:, kk] = airtovac(odict[str(kk)]['wave_soln'] * units.AA).value # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile)) if flg & (2**25): # FIRE longslit binspec = 1 reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') outroot = 'magellan_fire_long.fits' xidl_file = os.path.join(os.getenv('FIRE_DIR'), 'LowDispersion', 'NeNeAr_archive_fit.fits') spec_file = os.path.join(os.getenv('FIRE_DIR'), 'LowDispersion', 'NeNeAr2.sav') fire_sol = Table.read(xidl_file) wave = cheby_val(fire_sol['FFIT'].data[0], np.arange(2048), fire_sol['NRM'].data[0], fire_sol['NORD'].data[0]) wv_vac = airtovac(wave * units.AA) xidl_dict = readsav(spec_file) flux = xidl_dict['arc1d'] wvutils.write_template(wv_vac.value, flux, binspec, reid_path, outroot, det_cut=None) # Gemini/Flamingos2 if flg & (2**26): reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = ['Flamingos2_JH_JH.json', 'Flamingos2_HK_HK.json'] outroot = ['Flamingos2_JH_JH.fits', 'Flamingos2_HK_HK.fits'] binspec = 1 slits = [0] lcut = [] for ii in range(len(iroot)): wfile = os.path.join(reid_path, iroot[ii]) build_template(wfile, slits, lcut, binspec, outroot[ii], lowredux=False) # MDM/OSMOS -- MDM4K if flg & (2**28): # ArI 4159 -- 6800 wfile = os.path.join(template_path, 'MDM_OSMOS', 'MasterWaveCalib_MDM4K_01.json') outroot = 'mdm_osmos_mdm4k.fits' binspec = 1 slits = [0] lcut = [3200.] build_template(wfile, slits, lcut, binspec, outroot, lowredux=False, chk=True, subtract_conti=True) # Keck KCWI if flg & (2**29): # FeAr BH2 wfile1 = os.path.join(template_path, 'KCWI', 'BH2', 'Keck_KCWI_BH2_4200.json') outroot = 'keck_kcwi_BH2_4200.fits' binspec = 1 slits = [1015] lcut = [4350.0, 8000.0] build_template([wfile1], slits, lcut, binspec, outroot, lowredux=False, normalize=True) # FeAr BM wfile1 = os.path.join(template_path, 'KCWI', 'BM', 'Keck_KCWI_BM_4060.json') wfile2 = os.path.join(template_path, 'KCWI', 'BM', 'Keck_KCWI_BM_4670.json') outroot = 'keck_kcwi_BM.fits' binspec = 1 slits = [1026, 1021] lcut = [4350.0, 8000.0] build_template([wfile1, wfile2], slits, lcut, binspec, outroot, lowredux=False, normalize=True) # P200 DBSP r if flg & (2**30): # HeNeAr wfile = os.path.join(template_path, 'P200_DBSP', 'R316_7500_D55', 'P200_DBSP_Red.json') outroot = 'p200_dbsp_red_316_7500_d55.fits' binspec = 1 slits = [221] lcut = None # only matters if >1 slit build_template([wfile], slits, lcut, binspec, outroot, lowredux=False, normalize=True) # P200 DBSP b if flg & (2**31): # FeAr wfile = os.path.join(template_path, 'P200_DBSP', 'B600_4000_D55', 'P200_DBSP_Blue.json') outroot = 'p200_dbsp_blue_600_4000_d55.fits' binspec = 1 slits = [231] lcut = None build_template([wfile], slits, lcut, binspec, outroot, lowredux=False, normalize=True) # MMT/MMIRS if flg & (2**32): reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = [ 'mmt_mmirs_HK_zJ.json', 'mmt_mmirs_J_zJ.json', 'mmt_mmirs_K3000_Kspec.json' ] outroot = [ 'mmt_mmirs_HK_zJ.fits', 'mmt_mmirs_J_zJ.fits', 'mmt_mmirs_K3000_Kspec.fits' ] binspec = 1 slits = [1020, 1020, 1020] lcut = [] for ii in range(len(iroot)): wfile = os.path.join(reid_path, iroot[ii]) build_template(wfile, slits, lcut, binspec, outroot[ii], lowredux=False) # LBT/MODS if flg & (2**33): reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = ['lbt_mods1r_red.json', 'lbt_mods2r_red.json'] outroot = ['lbt_mods1r_red.fits', 'lbt_mods2r_red.fits'] binspec = 1 slits = [[1557], [1573]] lcut = [] for ii in range(len(iroot)): wfile = os.path.join(reid_path, iroot[ii]) build_template(wfile, slits[ii], lcut, binspec, outroot[ii], lowredux=False) # P200 Triplespec if flg & (2**34): reid_path = os.path.join(resource_filename('pypeit', 'data'), 'arc_lines', 'reid_arxiv') iroot = 'p200_triplespec_MasterWaveCalib.fits' iout = 'p200_triplespec.fits' # Load old_file = os.path.join(reid_path, iroot) par = io.fits_open(old_file) pyp_spec = par[0].header['PYP_SPEC'] spectrograph = load_spectrograph(pyp_spec) orders = spectrograph.orders # Do it all_wave = np.zeros((par[2].data['spec'].size, orders.size)) all_flux = np.zeros_like(all_wave) for kk, order in enumerate(orders): all_flux[:, kk] = par[2 * kk + 2].data['spec'] all_wave[:, kk] = par[2 * kk + 2].data['wave_soln'] # Write tbl = Table() tbl['wave'] = all_wave.T tbl['flux'] = all_flux.T tbl['order'] = orders tbl.meta['BINSPEC'] = 1 # Write outfile = os.path.join(reid_path, iout) tbl.write(outfile, overwrite=True) print("Wrote: {}".format(outfile))