Пример #1
0
def read_stdatmo(override_filename = None):
    # read the standard atmosphere bandpass file, precomputed by MODTRAN & DaveBurke.
    # this is closely equivalent to atmos_12.dat
    atmosdir = os.getenv("LSST_THROUGHPUTS_ATMOS")
    atmos_bp = Bandpass()
    if override_filename == None:
        atmos_bp.readThroughput(os.path.join(atmosdir, "atmos_std.dat"))
    else:
        atmos_bp.readThroughput(os.path.join(atmosdir, override_filename))
    return atmos_bp
Пример #2
0
def read_filtersonly(shift_perc=None):
    filterdir = os.getenv("LSST_THROUGHPUTS_DEFAULT")
    filters = {}
    for f in filterlist:
        filters[f] = Bandpass()
        filters[f].readThroughput(os.path.join(filterdir, "filter_" + f + ".dat"))
        effwavelenphi, effwavelensb = filters[f].calcEffWavelen()
        if shift_perc != None:
            shift = effwavelensb * shift_perc/100.0
            print f, shift, " nm = ", shift*10.0, " A"
            filters[f].wavelen = filters[f].wavelen + shift
            filters[f].resampleBandpass()
    return filters
Пример #3
0
def read_atmos():
    # Read some atmosphere throughputs.
    atmosdir = "."
    atmos = {}
    key = "Standard"
    atmos[key]= Bandpass()
    atmos[key].readThroughput(os.path.join(atmosdir, "atmos_std.dat"))
    key = "X=1.0" # H2O=0.5
    atmos[key] = Bandpass()
    atmos[key].readThroughput(os.path.join(atmosdir, "atmos_lo.dat"))
    key = "X=1.8" # H2O=1.5
    atmos[key] = Bandpass()
    atmos[key].readThroughput(os.path.join(atmosdir, "atmos_hi.dat"))
    return atmos
Пример #4
0
def read_atmos():
    # read atmosphere throughputs, make plots
    atmosdir = "."
    atmos = {}
    key = "Standard"
    atmos[key] = Bandpass()
    atmos[key].readThroughput(os.path.join(atmosdir, "atmos_std.dat"))
    key = "X=1.0, H2O=0.5"
    atmos[key] = Bandpass()
    atmos[key].readThroughput(os.path.join(atmosdir, "atmos_lo.dat"))
    key = "X=1.8, H2O=1.5"
    atmos[key] = Bandpass()
    atmos[key].readThroughput(os.path.join(atmosdir, "atmos_hi.dat"))
    return atmos
Пример #5
0
def read_filtersonly(shift_perc=None):
    # read the filter throughput curves only (called from read_hardware as well)
    # apply a shift of +shift_perc/100 * eff_wavelength to the wavelengths of the filter.
    filterdir = os.getenv("LSST_THROUGHPUTS_DEFAULT")
    filters = {}
    for f in filterlist:
        filters[f] = Bandpass()
        filters[f].readThroughput(os.path.join(filterdir, "filter_" + f + ".dat"))
        effwavelenphi, effwavelensb = filters[f].calcEffWavelen()
        if shift_perc != None:
            shift = effwavelensb * shift_perc/100.0
            print f, shift
            filters[f].wavelen = filters[f].wavelen + shift
            filters[f].resampleBandpass()
    return filters
Пример #6
0
def read_wvfiles():
    tt = os.listdir('.')
    files = []
    for t in tt:
        if t.startswith('am') & t.endswith('.plt'):
            files.append(t)
    print files
    atms = {}
    wvs = []
    for f in files:
        wv = f[9:12]
        print wv, f
        wvs.append(wv)
        atms[wv] = Bandpass()
        atms[wv].readThroughput(f, wavelen_step=0.1)
    std = Bandpass()
    std.readThroughput(
        os.path.join(os.getenv('LSST_THROUGHPUTS_ATMOS'), 'atmos_12.dat'))
    #std.readThroughput('atmos_85143574.dat', wavelen_step=.1)

    # calculate effect of absorption ..
    condition = ((atms[wvs[0]].wavelen >= 850) &
                 (atms[wvs[0]].wavelen <= 1100))
    abs = {}
    for w in wvs:
        abs[w] = (1 - atms[w].sb[condition]).sum() * 0.1
        print w, abs[w]

    # check with a plot
    max = len(wvs) - 1
    pylab.figure()
    for w in [wvs[0], wvs[max]]:
        pylab.plot(atms[w].wavelen, atms[w].sb, label=w)
    pylab.plot(std.wavelen, std.sb, 'k-', label='std')
    pylab.legend(loc='lower right')
    pylab.xlabel('Wavelength')
    pylab.ylabel('Transmission')
    pylab.xlim(900, 1000)
    pylab.figure()
    for w in [wvs[0], wvs[max]]:
        pylab.plot(atms[w].wavelen, atms[w].sb, label=w)
    pylab.plot(std.wavelen, std.sb, 'k-', label='std')
    pylab.legend(loc='lower right')
    pylab.xlabel('Wavelength')
    pylab.ylabel('Transmission')
    #pylab.show()

    return atms, wvs, std
Пример #7
0
def read_filtersonly(shift_perc=None):
    # read the filter throughput curves only (called from read_hardware as well)
    # apply a shift of +shift_perc/100 * eff_wavelength to the wavelengths of the filter.
    filterdir = os.getenv("LSST_THROUGHPUTS_DEFAULT")
    filters = {}
    for f in filterlist:
        filters[f] = Bandpass()
        filters[f].readThroughput(
            os.path.join(filterdir, "filter_" + f + ".dat"))
        effwavelenphi, effwavelensb = filters[f].calcEffWavelen()
        if shift_perc != None:
            shift = effwavelensb * shift_perc / 100.0
            print f, shift
            filters[f].wavelen = filters[f].wavelen + shift
            filters[f].resampleBandpass()
    return filters
Пример #8
0
def build_atmos(atmocmp=None,
                X=1.0,
                t0=(3.9 / 100.0),
                t1=(0.02 / 100.0),
                t2=(-0.03 / 100.0),
                alpha=-1.7,
                mol=0.96,
                BP=782,
                O3=0.9,
                H2O=0.9,
                doPlot=False):
    if atmocmp == None:
        atmocmp = ac.AtmoComp()
    # examples
    # max atmo = build_atmos(atmocmp, X=X, t0=5.6/100.0, alpha=-1.8, O3=1.5, H2O=1.3)
    # min atmo = build_atmos(atmocmp, X=X, t0=0.2/100.0, alpha=-0.5, O3=0.6, H2O=0.5)
    # 30p atmo = build_atmos(atmocmp, X=2.5, t0=(0.8/100), alpha=-1.0, O3=0.9, H2O=0.8)
    # 30p atmo = build_atmos(atmocmp, X=2.5, t0=(2.4/100.0), alpha=-1.4, O3=1.17, H2O=1.04)
    # 10p/30 atmo = build_atmos(atmocmp, X=X, t0=(0.8/100.0), alpha=-1.0, O3=0.9, H2O=0.8)
    # 10p/30 atmo = build_atmos(atmocmp, X=X, t0=(1.3/100.0), alpha=-1.13, O3=0.99, H2O=1.04)
    atmocmp.setCoefficients(t0=t0,
                            t1=t1,
                            t2=t2,
                            alpha=alpha,
                            mol=mol,
                            BP=BP,
                            O3=O3,
                            H2O=H2O)
    atmocmp.buildAtmos(secz=X, doPlot=doPlot)
    atmos_bp = Bandpass(wavelen=atmocmp.wavelen, sb=atmocmp.trans_total)
    return atmocmp, atmos_bp
Пример #9
0
def combine_throughputs(atmos, sys):
    # Set up the total throughput for this system bandpass
    total = {}
    for f in filterlist:
        wavelen, sb = sys[f].multiplyThroughputs(atmos.wavelen, atmos.sb)
        total[f] = Bandpass(wavelen, sb)
        total[f].sbTophi()
    return total
Пример #10
0
def read_wvfiles():
    tt = os.listdir('.')
    files = []
    for t in tt:
        if t.startswith('am') & t.endswith('.plt'):
            files.append(t)
    print files
    atms = {}
    wvs = []
    for f in files:
        wv = f[9:12]
        print wv, f
        wvs.append(wv)
        atms[wv] = Bandpass()
        atms[wv].readThroughput(f, wavelen_step=0.1)
    std = Bandpass()
    std.readThroughput(os.path.join(os.getenv('LSST_THROUGHPUTS_ATMOS'), 'atmos_12.dat'))
    #std.readThroughput('atmos_85143574.dat', wavelen_step=.1)

    # calculate effect of absorption ..
    condition = ((atms[wvs[0]].wavelen >= 850) & (atms[wvs[0]].wavelen <= 1100))
    abs = {}
    for w in wvs:
        abs[w] = (1-atms[w].sb[condition]).sum() * 0.1
        print w, abs[w]

    # check with a plot
    max = len(wvs)-1
    pylab.figure()
    for w in [wvs[0], wvs[max]]:
        pylab.plot(atms[w].wavelen, atms[w].sb, label=w)
    pylab.plot(std.wavelen, std.sb, 'k-', label='std')
    pylab.legend(loc='lower right')
    pylab.xlabel('Wavelength')
    pylab.ylabel('Transmission')
    pylab.xlim(900, 1000)
    pylab.figure()
    for w in [wvs[0], wvs[max]]:
        pylab.plot(atms[w].wavelen, atms[w].sb, label=w)
    pylab.plot(std.wavelen, std.sb, 'k-', label='std')
    pylab.legend(loc='lower right')
    pylab.xlabel('Wavelength')
    pylab.ylabel('Transmission')
    #pylab.show()

    return atms, wvs, std
Пример #11
0
def read_hardware(shift_perc=None):
    # read system (hardware) transmission)
    filterdir = os.getenv("LSST_THROUGHPUTS_DEFAULT")
    hardware = ("detector.dat", "m1.dat", "m2.dat", "m3.dat", "lens1.dat", "lens2.dat", "lens3.dat")
    # Read in the standard components, but potentially shift the filter by shift_perc percent.
    filters = read_filtersonly(shift_perc=shift_perc)
    sys = {}
    for f in filterlist:
        sys[f] = Bandpass()
        # put together the standard component list
        tlist = []
        for t in hardware:
            tlist.append(os.path.join(filterdir, t))
        # read in the standard components, combine into sys
        sys[f].readThroughputList(tlist)
        # multiply by the filter throughput for final hardware throughput (no atmosphere)
        sys[f].wavelen, sys[f].sb = sys[f].multiplyThroughputs(filters[f].wavelen, filters[f].sb)
    return sys
Пример #12
0
def read_hardware(shift_perc=None):
    # read system (hardware) transmission, return dictionary of system hardware (keyed to filter)
    filterdir = os.getenv("LSST_THROUGHPUTS_DEFAULT")
    hardware = ("detector.dat", "m1.dat", "m2.dat", "m3.dat", "lens1.dat", "lens2.dat", "lens3.dat")
    # Read in the standard components, but potentially shift the filter by shift_perc percent.
    filters = read_filtersonly(shift_perc=shift_perc)
    sys = {}
    for f in filterlist:
        sys[f] = Bandpass()
        # put together the standard component list
        tlist = []
        for t in hardware:
            tlist.append(os.path.join(filterdir, t))
        # read in the standard components, combine into sys
        sys[f].readThroughputList(tlist)
        # multiply by the filter throughput for final hardware throughput (no atmosphere)
        sys[f].wavelen, sys[f].sb = sys[f].multiplyThroughputs(filters[f].wavelen, filters[f].sb)
    return sys
Пример #13
0
def combine_throughputs(atmos, sys):
    # Set up the total throughput for this system bandpass, using the variety of atmospheres. 
    total = {}
    for key in atmos.keys():
        total[key] = {}
        for f in filterlist:
            wavelen, sb = sys[f].multiplyThroughputs(atmos[key].wavelen, atmos[key].sb)
            total[key][f] = Bandpass(wavelen, sb)
            total[key][f].sbTophi()
    return total
Пример #14
0
 def getSpecNorms(self, sedfile, mag, filtstr):
     band = Bandpass()
     band.readThroughput(
         os.path.join(self.tpath, "total_%s.dat" % (filtstr)))
     imsimband = Bandpass()
     imsimband.imsimBandpass()
     sed = Sed()
     sed.readSED_flambda(self.spath + "/" + sedfile)
     fluxNorm = sed.calcFluxNorm(mag, band)
     sed.multiplyFluxNorm(fluxNorm)
     magNorm = sed.calcMag(imsimband)
     return magNorm, fluxNorm
Пример #15
0
 def calcLSSTMags(self, sedfile, fluxnorm):
     sed = Sed()
     sed.readSED_flambda(self.spath + "/" + sedfile)
     sed.multiplyFluxNorm(fluxnorm)
     mags = []
     for filtstr in ('u', 'g', 'r', 'i', 'z', 'y'):
         band = Bandpass()
         band.readThroughput(
             os.path.join(self.tpath, "total_%s.dat" % (filtstr)))
         imsimband = Bandpass()
         imsimband.imsimBandpass()
         mags.append(sed.calcMag(band))
     return mags
 def calcMagNorm(self, spec, mag, redshift, filter='i'):
   """Calculate the SED normalization given a spectrum, redshift, and
   reference magnitude.  ***This assumes not host redenning.***
   """
   #Setup the filters
   imsimband = Bandpass()
   imsimband.imsimBandpass()
   #setup the sed
   sed = Sed()
   sed.readSED_flambda(os.path.join(self.spath,spec))
   #need the rest frame spectrum for calculating the mag norm since
   #the normalization is applied in the rest frame
   sed_orig = deepcopy(sed)
   #Redshift the spectrum
   sed.redshiftSED(redshift, dimming=True)
   #Calculate the normalization using the reference magnitude
   fluxNorm = sed.calcFluxNorm(mag, self.bands[filter])
   sed_orig.multiplyFluxNorm(fluxNorm)
   #Calculate the normalization in units of magnitudes
   magNorm = sed_orig.calcMag(imsimband)
   return magNorm, fluxNorm
Пример #17
0
    def __init__(self, metafile, trimfilename, centfilename, outfile, donum = None):
        self.datadir = os.environ.get("SIMS_DATA_DIR")

        self.tpath = os.getenv('LSST_THROUGHPUTS_DEFAULT')
        self.spath = os.getenv('SIMS_SED_LIBRARY_DIR')
        self.bands = {"u":None, "g":None, "r":None, "i":None, "z":None, "y":None}
        keys = self.bands.keys()
        for k in keys:
            self.bands[k] = Bandpass()
            self.bands[k].readThroughput(os.path.join(self.tpath, "total_%s.dat"%k))
        self.imsimband = Bandpass()
        self.imsimband.imsimBandpass()
        self.mfile = metafile
        self.tfile = trimfilename
        self.ofile = outfile
        self.outdata = {'id':[],'u':[], 'g':[], 'r':[], 'i':[], 'z':[],
                'y':[]}
        self.centdata = self.readCentroid(centfilename)
        self.filtmap = {0:'u', 1:'g', 2:'r', 3:'i', 4:'z', 5:'y'}
        self.filter = None
        self.donum = donum
Пример #18
0
 def calcMagNorm(self, spec, mag, redshift, filter='i'):
     """Calculate the SED normalization given a spectrum, redshift, and
 reference magnitude.  ***This assumes not host redenning.***
 """
     #Setup the filters
     imsimband = Bandpass()
     imsimband.imsimBandpass()
     #setup the sed
     sed = Sed()
     sed.readSED_flambda(os.path.join(self.spath, spec))
     #need the rest frame spectrum for calculating the mag norm since
     #the normalization is applied in the rest frame
     sed_orig = deepcopy(sed)
     #Redshift the spectrum
     sed.redshiftSED(redshift, dimming=True)
     #Calculate the normalization using the reference magnitude
     fluxNorm = sed.calcFluxNorm(mag, self.bands[filter])
     sed_orig.multiplyFluxNorm(fluxNorm)
     #Calculate the normalization in units of magnitudes
     magNorm = sed_orig.calcMag(imsimband)
     return magNorm, fluxNorm
 def calcAbsMag(self, mag, D_L, spec, redshift, filter='i'):
   """Calculate an absolute magnitude given a filter, luminosity distance,
   apparent magnitude, sed, and redshift
   """
   #Get default locations for filters and seds
   #Set up filters and sed
   imsimband = Bandpass()
   imsimband.imsimBandpass()
   sed = Sed()
   sed.readSED_flambda(os.path.join(self.spath,spec))
   #Calculate rest frame magnitude
   magr = sed.calcMag(self.bands[filter])
   #redshift spectrum
   sed.redshiftSED(redshift, dimming=False)
   #calculate observed frame magnitude
   mago = sed.calcMag(self.bands[filter])
   #SED portion of the K-correction
   Kcorr = mago-magr
   #Cosmological portion of the K-correction due to the dilation of the
   #filter
   Kcorrz = 2.5*numpy.log10(1+redshift)
   #D_L is in Mpc so the normal relation goes 5.(log(D_L) +6.-1.)
   absMag = mag - (5.*(numpy.log10(D_L) + 5.)) - Kcorr - Kcorrz
   return absMag
Пример #20
0
 def calcAbsMag(self, mag, D_L, spec, redshift, filter='i'):
     """Calculate an absolute magnitude given a filter, luminosity distance,
 apparent magnitude, sed, and redshift
 """
     #Get default locations for filters and seds
     #Set up filters and sed
     imsimband = Bandpass()
     imsimband.imsimBandpass()
     sed = Sed()
     sed.readSED_flambda(os.path.join(self.spath, spec))
     #Calculate rest frame magnitude
     magr = sed.calcMag(self.bands[filter])
     #redshift spectrum
     sed.redshiftSED(redshift, dimming=False)
     #calculate observed frame magnitude
     mago = sed.calcMag(self.bands[filter])
     #SED portion of the K-correction
     Kcorr = mago - magr
     #Cosmological portion of the K-correction due to the dilation of the
     #filter
     Kcorrz = 2.5 * numpy.log10(1 + redshift)
     #D_L is in Mpc so the normal relation goes 5.(log(D_L) +6.-1.)
     absMag = mag - (5. * (numpy.log10(D_L) + 5.)) - Kcorr - Kcorrz
     return absMag
Пример #21
0
def read_stdatmo(override_filename=None):
    # read the standard atmosphere bandpass file, precomputed by MODTRAN & DaveBurke.
    # this is closely equivalent to atmos_12.dat
    atmosdir = os.getenv("LSST_THROUGHPUTS_ATMOS")
    atmos_bp = Bandpass()
    if override_filename == None:
        atmos_bp.readThroughput(os.path.join(atmosdir, "atmos_std.dat"))
    else:
        atmos_bp.readThroughput(os.path.join(atmosdir, override_filename))
    return atmos_bp
 def getSpecNorms(self, sedfile, mag, filtstr):
     band = Bandpass()
     band.readThroughput(os.path.join(self.tpath, "total_%s.dat"%(filtstr)))
     imsimband = Bandpass()
     imsimband.imsimBandpass()
     sed = Sed()
     sed.readSED_flambda(self.spath+"/"+sedfile)
     fluxNorm = sed.calcFluxNorm(mag, band)
     sed.multiplyFluxNorm(fluxNorm)
     magNorm = sed.calcMag(imsimband)
     return magNorm, fluxNorm
 def calcLSSTMags(self, sedfile, fluxnorm):
     sed = Sed()
     sed.readSED_flambda(self.spath+"/"+sedfile)
     sed.multiplyFluxNorm(fluxnorm)
     mags = []
     for filtstr in ('u', 'g', 'r', 'i', 'z', 'y'):
         band = Bandpass()
         band.readThroughput(os.path.join(self.tpath, "total_%s.dat"%(filtstr)))
         imsimband = Bandpass()
         imsimband.imsimBandpass()
         mags.append(sed.calcMag(band))
     return mags
Пример #24
0
def combine_throughputs(atmos, sys_std, sys_edge):
    # Set up all the 'total' throughputs
    total = {}
    key = 'standard'
    total[key] = {}
    for f in filterlist:
        wavelen, sb = sys_std[f].multiplyThroughputs(atmos['Standard'].wavelen,
                                                     atmos['Standard'].sb)
        total[key][f] = Bandpass(wavelen, sb)
        total[key][f].sbTophi()
    key = 'standard, edge'
    total[key] = {}
    for f in filterlist:
        wavelen, sb = sys_edge[f].multiplyThroughputs(
            atmos['Standard'].wavelen, atmos['Standard'].sb)
        total[key][f] = Bandpass(wavelen, sb)
        total[key][f].sbTophi()
    key = 'low X, center'
    total[key] = {}
    for f in filterlist:
        wavelen, sb = sys_std[f].multiplyThroughputs(
            atmos['X=1.0, H2O=0.5'].wavelen, atmos['X=1.0, H2O=0.5'].sb)
        total[key][f] = Bandpass(wavelen, sb)
        total[key][f].sbTophi()
    key = 'hi X, center'
    total[key] = {}
    for f in filterlist:
        wavelen, sb = sys_std[f].multiplyThroughputs(
            atmos['X=1.8, H2O=1.5'].wavelen, atmos['X=1.8, H2O=1.5'].sb)
        total[key][f] = Bandpass(wavelen, sb)
        total[key][f].sbTophi()
    key = 'low X, edge'
    total[key] = {}
    for f in filterlist:
        wavelen, sb = sys_edge[f].multiplyThroughputs(
            atmos['X=1.0, H2O=0.5'].wavelen, atmos['X=1.0, H2O=0.5'].sb)
        total[key][f] = Bandpass(wavelen, sb)
        total[key][f].sbTophi()
    key = 'hi X, edge'
    total[key] = {}
    for f in filterlist:
        wavelen, sb = sys_edge[f].multiplyThroughputs(
            atmos['X=1.8, H2O=1.5'].wavelen, atmos['X=1.8, H2O=1.5'].sb)
        total[key][f] = Bandpass(wavelen, sb)
        total[key][f].sbTophi()
    pylab.figure()
    for key in total.keys():
        i = 0
        for f in filterlist:
            pylab.plot(total[key][f].wavelen, total[key][f].phi, colors[i])
            i = color_counter_next(i)
    return total
Пример #25
0
def get_atmos(atmocmp,
              X=1.0,
              t0=(3.9 / 100.0),
              t1=(0.02 / 100.0),
              t2=(-0.03 / 100.0),
              alpha=-1.7,
              mol=0.96,
              BP=782,
              O3=0.9,
              H2O=0.9):
    atmocmp.setCoefficients(t0=t0,
                            t1=t1,
                            t2=t2,
                            alpha=alpha,
                            mol=mol,
                            BP=BP,
                            O3=O3,
                            H2O=H2O)
    atmocmp.buildAtmos(secz=X, doplot=True)
    atmos_bp = Bandpass(wavelen=atmocmp.wavelen, sb=atmocmp.trans_total)
    return atmocmp, atmos_bp
Пример #26
0
 def __init__(self, file, posfile):
     self.keymap = ['u', 'g', 'r', 'i', 'z', 'y']
     self.indmap = {
         '0': 'u',
         '1': 'g',
         '2': 'r',
         '3': 'i',
         '4': 'z',
         '5': 'y'
     }
     #Read the data file.  This will presumably need to be specific to the data
     #Set paths to default throughputs and seds
     self.tpath = os.getenv('LSST_THROUGHPUTS_DEFAULT')
     self.spath = os.getenv('SIMS_SED_LIBRARY_DIR')
     self.bands = {}
     for k in self.keymap:
         self.bands[k] = Bandpass()
         self.bands[k].readThroughput(
             os.path.join(self.tpath, "total_%s.dat" % k))
     sed = Sed()
     (self.phiarr, self.wavelen_step) = sed.setupPhiArray(
         self.mapFiltDictToArr(self.bands))
     self.centpos = self.readPositionFile(posfile)
     (self.lensData, self.imgData) = self.readFile(file)
Пример #27
0
class testPhotTrim (object):
    def __init__(self, metafile, trimfilename, centfilename, outfile, donum = None):
        self.datadir = os.environ.get("SIMS_DATA_DIR")

        self.tpath = os.getenv('LSST_THROUGHPUTS_DEFAULT')
        self.spath = os.getenv('SIMS_SED_LIBRARY_DIR')
        self.bands = {"u":None, "g":None, "r":None, "i":None, "z":None, "y":None}
        keys = self.bands.keys()
        for k in keys:
            self.bands[k] = Bandpass()
            self.bands[k].readThroughput(os.path.join(self.tpath, "total_%s.dat"%k))
        self.imsimband = Bandpass()
        self.imsimband.imsimBandpass()
        self.mfile = metafile
        self.tfile = trimfilename
        self.ofile = outfile
        self.outdata = {'id':[],'u':[], 'g':[], 'r':[], 'i':[], 'z':[],
                'y':[]}
        self.centdata = self.readCentroid(centfilename)
        self.filtmap = {0:'u', 1:'g', 2:'r', 3:'i', 4:'z', 5:'y'}
        self.filter = None
        self.donum = donum

    def readCentroid(self,file):
        ifh = open(file)
        data = {}
        for l in ifh:
            flds = l.rstrip().split()
            if flds[0].startswith("Source") or int(flds[1]) == 0:
                continue
            data[float(flds[0])] = {'photons':int(flds[1]), 'x':float(flds[2]), 'y':float(flds[3])}
        return data

    def mkGalPhot(self):
        ifh = open(self.mfile)
        lnum = 0
        k = None
        for l in ifh:
            flds = l.rstrip().split()
            if l.startswith("Opsim_filter"):
                self.filter = self.filtmap[int(flds[1])]
                k = self.filter
        ifh.close()
        ifh = open(self.tfile)
        for l in ifh:
            flds = l.rstrip().split()
            if not flds[0] == "object":
                continue
            otype = flds[12]
            if otype != "sersic2D":
                continue
            id = float(flds[1])
            if not self.centdata.has_key(id):
                continue
            magNorm = float(flds[4])
            spec = flds[5]
            redshift = float(flds[6])
            ind = float(flds[16])
            mwav = float(flds[21])
            av = float(flds[18])
            sed = Sed()
            sed.readSED_flambda(self.spath+"/"+spec)
            a_int, b_int = sed.setupCCMab()
            self.outdata['id'].append(id)
            if lnum > self.donum and self.donum is not None:
                break
            if lnum%10000 == 0:
                print id
            fluxNorm = sed.calcFluxNorm(magNorm, self.imsimband)
            sed.multiplyFluxNorm(fluxNorm/(1+redshift))
            sed.addCCMDust(a_int, b_int, A_v=av)
            sed.redshiftSED(redshift, dimming=False)
            a_mw, b_mw = sed.setupCCMab()
            sed.addCCMDust(a_mw, b_mw, A_v=mwav)
            line = {'flux':None, 'mag':None}
            mag = sed.calcMag(self.bands[k])
            flux = sed.calcADU(self.bands[k], gain=1.0)
            line['mag'] = mag
            line['flux'] = flux
            self.outdata[k].append(line)
            lnum += 1
        ifh.close()

    def mkStarPhot(self):
        ifh = open(self.mfile)
        lnum = 0
        k = None
        for l in ifh:
            flds = l.rstrip().split()
            if l.startswith("Opsim_filter"):
                self.filter = self.filtmap[int(flds[1])]
                k = self.filter
        ifh.close()
        ifh = open(self.tfile)
        for l in ifh:
            flds = l.rstrip().split()
            if not flds[0] == "object":
                continue
            otype = flds[12]
            if otype != "point":
                continue
            id = float(flds[1])
            if not self.centdata.has_key(id):
                continue
            magNorm = float(flds[4])
            spec = flds[5]
            av = float(flds[14])
            sed = Sed()
            self.outdata['id'].append(id)
            if re.search("kurucz", spec):
              sed.readSED_flambda(self.spath+"/"+spec)
            else:
              sed.readSED_flambda(self.spath+"/"+spec)
            fluxNorm = sed.calcFluxNorm(magNorm, self.imsimband)
            sed.multiplyFluxNorm(fluxNorm)
            a, b = sed.setupCCMab()
            sed.addCCMDust(a, b, A_v=av)
            line = {'flux':None, 'mag':None}
            mag = sed.calcMag(self.bands[k])
            flux = sed.calcADU(self.bands[k], gain=1.)
            line['mag'] = mag
            line['flux'] = flux
            self.outdata[k].append(line)
            lnum += 1
        ifh.close()

    def printComp(self):
        ofh = open(self.ofile, "w")
        for id, mag in zip(self.outdata['id'], self.outdata[self.filter]):
            if self.centdata.has_key(id):
                line = (id,mag['mag'],mag['flux'],self.centdata[id]['photons'])
                ofh.write(",".join([str(el) for el in line])+"\n")
        ofh.close()
Пример #28
0
def read_stdatmo():
    atmosdir = "."
    atmos_bp = Bandpass()
    atmos_bp.readThroughput(os.path.join(atmosdir, "atmos_std.dat"))
    return atmos_bp
Пример #29
0
def atmo_BP(atmocmp):
    atmos_bp = Bandpass(wavelen=atmocmp.wavelen, sb=atmocmp.trans_total)
    return atmos_bp
Пример #30
0
for i in range(tests):
    t = time.time()
    print "Generating atmosphere for a test case:"
    print paramList[i]
    
    # Write modtran input cards
    m.writeModtranCards(paramList[i], 'tmp')

    # Run modtran on this file.
    m.runModtran('tmp')
    
    dt, t = dtime(t)
    print "Generating atmosphere took %f seconds." %(dt)

    # Read the atmosphere back in and plot to screen. 
    atm = Bandpass()
#    atm.readThroughput('tmp.psc', wavelen_min=800, wavelen_max=1300, wavelen_step=0.001)
    atm.readThroughput('tmp.psc', wavelen_min=300, wavelen_max=1100, wavelen_step=0.1)
    pylab.plot(atm.wavelen, atm.sb, 'b-')
    pylab.xlabel('Wavelength (nm)')
    pylab.ylabel('Atmospheric Transmission')
    
    m.cleanModtran('tmp')


pylab.show()




Пример #31
0
    return sed, colors, refrac
    
def integrate(sed, bp):
    wavelen = sed.wavelen
    fnu = sed.fnu
    if sed.needResample(wavelen=wavelen, wavelen_match=bp.wavelen):
        wavelen, fnu = sed.resampleSED(wavelen, fnu, wavelen_match=bp.wavelen)
    return np.sum(fnu * bp.phi)

if __name__ == "__main__":
    pickleFile = "calculateSedDcr3.pickle"
    if not os.path.isfile(pickleFile):
        catDir = os.environ["CAT_SHARE_DATA"]
        filtDir = os.environ["LSST_THROUGHPUTS_BASELINE"]
        uBand  = Bandpass()
        gBand  = Bandpass()
        rBand  = Bandpass()
        iBand  = Bandpass()
        zBand  = Bandpass()
        uBand.readThroughput(os.path.join(filtDir, "total_u.dat"))
        gBand.readThroughput(os.path.join(filtDir, "total_g.dat"))
        rBand.readThroughput(os.path.join(filtDir, "total_r.dat"))
        iBand.readThroughput(os.path.join(filtDir, "total_i.dat"))
        zBand.readThroughput(os.path.join(filtDir, "total_z.dat"))
        uBand.sbTophi()
        gBand.sbTophi()
        rBand.sbTophi()
        iBand.sbTophi()
        zBand.sbTophi()
    
Пример #32
0
import os
import numpy
import selfcal.analyze.useful_input as ui
import lsst.sims.catalogs.measures.photometry.Sed as Sed
import lsst.sims.catalogs.measures.photometry.Bandpass as Bandpass

# filter id table:
filterlist = ('u', 'g', 'r', 'i', 'z', 'y')
filterdict = {'u':0, 'g':1, 'r':2, 'i':3, 'z':4, 'y':5}
rootdir = os.getenv("LSST_THROUGHPUTS_BASELINE")
lsst = {}
for f in filterlist:
    lsst[f] = Bandpass()
    lsst[f].readThroughput(rootdir + "/total_" + f + ".dat")
imsimband = Bandpass()
imsimband.imsimBandpass()

# set up colors of objects in all bandpasses
rootdir_sed = "."
sedlist = ('S.dat', 'C.dat')
simobjs = {}
simmags = {}
for sed in sedlist:
    simobjs[sed] = Sed()
    simobjs[sed].readSED_flambda(rootdir_sed + sed)
    simmags[sed] = {}
    for filter in filterlist:
        simmags[sed][filter] = simobjs[sed].calcMag(lsst[filter])
    simmags[sed]['ims'] = simobjs[sed].calcMag(imsimband)
    
Пример #33
0
# script to help generate diasources and their magnitudes /SNR in a particular filter

import os
import numpy
import selfcal.analyze.useful_input as ui
import lsst.sims.catalogs.measures.photometry.Sed as Sed
import lsst.sims.catalogs.measures.photometry.Bandpass as Bandpass

# filter id table:
filterlist = ('u', 'g', 'r', 'i', 'z', 'y')
filterdict = {'u': 0, 'g': 1, 'r': 2, 'i': 3, 'z': 4, 'y': 5}
rootdir = os.getenv("LSST_THROUGHPUTS_BASELINE")
lsst = {}
for f in filterlist:
    lsst[f] = Bandpass()
    lsst[f].readThroughput(rootdir + "/total_" + f + ".dat")
imsimband = Bandpass()
imsimband.imsimBandpass()

# set up colors of objects in all bandpasses
rootdir_sed = "."
sedlist = ('S.dat', 'C.dat')
simobjs = {}
simmags = {}
for sed in sedlist:
    simobjs[sed] = Sed()
    simobjs[sed].readSED_flambda(rootdir_sed + sed)
    simmags[sed] = {}
    for filter in filterlist:
        simmags[sed][filter] = simobjs[sed].calcMag(lsst[filter])
    simmags[sed]['ims'] = simobjs[sed].calcMag(imsimband)
Пример #34
0
tests = 2

for i in range(tests):
    t = time.time()
    print("Generating atmosphere for a test case:")
    print(paramList[i])

    # Write modtran input cards
    m.writeModtranCards(paramList[i], 'tmp')

    # Run modtran on this file.
    m.runModtran('tmp')

    dt, t = dtime(t)
    print("Generating atmosphere took %f seconds." % (dt))

    # Read the atmosphere back in and plot to screen.
    atm = Bandpass()
    #    atm.readThroughput('tmp.psc', wavelen_min=800, wavelen_max=1300, wavelen_step=0.001)
    atm.readThroughput('tmp.psc',
                       wavelen_min=300,
                       wavelen_max=1100,
                       wavelen_step=0.1)
    pylab.plot(atm.wavelen, atm.sb, 'b-')
    pylab.xlabel('Wavelength (nm)')
    pylab.ylabel('Atmospheric Transmission')

    m.cleanModtran('tmp')

pylab.show()
Пример #35
0
def read_hardware():
    # read system (hardware) transmission)
    filterdir = os.getenv("LSST_THROUGHPUTS_DEFAULT")
    hardware = ("detector.dat", "m1.dat", "m2.dat", "m3.dat", "lens1.dat",
                "lens2.dat", "lens3.dat")
    sys_std = {}
    # Read in all the standard components
    for f in filterlist:
        sys_std[f] = Bandpass()
        tlist = []
        for t in hardware:
            tlist.append(os.path.join(filterdir, t))
        tlist.append(os.path.join(filterdir, "filter_" + f + ".dat"))
        sys_std[f].readThroughputList(tlist)
    sys_edge = {}
    # Read in the standard components, except shift the filter by 1% of the central wavelength near the edge
    for f in filterlist:
        sys_edge[f] = Bandpass()
        tlist = []
        for t in hardware:
            tlist.append(os.path.join(filterdir, t))
        sys_edge[f].readThroughputList(tlist)
        tmpfilter = Bandpass()
        tmpfilter.readThroughput(
            os.path.join(filterdir, "filter_" + f + ".dat"))
        effwavelenphi, effwavelensb = tmpfilter.calcEffWavelen()
        shift = effwavelensb * 0.01
        tmpfilter.wavelen = tmpfilter.wavelen + shift
        tmpfilter.resampleBandpass()
        sys_edge[f].wavelen, sys_edge[f].sb = sys_edge[f].multiplyThroughputs(
            tmpfilter.wavelen, tmpfilter.sb)
    for f in filterlist:
        junk, effwavelen = sys_std[f].calcEffWavelen()
        junk, effwavelen_edge = sys_edge[f].calcEffWavelen()
        print f, effwavelen, effwavelen_edge, effwavelen / effwavelen_edge
    return sys_std, sys_edge
    def calcAllMags(self,
                    filt,
                    mjdTaiList,
                    rootSEDdir,
                    rootFILTERdir=None,
                    withErrors=True,
                    fiveSigmaLimitingMag=None):
        """ Calculate the magnitude of all objects in the movingObjectList. 

        Give the filter, the mjd (to find the ephemeris info) and the root directory of SEDS. Calculates magnitudes.
        Individual objects already know their SED and their expected V magnitude (part of ephemeris info). """
        # Set up data needed to calculate magnitudes for each moving object.
        # First find location of lsst filter throughput curves, if not specified.
        import os
        if rootFILTERdir == None:
            # (assumes throughputs is setup)
            # Just use the default directory of the throughputs as this is probably correct.
            rootFILTERdir = os.getenv("LSST_THROUGHPUTS_DEFAULT")
        # Now rootFILTERdir should be defined.
        if rootFILTERdir == None:
            raise Exception(
                "Ack: rootFILTERdir is undefined and it seems that 'throughputs' is not setup."
            )
        # Import Sed and Bandpass for calculating magnitudes. (assumes catalogs_measures is setup)
        import lsst.sims.catalogs.measures.photometry.Sed as Sed
        import lsst.sims.catalogs.measures.photometry.Bandpass as Bandpass
        # read in and set up filter files
        bandpass = {}
        filterlist = ('V', 'imsim', filt)
        for f in filterlist:
            if f == 'V':
                filename = os.path.join(rootSEDdir, 'harris_V.dat')
                # Instantiate and read the throughput file.
                bandpass[f] = Bandpass()
                bandpass[f].readThroughput(filename)
            elif f == 'imsim':
                filename = 'imsim'
                bandpass[f] = Bandpass()
                bandpass[f].imsimBandpass()
            else:
                filename = os.path.join(rootFILTERdir, 'total_' + f + '.dat')
                # Instantiate and read the throughput file.
                bandpass[f] = Bandpass()
                bandpass[f].readThroughput(filename)
        # Read in and set up sed files. Assumes asteroid SEDS end in .dat
        possiblesedtypes = os.listdir(rootSEDdir)
        sedtypes = []
        for p in possiblesedtypes:
            if p.endswith('.dat'):
                sedtypes.append(p)
        sed = {}
        sedmag = {}
        sedcol = {}
        for sedfile in sedtypes:
            # read sed files
            filename = os.path.join(rootSEDdir, sedfile)
            sed[sedfile] = Sed()
            sed[sedfile].readSED_flambda(filename)
            # set up magnitudes for color calculation.
            sedmag[sedfile] = {}
            sedcol[sedfile] = {}
            for f in filterlist:
                sedmag[sedfile][f] = sed[sedfile].calcMag(bandpass[f])
                sedcol[sedfile][f] = sedmag[sedfile][f] - sedmag[sedfile]['V']
        # set up mjdTaiListStr for access to ephemeris dictionaries
        movingobj = self._mObjects[0]
        mjdTaiListStr = []
        if isinstance(mjdTaiList, list) == False:
            mjdTaiList = [mjdTaiList]
        for mjdTai in mjdTaiList:
            mjdTaiListStr.append(movingobj.mjdTaiStr(mjdTai))
            # mjdTaiListStr will be the same for all objects.

        # now loop through each object and assign appropriate magnitudes values for this observation
        for movingobj in self._mObjects:
            # loop through mjdTaiList
            for mjdTaiStr in mjdTaiListStr:
                try:  # check ephemerides exist
                    movingobj.Ephemerides[mjdTaiStr]
                except AttributeError:
                    raise Exception("Do not have an ephemeride on date %s" %
                                    (mjdTaiStr))
                vmag = movingobj.Ephemerides[mjdTaiStr].getmagV()
                sedname = movingobj.getsedname()
                # Check if sedname in list of known seds.
                if sed.has_key(sedname) == False:
                    # HACK  - FIX when catalogs updated
                    sedname = 'S.dat'
                    #raise Exception("SED (%s) of moving object (#%d) not in movingObjectList's directory."
                    #                %(sedname, movingobj.getobjid()))
                # calculate magnitudes
                filtmag = vmag + sedcol[sedname][filt]
                imsimmag = vmag + sedcol[sedname]['imsim']
                # set filter magnitude in ephemeris
                movingobj.Ephemerides[mjdTaiStr].setmagFilter(filtmag)
                movingobj.Ephemerides[mjdTaiStr].setmagImsim(imsimmag)
                # Add SNR measurement if given 5-sigma limiting mag for exposure.
                if fiveSigmaLimitingMag != None:
                    flux_ratio = n.power(
                        10, 0.4 * (fiveSigmaLimitingMag - filtmag))
                    snr = 5 * (flux_ratio)
                    movingobj.Ephemerides[mjdTaiStr].setsnr(snr)
                # Calculate approx errors in ra/dec/mag from magnitude/m5.
                if withErrors:
                    if fiveSigmaLimitingMag == None:
                        raise Exception(
                            "To calculate errors, fiveSigmaLimitingMag is needed."
                        )
                    # calculate error in ra/dec
                    rgamma = 0.039
                    # average seeing is 0.7" (or 700 mas)
                    error_rand = n.sqrt((0.04 - rgamma) * flux_ratio +
                                        rgamma * flux_ratio * flux_ratio)
                    ast_error_rand = 700.0 * error_rand
                    ast_error_sys = 10.0
                    astrom_error = n.sqrt(ast_error_sys**2 + ast_error_rand**2)
                    # convert from mas to deg
                    astrom_error = astrom_error / 100.0 / 60.0 / 60.0
                    movingobj.Ephemerides[mjdTaiStr].setastErr(astrom_error)
                    mag_error_sys = 0.005
                    mag_error = n.sqrt(error_rand**2 + mag_error_sys**2)
                    movingobj.Ephemerides[mjdTaiStr].setmagErr(mag_error)
            # end of mjdTaiList loop
        return
Пример #37
0
    #    print sed, nsed
    return sed, color, nsed
    
def integrate(sed, bp):
    wavelen = sed.wavelen
    fnu = sed.fnu
    if sed.needResample(wavelen=wavelen, wavelen_match=bp.wavelen):
        wavelen, fnu = sed.resampleSED(wavelen, fnu, wavelen_match=bp.wavelen)
    return np.sum(fnu * bp.phi)

if __name__ == "__main__":
    import multiprocessing
    pool = multiprocessing.Pool(multiprocessing.cpu_count()-2)
    
    filtDir = os.environ["LSST_THROUGHPUTS_BASELINE"]
    gBand  = Bandpass()
    rBand  = Bandpass()
    gBand.readThroughput(os.path.join(filtDir, "total_g.dat"))
    rBand.readThroughput(os.path.join(filtDir, "total_r.dat"))
    gBand.sbTophi()
    rBand.sbTophi()
    
    catDir = os.environ["CAT_SHARE_DATA"]
    
    args = []
    for line in open(sys.argv[1]).readlines()[1:]:
        sed, mag, nsed = line.split()
        mag = float(mag) 
        if mag < 16 or mag > 25:
            continue
        args.append((line, gBand, rBand, catDir))
Пример #38
0
import numpy
import pylab
import lsst.sims.catalogs.measures.photometry.Sed as Sed
import lsst.sims.catalogs.measures.photometry.Bandpass as Bandpass
import os

# read filters
filterdir = os.getenv("LSST_THROUGHPUTS_DEFAULT")
filterlist = ('u', 'g', 'r', 'i', 'z', 'y')
lsst = {}
for f in filterlist:
    lsst[f] = Bandpass()
    lsst[f].readThroughput(os.path.join(filterdir, "total_" + f + ".dat"))

# read base quasar sed
qso = Sed()
qso.readSED_flambda("quasar.dat")

# set redshift range
redshifts = numpy.arange(0, 6, 0.2)

# set up quasar seds for this redshift range
qsoz = {}
for z in redshifts:
    qsoz[z] = Sed(qso.wavelen, flambda=qso.flambda)
    qsoz[z].redshiftSED(z, dimming=True)
    qsoz[z].flambdaTofnu()

# calculate colors
mags = {}
for f in filterlist:
Пример #39
0
    mStar  = Sed() 
    oStar.readSED_flambda(os.path.join(catDir, "data/starSED/kurucz", "kp01_9750.fits_g45_9830.gz"))
    gStar.readSED_flambda(os.path.join(catDir, "data/starSED/kurucz", "km20_6000.fits_g30_6020.gz"))
    mStar.readSED_flambda(os.path.join(catDir, "data/starSED/mlt", "m2.0Full.dat"))
    seds.append(oStar)
    seds.append(gStar)
    seds.append(mStar)

    for sed in seds:
        sed.flambdaTofnu() 

    filtDir = os.environ["LSST_THROUGHPUTS_BASELINE"]
    for airmass, zd in zip((15, 11), (50, 30)):
        for sidx, sed in enumerate(seds):
            for bpname in ("g", "r", "i"):
                bp = Bandpass(wavelen_max=1200) 
                components = common_components + [os.path.join(tp_dir, "baseline", "filter_%s.dat" % (bpname)), 
                                                  os.path.join(tp_dir, "atmos", "atmos_%d.dat" % (airmass))]
                #print components
                bp.readThroughputList(components)
                bp.sbTophi()

                wavelen           = sed.wavelen
                fnu               = sed.fnu
                wavelen, fnu      = sed.resampleSED(wavelen, fnu, wavelen_match=bp.wavelen)
                wavelenf, flambda = sed.fnuToflambda(wavelen, fnu)

                waveleng            = gStar.wavelen
                fnug                = gStar.fnu
                waveleng, fnug      = gStar.resampleSED(waveleng, fnug, wavelen_match=bp.wavelen)
                wavelenfg, flambdag = gStar.fnuToflambda(waveleng, fnug)