#!/net/python/bin/python from Header import * from Function1D import * from Spectrum import * from extinction import CardelliExtinction class Filter(Function1D): def __init__(self,filterset='',filtername=''): self.name = filtername self.getfromfile(FilterFile(filterset,filtername)) self.mean_l = None #will hold mean wavelength when calculated # to save computation time self.vegaflux = None def copy(self): selfcopy = self.__class__() selfcopy.x = self.x.copy() selfcopy.y = self.y.copy() selfcopy.mean_l = self.mean_l selfcopy.vegaflux = self.vegaflux return selfcopy def CCDflux(self,spectrum,ZP): sourceSignal = self.PhotonFlux( spectrum ) if self.vegaflux is None: self.vegaflux = self.PhotonFlux( GetRefSpectrum() ) return sourceSignal/self.vegaflux * 10**(0.4*ZP) def Mag(self,spectrum): sourceSignal = self.PhotonFlux( spectrum ) if self.vegaflux is None: self.vegaflux = self.PhotonFlux( GetRefSpectrum() ) return -2.5*num.log10(sourceSignal/self.vegaflux) def mean(self): if self.mean_l == None: self.mean_l = self.xmean() return self.mean_l def PhotonFlux(self,spectrum): # number of photons = energy/(h*nu) = energy * lam/(2*pi*hbar*c) # 2*pi* hbar*c # = 2* pi * 197 eV nm # = 6.28*197 * 1.60e-12 * 10 ergs angst # = 1.97946e-08 # = 1/5.006909561e07 return 5.006909561E07 * (self * spectrum * (lambda x:x)).integrate() def ErgFlux(self,spectrum): return (self*spectrum).integrate() #--Redshifting functions------------- def redshift(self,z): selfcopy = self.xshift( 1.+z ) if self.mean_l is not None: selfcopy.mean_l = self.mean_l*(1.+z) else: selfcopy.mean_l = None selfcopy.vegaflux = None return selfcopy def blueshift(self,z): selfcopy = self.xshift( 1./(1.+z) ) if self.mean_l is not None: selfcopy.mean_l = self.mean_l/(1.+z) else: selfcopy.mean_l = None selfcopy.vegaflux = None return selfcopy def unredshift(self,z): return self.blueshift(z) def unblueshift(self,z): return self.redshift(z) #------------------------------------- def extincted(self,EBV,Rv=3.1): """ returns a copy of self adjusted according to Cardelli extinction law """ #CardelliExtinction function comes from extinction.py selfcopy = self.copy() selfcopy.vegaflux = None selfcopy.mean_l = None for i in range(len(selfcopy)): lam = selfcopy.x[i] selfcopy.y[i] *= CardelliExtinction(lam,EBV,Rv) return selfcopy def z_where_tossed(self,BlueCutoff=3460.0,RedCutoff=6600.0): mean_l = self.mean() Rcut = mean_l/RedCutoff - 1 Bcut = mean_l/BlueCutoff -1 if Rcut > 0: return '%.3f < z < %.3f' % (Rcut,Bcut) else: return 'z < %.3f' % Bcut if __name__ == '__main__': for f in 'ugriz': F = Filter('SDSS',f) F.graph() print "%s: %.3f" % ( f,F.mean() ) p.show()