def test_gen_sensfunc(): kastb = load_spectrograph('shane_kast_blue') # Load a random spectrum for the sensitivity function sfile = data_path('spec1d_r153-J0025-0312_KASTr_2015Jan23T025323.850.fits') specobjs = load.load_specobjs(sfile) # telescope = telescopes.ShaneTelescopePar() fitstbl = dummy_fitstbl() RA = '05:06:36.6' DEC = '52:52:01.0' # Get the sensitivity function sens_dict = flux.generate_sensfunc(specobjs[0][0].boxcar['WAVE'], specobjs[0][0].boxcar['COUNTS'], specobjs[0][0].boxcar['COUNTS_IVAR'], fitstbl['airmass'][4], fitstbl['exptime'][4], kastb.telescope['longitude'], kastb.telescope['latitude'], ra=RA, dec=DEC) # Test assert isinstance(sens_dict, dict) assert isinstance(sens_dict['wave_min'], units.Quantity)
def ech_generate_sensfunc(stdframe,spectrograph=None, telluric=True, star_type=None, star_mag=None, ra=None, dec=None, std_file = None, BALM_MASK_WID=5., nresln=None,debug=False): if spectrograph is None: std_specobjs, std_header = ech_load_specobj(stdframe, order=0) spectrograph = std_header['INSTRUME'] msgs.info('You are working on {:s}'.format(spectrograph)) ext_final = fits.getheader(stdframe, -1) norder = 5 #norder = ext_final['ORDER'] + 1 sens_dicts = {} for iord in range(norder): std_specobjs, std_header = ech_load_specobj(stdframe, order=iord) std_idx = flux.find_standard(std_specobjs) std = std_specobjs[std_idx] wavemask = std.boxcar['WAVE']>1000.0*units.AA wave,counts,ivar = std.boxcar['WAVE'][wavemask],std.boxcar['COUNTS'][wavemask],std.boxcar['COUNTS_IVAR'][wavemask] sens_dict = flux.generate_sensfunc(wave,counts,ivar,std_header['AIRMASS'],std_header['EXPTIME'], spectrograph,star_type=star_type,star_mag=star_mag, telluric=telluric,ra=ra,dec=dec,BALM_MASK_WID=BALM_MASK_WID, nresln=nresln,std_file=std_file,debug=debug) sens_dict['ech_orderindx'] = iord sens_dicts[str(iord)] = sens_dict sens_dicts['norder'] = norder return sens_dicts
def generate_sensfunc(self): """ Generate the senstivity function Wrapper to flux.generate_sensfunc Requires self.std has been set Returns ------- self.sensfunc : dict """ # Check internals if self.std is None: msgs.warn('First identify the star first (with find_standard).') return None if self.std_header is None: msgs.warn( 'First set std_header with a dict-like object holding RA, DEC, ' 'AIRMASS, EXPTIME.') return None self.sens_dict = {} try: this_wave = self.std.optimal['WAVE_GRID'] except KeyError: this_wave = self.std.optimal['WAVE'] sens_dict_long = flux.generate_sensfunc( this_wave, self.std.optimal['COUNTS'], self.std.optimal['COUNTS_IVAR'], self.std_header['AIRMASS'], self.std_header['EXPTIME'], self.spectrograph.telescope['longitude'], self.spectrograph.telescope['latitude'], BALM_MASK_WID=self.par['balm_mask_wid'], telluric=self.telluric, ra=self.std_ra, dec=self.std_dec, std_file=self.std_file, debug=self.debug) self.sens_dict['0'] = sens_dict_long self.sens_dict['nslits'] = 1 # Step self.steps.append(inspect.stack()[0][3]) # Return return self.sens_dict
def ech_generate_sensfunc(stdframe, spectrograph=None, telluric=True, star_type=None, star_mag=None, ra=None, dec=None, std_file=None, BALM_MASK_WID=5., nresln=None, debug=False): if spectrograph is None: std_specobjs, std_header = ech_load_specobj(stdframe, order=0) spectrograph = std_header['INSTRUME'] msgs.info('You are working on {:s}'.format(spectrograph)) ext_final = fits.getheader(stdframe, -1) norder = 5 #norder = ext_final['ORDER'] + 1 sens_dicts = {} for iord in range(norder): std_specobjs, std_header = ech_load_specobj(stdframe, order=iord) std_idx = flux.find_standard(std_specobjs) std = std_specobjs[std_idx] wavemask = std.boxcar['WAVE'] > 1000.0 * units.AA wave, counts, ivar = std.boxcar['WAVE'][wavemask], std.boxcar[ 'COUNTS'][wavemask], std.boxcar['COUNTS_IVAR'][wavemask] sens_dict = flux.generate_sensfunc(wave, counts, ivar, std_header['AIRMASS'], std_header['EXPTIME'], spectrograph, star_type=star_type, star_mag=star_mag, telluric=telluric, ra=ra, dec=dec, BALM_MASK_WID=BALM_MASK_WID, nresln=nresln, std_file=std_file, debug=debug) sens_dict['ech_orderindx'] = iord sens_dicts[str(iord)] = sens_dict sens_dicts['norder'] = norder return sens_dicts
def generate_sensfunc(self): """ Generate the senstivity function Wrapper to flux.generate_sensfunc Requires self.std has been set Returns ------- self.sensfunc : dict """ # Check internals # if self.std is None: # msgs.warn('First identify the star first (with find_standard).') # return None if self.std_header is None: msgs.warn('First set std_header with a dict-like object holding RA, DEC, ' 'AIRMASS, EXPTIME.') return None ext_final = fits.getheader(self.std_spec1d_file, -1) norder = ext_final['ORDER'] + 1 self.sens_dict = {} for iord in range(norder): std_specobjs, std_header = load.ech_load_specobj(self.std_spec1d_file, order=iord) std_idx = flux.find_standard(std_specobjs) std = std_specobjs[std_idx] wavemask = std.boxcar['WAVE'] > 1000.0 * units.AA wave, counts, ivar = std.boxcar['WAVE'][wavemask], std.boxcar['COUNTS'][wavemask], \ std.boxcar['COUNTS_IVAR'][wavemask] sens_dict_iord = flux.generate_sensfunc(wave, counts, ivar, std_header['AIRMASS'], std_header['EXPTIME'], self.spectrograph, star_type=self.star_type, star_mag=self.star_mag, telluric=self.telluric, ra=self.std_ra, dec=self.std_dec, BALM_MASK_WID=self.BALM_MASK_WID, nresln=self.nresln, std_file=self.std_file, debug=self.debug) sens_dict_iord['ech_orderindx'] = iord self.sens_dict[str(iord)] = sens_dict_iord self.sens_dict['norder'] = norder # Step self.steps.append(inspect.stack()[0][3]) # Return return self.sens_dict
def generate_sensfunc(self): """ Generate the senstivity function Wrapper to flux.generate_sensfunc Requires self.std has been set Returns ------- self.sensfunc : dict """ # Check internals if self.std is None: msgs.warn('First identify the star first (with find_standard).') return None if self.std_header is None: msgs.warn( 'First set std_header with a dict-like object holding RA, DEC, ' 'AIRMASS, EXPTIME.') return None ext_final = fits.getheader(self.par['std_file'], -1) norder = ext_final['ECHORDER'] + 1 self.sens_dict = {} for iord in range(norder): std_specobjs, std_header = load.load_specobjs(self.par['std_file'], order=iord) std_idx = flux.find_standard(std_specobjs) std = std_specobjs[std_idx] try: wavemask = std.optimal['WAVE_GRID'] > 0.0 #*units.AA except KeyError: wavemask = std.optimal['WAVE'] > 1000.0 * units.AA this_wave = std.optimal['WAVE'][wavemask] else: this_wave = std.optimal['WAVE_GRID'][wavemask] counts, ivar = std.optimal['COUNTS'][wavemask], std.optimal[ 'COUNTS_IVAR'][wavemask] sens_dict_iord = flux.generate_sensfunc( this_wave, counts, ivar, float(self.std_header['AIRMASS']), self.std_header['EXPTIME'], self.spectrograph.telescope['longitude'], self.spectrograph.telescope['latitude'], star_type=self.star_type, star_mag=self.star_mag, telluric=self.telluric, ra=self.std_ra, dec=self.std_dec, resolution=self.resolution, BALM_MASK_WID=self.BALM_MASK_WID, std_file=self.std_file, poly_norder=self.poly_norder, polycorrect=self.polycorrect, debug=self.debug) sens_dict_iord['ech_orderindx'] = iord self.sens_dict[str(iord)] = sens_dict_iord ## add some keys to be saved into primary header in masterframe for key in [ 'wave_max', 'exptime', 'airmass', 'std_file', 'std_ra', 'std_dec', 'std_name', 'cal_file' ]: try: self.sens_dict[key] = sens_dict_iord[key] except: pass self.sens_dict['meta'] = {} self.sens_dict['meta']['nslits'] = norder self.sens_dict['wave_min'] = self.sens_dict['0']['wave_min'] # Step self.steps.append(inspect.stack()[0][3]) # Return return self.sens_dict