def volume(L,Lval,volbins): ''' Function linearly interpolating between volume bins to get a volume value ''' if L < np.min(Lval): vol = 0.0 elif L > np.max(Lval): sys.exit(':: ERROR :: Input Volume L in volume function is larger than max(Lvector) --> ABORTING') else: newL = np.sort(np.append(Lval,L)) newV = kbs.interpn(Lval,volbins,newL) ent = np.where(newL == L) vol = newV[ent] return vol
def spectrans(waveval, wavevec, specvec, transvec): """ Retunring the (interpolated) value of the spectrum for a given wavelength """ STvec = specvec * transvec ent = np.where(wavevec == waveval) if len(ent[0]) == 1: STval = STvec[ent] else: wavenew = np.sort(np.append(wavevec, waveval)) STvecnew = kbs.interpn(wavevec, STvec, wavenew) ent = np.where(wavenew == waveval) STval = STvecnew[ent] return STval
def spectrans(waveval,wavevec,specvec,transvec): """ Retunring the (interpolated) value of the spectrum for a given wavelength """ STvec = specvec*transvec ent = np.where(wavevec == waveval) if len(ent[0]) == 1 : STval = STvec[ent] else: wavenew = np.sort(np.append(wavevec,waveval)) STvecnew = kbs.interpn(wavevec,STvec,wavenew) ent = np.where(wavenew == waveval) STval = STvecnew[ent] return STval
def volume(L, Lval, volbins): ''' Function linearly interpolating between volume bins to get a volume value ''' if L < np.min(Lval): vol = 0.0 elif L > np.max(Lval): sys.exit( ':: ERROR :: Input Volume L in volume function is larger than max(Lvector) --> ABORTING' ) else: newL = np.sort(np.append(Lval, L)) newV = kbs.interpn(Lval, volbins, newL) ent = np.where(newL == L) vol = newV[ent] return vol
def kappa(waveval, site='maunakea', intmethod='linear', plot=0): """ ---- PURPOSE ---- Returning the (interpolated) value of the extinction coefficient needed to correct magnitudes for atmospheric extinction (air mass) ---- INPUT ---- wave wavelength in [A] site name of site (data) to use when interpolating intmethod the interpolation to perform ---- OUTPUT ---- kappa(lambda) The atmospheric instinction coefficient for lambda[A] ---- EXAMPLE OF USAGE ---- """ if site == 'maunakea': #data taken from http://www.gemini.edu/?q=node/10790#Mauna%20Kea wavedat = np.array([ 0.310, 0.320, 0.340, 0.360, 0.380, 0.400, 0.450, 0.500, 0.550, 0.600, 0.650, 0.700, 0.800, 0.900, 1.25, 1.65, 2.20 ]) * 1e4 kappadat = np.array([ 1.37, 0.82, 0.51, 0.37, 0.30, 0.25, 0.17, 0.13, 0.12, 0.11, 0.11, 0.10, 0.07, 0.05, 0.015, 0.015, 0.033 ]) else: sys.exit(':: kappa :: ERROR: Chosen site not available --> ABORTING') wavenew = np.sort(np.append(wavedat, waveval)) if waveval < np.min(wavedat): print 'NB! Selected wavelength is shorter than shortest wavelength in data. ' print ' Setting output to kappa of shortest wavelength in data.' kappa = kappadat[0] kappanew = np.insert(kappadat, 0, kappa) elif waveval > np.max(wavedat): print 'NB! Selected wavelength is longer than longest wavelength in data. ' print ' Setting output to kappa of longest wavelength in data.' kappa = kappadat[-1] kappanew = np.append(kappadat, kappa) else: kappanew = kbs.interpn(wavedat, kappadat, wavenew, method=intmethod) kappa = kappanew[np.where(wavenew == waveval)] if plot == 1: import pylab as plt plt.clf() plt.plot(wavedat, kappadat, 'ro', label='data for ' + site) plt.plot(wavenew, kappanew, 'r--', label='interpolation of data') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='cubic') #plt.plot(wavenew,kappanew,'g--',label='cubic') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='nearest') #plt.plot(wavenew,kappanew,'b--',label='nearest') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='slinear') #plt.plot(wavenew,kappanew,'y--',label='slinear') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='quadratic') #plt.plot(wavenew,kappanew,'m--',label='quadratic') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='zero') #plt.plot(wavenew,kappanew,'r:',label='zero') plt.plot(waveval, kappa, 'go', label='obtained value') plt.legend( fancybox=True, loc='upper right') # add the legend in the middle of the plot plt.show() return kappa
utcstart_sci = parameters[16] utcstop_sci = parameters[17] throughput = np.genfromtxt(tpfile) # reading througput into array #------------------------------------------------------------------------------------------------------------- # A: TELLURIC STAR #------------------------------------------------------------------------------------------------------------- # reading wavelengths, spectrum and ra dec from file wave_tel, spec1D_tel_eps, radec_tel = cal.readfitsspec1D(spec1D_tel, spec='SPEC1D_SUM') # get E(B-V) for ra and dec AV, extval_tel = kbs.getAv(radec_tel[0], radec_tel[1], 'F098M') # filter only important when using AV # interpolating throughput to telluric wavelengths tpinterp_tel = kbs.interpn(throughput[:, 0] * 10**4, throughput[:, 1], wave_tel) # loading expected initial 'template' spectrum of standard star (in flux units: [erg/s/cm2/A] standat = np.genfromtxt(spec1Dstandard) wave_stan = standat[:, 0] flux_stan = standat[:, 1] spec_stan_flux = kbs.interpn(wave_stan, flux_stan, wave_tel) # rescale 'template' spec to match telluric's magnitude magABstan = cal.magFromSpec(wave_tel, spec_stan_flux, tpinterp_tel) # magnitude of standard in band magABtel = magV_tel + magABstan # assuming telluric A0V (Vega) star => magABtel_band - magABtel_V = magABstan_band spec_stanscale = cal.scalespec( wave_tel, spec_stan_flux, tpinterp_tel, magABtel) # scaling standard spectrum to match telluric # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
spec1D_sci = parameters[14] nightdate_sci = parameters[15] utcstart_sci = parameters[16] utcstop_sci = parameters[17] throughput = np.genfromtxt(tpfile) # reading througput into array #------------------------------------------------------------------------------------------------------------- # A: TELLURIC STAR #------------------------------------------------------------------------------------------------------------- # reading wavelengths, spectrum and ra dec from file wave_tel, spec1D_tel_eps, radec_tel = cal.readfitsspec1D(spec1D_tel,spec='SPEC1D_SUM') # get E(B-V) for ra and dec AV, extval_tel = kbs.getAv(radec_tel[0],radec_tel[1],'F098M') # filter only important when using AV # interpolating throughput to telluric wavelengths tpinterp_tel = kbs.interpn(throughput[:,0]*10**4,throughput[:,1],wave_tel) # loading expected initial 'template' spectrum of standard star (in flux units: [erg/s/cm2/A] standat = np.genfromtxt(spec1Dstandard) wave_stan = standat[:,0] flux_stan = standat[:,1] spec_stan_flux = kbs.interpn(wave_stan,flux_stan,wave_tel) # rescale 'template' spec to match telluric's magnitude magABstan = cal.magFromSpec(wave_tel,spec_stan_flux,tpinterp_tel) # magnitude of standard in band magABtel = magV_tel+magABstan # assuming telluric A0V (Vega) star => magABtel_band - magABtel_V = magABstan_band spec_stanscale = cal.scalespec(wave_tel,spec_stan_flux,tpinterp_tel,magABtel) # scaling standard spectrum to match telluric # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # model spectrum of a telluric standard (i.e. manipulating standard) for testing telmodel = 0 modelstr = ' '
def kappa(waveval,site='maunakea',intmethod='linear',plot=0): """ ---- PURPOSE ---- Returning the (interpolated) value of the extinction coefficient needed to correct magnitudes for atmospheric extinction (air mass) ---- INPUT ---- wave wavelength in [A] site name of site (data) to use when interpolating intmethod the interpolation to perform ---- OUTPUT ---- kappa(lambda) The atmospheric instinction coefficient for lambda[A] ---- EXAMPLE OF USAGE ---- """ if site == 'maunakea': #data taken from http://www.gemini.edu/?q=node/10790#Mauna%20Kea wavedat = np.array([0.310,0.320,0.340,0.360,0.380,0.400,0.450,0.500,0.550,0.600,0.650,0.700,0.800,0.900,1.25,1.65,2.20])*1e4 kappadat = np.array([1.37,0.82,0.51,0.37,0.30,0.25,0.17,0.13,0.12,0.11,0.11,0.10,0.07,0.05,0.015,0.015,0.033]) else: sys.exit(':: kappa :: ERROR: Chosen site not available --> ABORTING') wavenew = np.sort(np.append(wavedat,waveval)) if waveval < np.min(wavedat): print 'NB! Selected wavelength is shorter than shortest wavelength in data. ' print ' Setting output to kappa of shortest wavelength in data.' kappa = kappadat[0] kappanew = np.insert(kappadat,0,kappa) elif waveval > np.max(wavedat): print 'NB! Selected wavelength is longer than longest wavelength in data. ' print ' Setting output to kappa of longest wavelength in data.' kappa = kappadat[-1] kappanew = np.append(kappadat,kappa) else: kappanew = kbs.interpn(wavedat,kappadat,wavenew,method=intmethod) kappa = kappanew[np.where(wavenew == waveval)] if plot == 1: import pylab as plt plt.clf() plt.plot(wavedat,kappadat,'ro',label='data for '+site) plt.plot(wavenew,kappanew,'r--',label='interpolation of data') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='cubic') #plt.plot(wavenew,kappanew,'g--',label='cubic') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='nearest') #plt.plot(wavenew,kappanew,'b--',label='nearest') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='slinear') #plt.plot(wavenew,kappanew,'y--',label='slinear') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='quadratic') #plt.plot(wavenew,kappanew,'m--',label='quadratic') #kappanew = kbs.interpn(wavedat,kappadat,wavenew,method='zero') #plt.plot(wavenew,kappanew,'r:',label='zero') plt.plot(waveval,kappa,'go',label='obtained value') plt.legend(fancybox=True, loc='upper right') # add the legend in the middle of the plot plt.show() return kappa