def build_template(in_files, slits, wv_cuts, binspec, outroot, lowredux=True, ifiles=None, det_cut=None, chk=False): """ Generate a full_template for a given instrument Args: in_files: slits: wv_cuts: binspec: outroot: lowredux: ifiles: det_cut: chk: Returns: """ # Load xidl file # Grab it # Load and splice yvals = [] lvals = [] if not isinstance(in_files,list): in_files = [in_files] ifiles = [0]*len(slits) for kk, slit in enumerate(slits): in_file = in_files[ifiles[kk]] if lowredux: wv_vac, spec = xidl_arcspec(in_file, slit) else: wv_vac, spec = pypeit_arcspec(in_file, slit) # Cut if len(slits) > 1: if kk == 0: llow = 0. lhi = wv_cuts[0] elif kk == len(slits)-1: llow = wv_cuts[kk-1] lhi = 1e9 else: llow = wv_cuts[kk-1] lhi = wv_cuts[kk] # gdi = (wv_vac > llow) & (wv_vac < lhi) else: gdi = np.arange(spec.size).astype(int) # Append yvals.append(spec[gdi]) lvals.append(wv_vac[gdi]) # Concatenate nwspec = np.concatenate(yvals) nwwv = np.concatenate(lvals) # Check if chk: debugger.plot1d(nwwv, nwspec) # Generate the table write_template(nwwv, nwspec, binspec, outpath, outroot, det_cut=det_cut)
def show_sensfunc(self): """ Plot the sensitivity function """ if self.sens_dict is None: msgs.warn("You need to generate the sens_dict first!") return None # Generate from model #wave = np.linspace(self.sens_dict['wave_min'], self.sens_dict['wave_max'], 1000) #mag_func = utils.func_val(self.sens_dict['c'], wave, self.sens_dict['func']) #sens = 10.0**(0.4*mag_func) # Plot debugger.plot1d(self.sens_dict['wave'], self.sens_dict['sensfunc'], xlbl='Wavelength', ylbl='Sensitivity Function')
def show_sensfunc(self): """ Plot the sensitivity function """ if self.sens_dict is None: msgs.warn("You need to generate the sens_dict first!") return None # Generate from model #wave = np.linspace(self.sens_dict['wave_min'], self.sens_dict['wave_max'], 1000) #mag_func = utils.func_val(self.sens_dict['c'], wave, self.sens_dict['func']) #sens = 10.0**(0.4*mag_func) # Plot if self.spectrograph.pypeline == 'Echelle': for iord in range(len(self.std)): sord = str(iord) debugger.plot1d(self.sens_dict[sord]['wave'], self.sens_dict[sord]['sensfunc'], xlbl='Wavelength', ylbl='Sensitivity Function') else: debugger.plot1d(self.sens_dict['0']['wave'], self.sens_dict['0']['sensfunc'], xlbl='Wavelength', ylbl='Sensitivity Function')
def build_template(in_files, slits, wv_cuts, binspec, outroot, outdir=None, normalize=False, subtract_conti=False, wvspec=None, lowredux=True, ifiles=None, det_cut=None, chk=False, miny=None, overwrite=True): """ Generate a full_template for a given instrument Args: in_files (list or str): Wavelength solution files, XIDL or PypeIt slits (list): Slits in the archive files to use wv_cuts (list): Wavelengths to cut each slit at binspec (int): Spectral binning of the archived spectrum outroot (str): Name of output archive outdir (str): Name of output directory lowredux (bool, optional): If true, in_files are from LowRedux wvspec (ndarray, optional): Manually input the wavelength values ifiles (list, optional): Ordering of the in_files. Default is np.arange(len(in_files)) det_cut (dict, optional): Cut the detector into pieces. Important for long detectors with wavelengths on one side chk (bool, optional): Show a plot or two miny (float): Impose a minimum value normalize (bool, optional): If provided multiple in_files, normalize each snippet to have the same maximum amplitude. subtract_conti (bool, optional): Subtract the continuum for the final archive """ if outdir is None: outdir = outpath # Load xidl file # Grab it # Load and splice yvals = [] lvals = [] if not isinstance(in_files,list): in_files = [in_files] ifiles = [0]*len(slits) for kk, slit in enumerate(slits): if wvspec is None: in_file = in_files[ifiles[kk]] if lowredux: wv_vac, spec = xidl_arcspec(in_file, slit) else: wv_vac, spec = pypeit_arcspec(in_file, slit) else: wv_vac, spec = wvspec['wv_vac'], wvspec['spec'] # Cut if len(slits) > 1: if kk == 0: llow = 0. lhi = wv_cuts[0] elif kk == len(slits)-1: llow = wv_cuts[kk-1] lhi = 1e9 else: llow = wv_cuts[kk-1] lhi = wv_cuts[kk] # gdi = (wv_vac > llow) & (wv_vac < lhi) else: gdi = np.arange(spec.size).astype(int) # Append yvals.append(spec[gdi]) lvals.append(wv_vac[gdi]) # Continuum if subtract_conti: for kk,spec in enumerate(yvals): _, _, _, _, spec_cont_sub = wvutils.arc_lines_from_spec(spec) yvals[kk] = spec_cont_sub # Normalize? if normalize: norm_val = 10000. # Max values maxs = [] for kk,spec in enumerate(yvals): mx = np.max(spec) spec = spec * norm_val / mx yvals[kk] = spec # Concatenate nwspec = np.concatenate(yvals) nwwv = np.concatenate(lvals) # Min y? if miny is not None: nwspec = np.maximum(nwspec, miny) # Check if chk: debugger.plot1d(nwwv, nwspec) embed(header='123') # Generate the table write_template(nwwv, nwspec, binspec, outdir, outroot, det_cut=det_cut, overwrite=overwrite)