def get_sens_from_file(std1dfile=None, instrument='GNIRS', star_type=None, star_mag=None, star_ra=None, star_dec=None, sens_polyorder=8, mask_abs_lines=True, disp=True, show=True, debug=False): # sensfunction output file name if '.sens.fits' in std1dfile: sensfile = std1dfile else: sensfile = std1dfile.replace('.fits', '.sens.fits') # get the pca pickle file and atmosphere model grid pca_file = os.path.join(basedir, 'Dropbox/PypeIt_Redux/qso_pca_1200_3100.pckl') if (instrument == 'GNIRS') or (instrument == 'NIRES') or (instrument == 'MOSFIRE'): telgridfile = os.path.join( basedir, 'Dropbox/PypeIt_Redux/TelFit_MaunaKea_3100_26100_R20000.fits') elif (instrument == 'XSHOOTER_VIS') or (instrument == 'GMOS-S'): telgridfile = os.path.join( basedir, 'Dropbox/PypeIt_Redux/XSHOOTER/TelFit_Paranal_VIS_4900_11100_R25000.fits' ) elif instrument == 'XSHOOTER_NIR': telgridfile = os.path.join( basedir, 'Dropbox/PypeIt_Redux/XSHOOTER/TelFit_Paranal_NIR_9800_25000_R25000.fits' ) else: telgridfile = os.path.join( basedir, 'Dropbox/PypeIt_Redux/TelFit_MaunaKea_3100_26100_R20000.fits') msgs.warn('No telluric grid is found. Using MaunaKea!') msgs.info('Using {:}'.format(telgridfile)) # run telluric.sensfunc_telluric to get the sensfile TelSens = telluric.sensfunc_telluric(std1dfile, telgridfile, sensfile, star_type=star_type, star_mag=star_mag, star_ra=star_ra, star_dec=star_dec, mask_abs_lines=mask_abs_lines, polyorder=sens_polyorder, disp=show, debug=debug) return sensfile, telgridfile
def compute_sensfunc(self): """ Calls routine to compute the sensitivity function. Returns ------- meta_table: astropy table Table containing sensfunc meta data out_table: astropy table Table containing sensfunc information. """ meta_table, out_table = telluric.sensfunc_telluric( self.wave, self.counts, self.counts_ivar, self.counts_mask, self.meta_spec['EXPTIME'], self.meta_spec['AIRMASS'], self.std_dict, self.par['IR']['telgridfile'], polyorder=self.par['polyorder'], ech_orders=self.meta_spec['ECH_ORDERS'], sn_clip=self.par['IR']['sn_clip'], mask_abs_lines=self.par['mask_abs_lines'], # JFH Implement thease in parset? #delta_coeff_bounds=self.par['IR']['delta_coeff_bounds'], #minmax_coeff_bounds=self.par['IR']['min_max_coeff_bounds'], tol=self.par['IR']['tol'], popsize=self.par['IR']['popsize'], recombination=self.par['IR']['recombination'], polish=self.par['IR']['polish'], disp=self.par['IR']['disp'], debug=self.debug) # Add the algorithm to the meta_table meta_table['ALGORITHM'] = self.par['algorithm'] self.steps.append(inspect.stack()[0][3]) return meta_table, out_table
'Dropbox/PypeIt_Redux/qso_pca_1200_3100.pckl') telgridfile = os.path.join( os.getenv('HOME'), 'Dropbox/PypeIt_Redux/TelFit_MaunaKea_3100_26100_R20000.fits') # TODO: set sensfile=None if you want to derive sensfunc from std1dfile sensfile = os.path.join( os.getenv('HOME'), 'Dropbox/PypeIt_Redux/NIRES/GD153_sens_tell_nires.fits') if do_sens: if std1dfile is None: msgs.error('You need either give a std1dfile to derive sensfunc') else: # run telluric.sensfunc_telluric to get the sensfile TelSens = telluric.sensfunc_telluric(std1dfile, telgridfile, sensfile, mask_abs_lines=True, debug=debug) ## Apply the sensfunc to all spectra (only sensfunc but not tellluric) # TODO: change show=False to show=show apply_sensfunc(fnames, sensfile, extinct_correct=False, tell_correct=False, debug=debug, show=show) fnames_flux = [f.replace('.fits', '_flux.fits') for f in fnames] ## Let's coadd all the fluxed spectra
dev_suite_path, 'spec1d_cN20170331S0206-HIP62745_GNIRS_2017Mar31T083351.681.fits') #According to Simbad HIP62745 is an A0 star with V=8.86 star_type = 'A0' Vmag = 8.86 sensfile = os.path.join(mpia_path, 'HIP62745_sens_tell_gnirs.fits') # telgridfile is a large grid of atmosphere models telgridfile = os.path.join(mpia_path, 'TelFit_MaunaKea_3100_26100_R20000.fits') # TODO: set sensfile=None if you want to derive sensfunc from std1dfile if not os.path.exists(sensfile) or clobber: # Run sensfun_teluric to get the sensitivity function TelSens = telluric.sensfunc_telluric(std1dfile, telgridfile, sensfile, star_type=star_type, star_mag=Vmag, mask_abs_lines=True, debug=True) ## Apply the sensfunc to all spectra. This is flux calibration only, but not telluric correction. spec1dfiles_flux = [f.replace('.fits', '_flux.fits') for f in spec1dfiles] if not os.path.exists(spec1dfiles_flux[0]): apply_sensfunc(spec1dfiles, sensfile, extinct_correct=False, tell_correct=False, debug=False, show=False) # Now let's coadd the spectrum
def compute_zeropoint(self): """ Calls routine to compute the sensitivity function. Returns ------- TelObj : :class:`~pypeit.core.telluric.Telluric` Best-fitting telluric model """ self.telluric = telluric.sensfunc_telluric( self.wave_cnts, self.counts, self.counts_ivar, self.counts_mask, self.meta_spec['EXPTIME'], self.meta_spec['AIRMASS'], self.std_dict, self.par['IR']['telgridfile'], polyorder=self.par['polyorder'], ech_orders=self.meta_spec['ECH_ORDERS'], resln_guess=self.par['IR']['resln_guess'], resln_frac_bounds=self.par['IR']['resln_frac_bounds'], sn_clip=self.par['IR']['sn_clip'], mask_abs_lines=self.par['mask_abs_lines'], maxiter=self.par['IR']['maxiter'], lower=self.par['IR']['lower'], upper=self.par['IR']['upper'], delta_coeff_bounds=self.par['IR']['delta_coeff_bounds'], minmax_coeff_bounds=self.par['IR']['minmax_coeff_bounds'], tol=self.par['IR']['tol'], popsize=self.par['IR']['popsize'], recombination=self.par['IR']['recombination'], polish=self.par['IR']['polish'], disp=self.par['IR']['disp'], debug=self.debug, debug_init=self.debug) # Copy the relevant metadata self.std_name = self.telluric.std_name self.std_cal = self.telluric.std_cal self.std_ra = self.telluric.std_ra self.std_dec = self.telluric.std_dec self.airmass = self.telluric.airmass self.exptime = self.telluric.exptime # Instantiate the main output data table self.sens = self.empty_sensfunc_table( self.telluric.norders, self.telluric.wave_grid.size, ncoeff=self.telluric.max_ntheta_obj) # For stupid reasons related to how astropy tables will let me store # this data I have to redundantly write out the wavelength grid for each # order. In actuality a variable length wavelength grid is needed which # is a subset of the original fixed grid, but there is no way to write # this to disk. Perhaps the better solution would be a list of of # astropy tables, one for each order, that would save some space, since # we could then write out only the subset used to the table column. I'm # going with this inefficient approach for now, since eventually we will # want to create a data container for these outputs. That said, coming # up with that standarized model is a bit tedious given the somewhat # heterogenous outputs of the two different fluxing algorithms. # Extract and construct the relevant data using the telluric model self.sens['SENS_COEFF'] = self.telluric.model['OBJ_THETA'] self.sens['WAVE_MIN'] = self.telluric.model['WAVE_MIN'] self.sens['WAVE_MAX'] = self.telluric.model['WAVE_MAX'] self.sens['ECH_ORDERS'] = self.telluric.model['ECH_ORDERS'] s = self.telluric.model['IND_LOWER'] e = self.telluric.model['IND_UPPER'] + 1 self.sens['POLYORDER_VEC'] = self.telluric.model['POLYORDER_VEC'] for i in range(self.norderdet): # Compute and assign the zeropint_data from the input data and the # best-fit telluric model self.sens['SENS_WAVE'][ i, s[i]:e[i]] = self.telluric.wave_grid[s[i]:e[i]] self.sens['SENS_ZEROPOINT_GPM'][ i, s[i]:e[i]] = self.telluric.mask_arr[s[i]:e[i], i] self.sens['SENS_COUNTS_PER_ANG'][ i, s[i]:e[i]] = self.telluric.flux_arr[s[i]:e[i], i] N_lam = self.sens['SENS_COUNTS_PER_ANG'][i, s[i]:e[i]] / self.exptime self.sens['SENS_ZEROPOINT'][i,s[i]:e[i]] \ = flux_calib.compute_zeropoint(self.sens['SENS_WAVE'][i,s[i]:e[i]], N_lam, self.sens['SENS_ZEROPOINT_GPM'][i,s[i]:e[i]], self.telluric.obj_dict_list[i]['flam_true'], tellmodel=self.telluric.tellmodel_list[i])[0] # TODO: func is always 'legendre' because that is what's set by # sensfunc_telluric self.sens['SENS_ZEROPOINT_FIT'][i,s[i]:e[i]] \ = fitting.evaluate_fit(self.sens['SENS_COEFF'][ i,:self.sens['POLYORDER_VEC'][i]+2], self.telluric.func, self.sens['SENS_WAVE'][i,s[i]:e[i]], minx=self.sens['WAVE_MIN'][i], maxx=self.sens['WAVE_MAX'][i]) self.sens['SENS_ZEROPOINT_FIT_GPM'][ i, s[i]:e[i]] = self.telluric.outmask_list[i]