当前位置: 首页>>代码示例>>Python>>正文


Python Sed.setSED方法代码示例

本文整理汇总了Python中lsst.sims.photUtils.Sed.setSED方法的典型用法代码示例。如果您正苦于以下问题:Python Sed.setSED方法的具体用法?Python Sed.setSED怎么用?Python Sed.setSED使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lsst.sims.photUtils.Sed的用法示例。


在下文中一共展示了Sed.setSED方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: returnMags

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
    def returnMags(self, bandpass=None):
        """
        Convert the computed spectra to magnitudes using the supplied bandpasses,
        or, if self.mags=True, just return the mags in the LSST filters

        If mags=True when initialized, return mags returns an structured array with
        dtype names u,g,r,i,z,y.
        """
        if self.mags:
            if bandpass:
                warnings.warn('Ignoring set bandpasses and returning LSST ugrizy.')
            mags = -2.5*np.log10(self.spec)+np.log10(3631.)
            # Mask out high airmass
            mags[self.mask] *= np.nan
            # Convert to a structured array
            mags = np.core.records.fromarrays(mags.transpose(),
                                              names='u,g,r,i,z,y',
                                              formats='float,'*6)
        else:
            mags = np.zeros(self.npts, dtype=float)-666
            tempSed = Sed()
            isThrough = np.where(bandpass.sb > 0)
            minWave = bandpass.wavelen[isThrough].min()
            maxWave = bandpass.wavelen[isThrough].max()
            inBand = np.where((self.wave >= minWave) & (self.wave <= maxWave))
            for i, ra in enumerate(self.ra):
                # Check that there is flux in the band, otherwise calcMag fails
                if np.max(self.spec[i, inBand]) > 0:
                    tempSed.setSED(self.wave, flambda=self.spec[i, :])
                    mags[i] = tempSed.calcMag(bandpass)

            # Mask out high airmass
            mags[self.mask] *= np.nan
        return mags
开发者ID:jonathansick-shadow,项目名称:sims_skybrightness,代码行数:36,代码来源:skyModel.py

示例2: test_norm

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
    def test_norm(self):
        """
        Test that the special test case getImsimFluxNorm
        returns the same value as calling calcFluxNorm actually
        passing in the imsim Bandpass
        """

        bp = Bandpass()
        bp.imsimBandpass()

        rng = np.random.RandomState(1123)
        wavelen = np.arange(300.0, 2000.0, 0.17)

        for ix in range(10):
            flux = rng.random_sample(len(wavelen))*100.0
            sed = Sed()
            sed.setSED(wavelen=wavelen, flambda=flux)
            magmatch = rng.random_sample()*5.0 + 10.0

            control = sed.calcFluxNorm(magmatch, bp)
            test = getImsimFluxNorm(sed, magmatch)

            # something about how interpolation is done in Sed means
            # that the values don't come out exactly equal.  They come
            # out equal to 8 seignificant digits, though.
            self.assertEqual(control, test)
开发者ID:lsst,项目名称:sims_photUtils,代码行数:28,代码来源:testSedUtils.py

示例3: calcBasicColors

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
    def calcBasicColors(self, sedList, bandpassDict, makeCopy = False):

        """
        This will calculate a set of colors from a list of SED objects when there is no need to redshift
        the SEDs.

        @param [in] sedList is the set of spectral objects from the models SEDs provided by loaders in
        rgStar or rgGalaxy. NOTE: Since this uses photometryBase.manyMagCalc_list the SED objects
        will be changed.

        @param [in] bandpassDict is a BandpassDict class instance with the Bandpasses set to those
        for the magnitudes given for the catalog object

        @param [in] makeCopy indicates whether or not to operate on copies of the SED objects in sedList
        since this method will change the wavelength grid.

        @param [out] modelColors is the set of colors in the Bandpasses provided for the given sedList.
        """

        modelColors = []

        for specObj in sedList:
            if makeCopy==True:
                fileSED = Sed()
                fileSED.setSED(wavelen = specObj.wavelen, flambda = specObj.flambda)
                sEDMags = bandpassDict.magListForSed(fileSED)
            else:
                sEDMags = bandpassDict.magListForSed(specObj)
            colorInfo = []
            for filtNum in range(0, len(bandpassDict)-1):
                colorInfo.append(sEDMags[filtNum] - sEDMags[filtNum+1])
            modelColors.append(colorInfo)

        return modelColors
开发者ID:lsst,项目名称:sims_catUtils,代码行数:36,代码来源:matchUtils.py

示例4: calcMagNorm

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
    def calcMagNorm(self, objectMags, sedObj, bandpassDict, mag_error = None,
                    redshift = None, filtRange = None):

        """
        This will find the magNorm value that gives the closest match to the magnitudes of the object
        using the matched SED. Uses scipy.optimize.leastsq to find the values of fluxNorm that minimizes
        the function: ((flux_obs - (fluxNorm*flux_model))/flux_error)**2.

        @param [in] objectMags are the magnitude values for the object with extinction matching that of
        the SED object. In the normal case using the selectSED routines above it will be dereddened mags.

        @param [in] sedObj is an Sed class instance that is set with the wavelength and flux of the
        matched SED

        @param [in] bandpassDict is a BandpassDict class instance with the Bandpasses set to those
        for the magnitudes given for the catalog object

        @param [in] mag_error are provided error values for magnitudes in objectMags. If none provided
        then this defaults to 1.0. This should be an array of the same length as objectMags.

        @param [in] redshift is the redshift of the object if the magnitude is observed

        @param [in] filtRange is a selected range of filters specified by their indices in the bandpassList
        to match up against. Used when missing data in some magnitude bands.

        @param [out] bestMagNorm is the magnitude normalization for the given magnitudes and SED
        """

        import scipy.optimize as opt

        sedTest = Sed()
        sedTest.setSED(sedObj.wavelen, flambda = sedObj.flambda)
        if redshift is not None:
            sedTest.redshiftSED(redshift)
        imSimBand = Bandpass()
        imSimBand.imsimBandpass()
        zp = -2.5*np.log10(3631)  #Note using default AB zeropoint
        flux_obs = np.power(10,(objectMags + zp)/(-2.5))
        sedTest.resampleSED(wavelen_match=bandpassDict.wavelenMatch)
        sedTest.flambdaTofnu()
        flux_model = sedTest.manyFluxCalc(bandpassDict.phiArray, bandpassDict.wavelenStep)
        if filtRange is not None:
            flux_obs = flux_obs[filtRange]
            flux_model = flux_model[filtRange]
        if mag_error is None:
            flux_error = np.ones(len(flux_obs))
        else:
            flux_error = np.abs(flux_obs*(np.log(10)/(-2.5))*mag_error)
        bestFluxNorm = opt.leastsq(lambda x: ((flux_obs - (x*flux_model))/flux_error), 1.0)[0][0]
        sedTest.multiplyFluxNorm(bestFluxNorm)
        bestMagNorm = sedTest.calcMag(imSimBand)
        return bestMagNorm
开发者ID:lsst,项目名称:sims_catUtils,代码行数:54,代码来源:matchUtils.py

示例5: get_mags

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
 def get_mags(self,source, phase ):
     
     sed = Sed()
     print "==========================================="
     print phase
     print "==========================================="
     if phase > -20 and phase < 50 :
         sourceflux = source.flux(phase=phase, wave=self.rband.wavelen*10.)
         sed.setSED(wavelen=self.rband.wavelen, flambda=sourceflux/10.)
     else:
         sed.setSED(wavelen=self.rband.wavelen, flambda=flambda)
     #sed.redshiftSED(redshift=_z[i], dimming=True)
     return [sed.calcMag(bandpass=self.uband),
             sed.calcMag(bandpass=self.gband),
             sed.calcMag(bandpass=self.rband),
             sed.calcMag(bandpass=self.iband),
             sed.calcMag(bandpass=self.zband)]
开发者ID:rbiswas4,项目名称:SNIacatalogs,代码行数:19,代码来源:snIa.py

示例6: computeMags

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
    def computeMags(self, bandpass=None):
        """After the spectra have been computed, optionally convert to mags"""
        if self.mags:
            mags = -2.5*np.log10(self.spec)+np.log10(3631.)
        else:
            mags = np.zeros(self.npts, dtype=float)-666
            tempSed = Sed()
            isThrough = np.where(bandpass.sb > 0)
            minWave = bandpass.wavelen[isThrough].min()
            maxWave = bandpass.wavelen[isThrough].max()
            inBand = np.where( (self.wave >= minWave) & (self.wave <= maxWave))
            for i, ra in enumerate(self.ra):
                if np.max(self.spec[i,inBand]) > 0:
                    tempSed.setSED(self.wave, flambda=self.spec[i,:])
                    # Need to try/except because the spectra might be zero in the filter
                    # XXX-upgrade this to check if it's zero
                    mags[i] = tempSed.calcMag(bandpass)

        return mags
开发者ID:linan7788626,项目名称:sims_skybrightness,代码行数:21,代码来源:skyModel.py

示例7: returnMags

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
    def returnMags(self, bandpasses=None):
        """
        Convert the computed spectra to a magnitude using the supplied bandpass,
        or, if self.mags=True, return the mags in the LSST filters

        If mags=True when initialized, return mags returns an structured array with
        dtype names u,g,r,i,z,y.

        bandpasses: optional dictionary with bandpass name keys and bandpass object values.

        """
        if self.azs is None:
            raise ValueError('No coordinates set. Use setRaDecMjd, setRaDecAltAzMjd, or setParams methods before calling returnMags.')

        if self.mags:
            if bandpasses:
                warnings.warn('Ignoring set bandpasses and returning LSST ugrizy.')
            mags = -2.5*np.log10(self.spec)+np.log10(3631.)
            # Mask out high airmass
            mags[self.mask] *= np.nan
            mags = mags.swapaxes(0, 1)
            magsBack = {}
            for i, f in enumerate(self.filterNames):
                magsBack[f] = mags[i]
        else:
            magsBack = {}
            for key in bandpasses:
                mags = np.zeros(self.npts, dtype=float)-666
                tempSed = Sed()
                isThrough = np.where(bandpasses[key].sb > 0)
                minWave = bandpasses[key].wavelen[isThrough].min()
                maxWave = bandpasses[key].wavelen[isThrough].max()
                inBand = np.where((self.wave >= minWave) & (self.wave <= maxWave))
                for i, ra in enumerate(self.ra):
                    # Check that there is flux in the band, otherwise calcMag fails
                    if np.max(self.spec[i, inBand]) > 0:
                        tempSed.setSED(self.wave, flambda=self.spec[i, :])
                        mags[i] = tempSed.calcMag(bandpasses[key])
                # Mask out high airmass
                mags[self.mask] *= np.nan
                magsBack[key] = mags
        return magsBack
开发者ID:lsst,项目名称:sims_skybrightness,代码行数:44,代码来源:skyModel.py

示例8: applyIGM

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
    def applyIGM(self, redshift, sedobj):

        """
        Apply IGM extinction to already redshifted sed with redshift
        between zMin and zMax defined by range of lookup tables

        @param [in] redshift is the redshift of the incoming SED object

        @param [in] sedobj is the SED object to which IGM extinction will be applied. This object
        will be modified as a result of this.
        """

        if self.IGMisInitialized == False:
            self.initializeIGM()

        #First make sure redshift is in range of lookup tables.
        if (redshift < self.zMin) or (redshift > self.zMax):
            warnings.warn(str("IGM Lookup tables only applicable for " + str(self.zMin) + " < z < " + str(self.zMax) + ". No action taken"))
            return

        #Now read in closest two lookup tables for given redshift
        lowerSed = Sed()
        upperSed = Sed()
        for lower, upper in zip(self.zRange[:-1], self.zRange[1:]):
            if lower <= redshift <= upper:
                lowerSed.setSED(self.meanLookups['%.1f' % lower][:,0],
                                flambda = self.meanLookups['%.1f' % lower][:,1])
                upperSed.setSED(self.meanLookups['%.1f' % upper][:,0],
                                flambda = self.meanLookups['%.1f' % lower][:,1])
                break

        #Redshift lookup tables to redshift of source, i.e. if source redshift is 1.78 shift lookup
        #table for 1.7 and lookup table for 1.8 to up and down to 1.78, respectively
        zLowerShift = ((1.0 + redshift)/(1.0 + lower)) - 1.0
        zUpperShift = ((1.0 + redshift)/(1.0 + upper)) - 1.0
        lowerSed.redshiftSED(zLowerShift)
        upperSed.redshiftSED(zUpperShift)

        #Resample lower and upper transmission data onto same wavelength grid.
        minWavelen = 300. #All lookup tables are usable above 300nm
        maxWavelen = np.amin([lowerSed.wavelen[-1], upperSed.wavelen[-1]]) - 0.01
        lowerSed.resampleSED(wavelen_min = minWavelen, wavelen_max = maxWavelen, wavelen_step = 0.01)
        upperSed.resampleSED(wavelen_match = lowerSed.wavelen)

        #Now insert this into a transmission array of 1.0 beyond the limits of current application
        #So that we can get an sed back that extends to the longest wavelengths of the incoming sed
        finalWavelen = np.arange(300., sedobj.wavelen[-1]+0.01, 0.01)
        finalFlambdaExtended = np.ones(len(finalWavelen))

        #Weighted Average of Transmission from each lookup table to get final transmission
        #table at desired redshift
        dzGrid = self.zDelta #Step in redshift between transmission lookup table files
        finalSed = Sed()
        finalFlambda = (lowerSed.flambda*(1.0 - ((redshift - lower)/dzGrid)) +
                        upperSed.flambda*(1.0 - ((upper - redshift)/dzGrid)))
        finalFlambdaExtended[0:len(finalFlambda)] = finalFlambda
        finalSed.setSED(wavelen = finalWavelen, flambda = finalFlambdaExtended)

        #Resample incoming sed to new grid so that we don't get warnings from multiplySED
        #about matching wavelength grids
        sedobj.resampleSED(wavelen_match=finalSed.wavelen)

        #Now multiply transmission curve by input SED to get final result and make it the new flambda
        #data in the original sed which also is now on a new grid starting at 300 nm
        test = sedobj.multiplySED(finalSed)
        sedobj.flambda = test.flambda
开发者ID:lsst,项目名称:sims_catUtils,代码行数:68,代码来源:applyIGM.py

示例9: packageLowerAtm

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
def packageLowerAtm():

    dataDir = getPackageDir('SIMS_SKYBRIGHTNESS_DATA')
    outDir = os.path.join(dataDir, 'ESO_Spectra/LowerAtm')

    # Read in all the spectra from ESO call and package into a single npz file

    files = glob.glob('LowerAtm/skytable*.fits')

    temp = pyfits.open(files[0])
    wave = temp[1].data['lam'].copy()*1e3

    airmasses = []
    nightTimes = []
    specs = []

    for i,filename in enumerate(files):
        fits = pyfits.open(filename)
        if np.max(fits[1].data['flux']) > 0:
            specs.append(fits[1].data['flux'].copy())
            header = fits[0].header['comment']
            for card in header:
                if 'SKYMODEL.TARGET.AIRMASS' in card:
                    airmasses.append(float(card.split('=')[-1]))
                elif 'SKYMODEL.TIME' in card:
                    nightTimes.append(float(card.split('=')[-1]))

    airmasses = np.array(airmasses)
    nigtTimes = np.array(nightTimes)

    nrec = airmasses.size
    nwave = wave.size

    dtype = [('airmass', 'float'),
             ('nightTimes', 'float'),
             ('spectra', 'float', (nwave)), ('mags', 'float', (6))]
    Spectra = np.zeros(nrec, dtype=dtype)
    Spectra['airmass'] = airmasses
    Spectra['nightTimes'] = nightTimes
    Spectra['spectra'] = specs

    hPlank = 6.626068e-27 # erg s
    cLight = 2.99792458e10 # cm/s

    # Convert spectra from ph/s/m2/micron/arcsec2 to erg/s/cm2/nm/arcsec2
    Spectra['spectra'] = Spectra['spectra']/(100.**2)*hPlank*cLight/(wave*1e-7)/1e3

    # Sort things since this might be helpful later
    Spectra.sort(order=['airmass','nightTimes'])

    # Load LSST filters
    throughPath = os.path.join(getPackageDir('throughputs'),'baseline')
    keys = ['u','g','r','i','z','y']
    nfilt = len(keys)
    filters = {}
    for filtername in keys:
        bp = np.loadtxt(os.path.join(throughPath, 'filter_'+filtername+'.dat'),
                        dtype=zip(['wave','trans'],[float]*2 ))
        tempB = Bandpass()
        tempB.setBandpass(bp['wave'],bp['trans'])
        filters[filtername] = tempB

    filterWave = np.array([filters[f].calcEffWavelen()[0] for f in keys ])

    for i,spectrum in enumerate(Spectra['spectra']):
        tempSed = Sed()
        tempSed.setSED(wave,flambda=spectrum)
        for j,filtName in enumerate(keys):
            try:
                Spectra['mags'][i][j] = tempSed.calcMag(filters[filtName])
            except:
                pass

    np.savez(os.path.join(outDir,'Spectra.npz'), wave = wave, spec=Spectra, filterWave=filterWave)
开发者ID:lsst-sims,项目名称:sims_skybrightness_fits,代码行数:76,代码来源:package_spec.py

示例10: packageZodiacal

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
def packageZodiacal():

    dataDir = getPackageDir('SIMS_SKYBRIGHTNESS_DATA')
    outDir = os.path.join(dataDir, 'ESO_Spectra/Zodiacal')

    nside = 4

    # Read in all the spectra from ESO call and package into a single npz file

    files = glob.glob('Zodiacal/skytable*.fits')

    temp = pyfits.open(files[0])
    wave = temp[1].data['lam'].copy()*1e3

    airmasses = []
    eclLon = []
    eclLat = []
    specs = []

    for i,filename in enumerate(files):
        fits = pyfits.open(filename)
        if np.max(fits[1].data['flux']) > 0:
            specs.append(fits[1].data['flux'].copy())
            header = fits[0].header['comment']
            for card in header:
                if 'SKYMODEL.TARGET.AIRMASS' in card:
                    airmasses.append(float(card.split('=')[-1]))
                elif 'SKYMODEL.ECL.LON' in card:
                    eclLon.append(float(card.split('=')[-1]))
                elif 'SKYMODEL.ECL.LAT' in card:
                    eclLat.append(float(card.split('=')[-1]))


    airmasses = np.array(airmasses)
    eclLon = np.array(eclLon)
    eclLat = np.array(eclLat)

    wrapA = np.where(eclLon < 0.)
    eclLon[wrapA] = eclLon[wrapA]+360.

    uAM = np.unique(airmasses)
    nAM = uAM.size
    nwave = wave.size

    dtype = [('airmass', 'float'),
             ('hpid', 'int' ),
             ('spectra', 'float', (nwave)), ('mags', 'float', (6))]
    npix = hp.nside2npix(nside)
    Spectra = np.zeros(nAM*npix, dtype=dtype)
    for i,am in enumerate(uAM):
        Spectra['airmass'][i*npix:i*npix+npix] = am
        Spectra['hpid'][i*npix:i*npix+npix] = np.arange(npix)


    for am, lat, lon, spec in zip(airmasses,eclLat, eclLon, specs):
        hpid = hp.ang2pix(nside, np.radians(lat+90.), np.radians(lon) )
        good = np.where( (Spectra['airmass'] == am) & (Spectra['hpid'] == hpid))
        Spectra['spectra'][good] = spec.copy()

    hPlank = 6.626068e-27 # erg s
    cLight = 2.99792458e10 # cm/s

    # Convert spectra from ph/s/m2/micron/arcsec2 to erg/s/cm2/nm/arcsec2
    Spectra['spectra'] = Spectra['spectra']/(100.**2)*hPlank*cLight/(wave*1e-7)/1e3

    # Sort things since this might be helpful later
    Spectra.sort(order=['airmass', 'hpid'])

    # Load LSST filters
    throughPath = os.path.join(getPackageDir('throughputs'),'baseline')
    keys = ['u','g','r','i','z','y']
    nfilt = len(keys)
    filters = {}
    for filtername in keys:
        bp = np.loadtxt(os.path.join(throughPath, 'filter_'+filtername+'.dat'),
                        dtype=zip(['wave','trans'],[float]*2 ))
        tempB = Bandpass()
        tempB.setBandpass(bp['wave'],bp['trans'])
        filters[filtername] = tempB

    filterWave = np.array([filters[f].calcEffWavelen()[0] for f in keys ])

    for i,spectrum in enumerate(Spectra['spectra']):
        tempSed = Sed()
        tempSed.setSED(wave,flambda=spectrum)
        for j,filtName in enumerate(keys):
            try:
                Spectra['mags'][i][j] = tempSed.calcMag(filters[filtName])
            except:
                pass


    #span this over multiple files to store in github
    nbreak = 3
    nrec = np.size(Spectra)

    for i in np.arange(nbreak):
        np.savez(os.path.join(outDir,'zodiacalSpectra_'+str(i)+'.npz'), wave = wave,
                 spec=Spectra[i*nrec/nbreak:(i+1)*nrec/nbreak], filterWave=filterWave)
开发者ID:lsst-sims,项目名称:sims_skybrightness_fits,代码行数:101,代码来源:package_spec.py

示例11: packageMoon

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]

#.........这里部分代码省略.........
                moonSpec.append(fits[1].data['flux'].copy())
                header = fits[0].header['comment']
                for card in header:
                    if 'SKYMODEL.MOON.SUN.SEP' in card:
                        moonSunSep.append(float(card.split('=')[-1]))
                    elif 'SKYMODEL.TARGET.AIRMASS' in card:
                        #moonAM.append( 1./np.cos(np.radians(90.-float(card.split('=')[-1]))) )
                        moonAM.append( float(card.split('=')[-1]) )
                    elif 'SKYMODEL.MOON.TARGET.SEP' in card:
                        moonTargetSep.append(float(card.split('=')[-1]))
                    elif 'SKYMODEL.MOON.ALT' in card:
                        moonAlt.append(float(card.split('=')[-1]))
        except:
            print filename, ' Failed'

    import healpy as hp
    from lsst.sims.utils import haversine

    nside = 4
    lat, az = hp.pix2ang(nside, np.arange(hp.nside2npix(nside)))
    alt = np.pi/2.-lat
    airmass = 1./np.cos(np.pi/2.-alt)

    # Only need low airmass and then 1/2 to sky
    good = np.where( (az >= 0) & (az <= np.pi) & (airmass <=2.6) & (airmass >= 1.) )
    airmass = airmass[good]
    alt=alt[good]
    az = az[good]

    moonAM = np.array(moonAM)
    moonAlt = np.array(moonAlt)
    moonSunSep = np.array(moonSunSep)
    moonTargetSep = np.array(moonTargetSep)
    moonAzDiff = moonTargetSep*0
    targetAlt = np.pi/2.-np.arccos(1./moonAM)
    # Compute the azimuth difference given the moon-target-seperation
    # Let's just do a stupid loop:
    for i in np.arange(targetAlt.size):
        possibleDistances = haversine(0., np.radians(moonAlt[i]),  az, az*0+targetAlt[i])
        diff = np.abs(possibleDistances - np.radians(moonTargetSep[i]))
        good = np.where(diff == diff.min())
        moonAzDiff[i] = az[good][0]
        # ok, now I have an alt and az, I can convert that back to a healpix id.

        hpid.append(hp.ang2pix(nside, np.pi/2.-targetAlt[i], moonAzDiff[i]))

    nrec = moonAM.size
    nwave = moonWave.size

    dtype = [('hpid', 'int'),
             ('moonAltitude', 'float'),
             ('moonSunSep', 'float'),
             ('spectra', 'float', (nwave)), ('mags', 'float', (6))]
    moonSpectra = np.zeros(nrec, dtype=dtype)
    moonSpectra['hpid'] = hpid
    moonSpectra['moonAltitude'] = moonAlt
    moonSpectra['moonSunSep'] = moonSunSep
    moonSpectra['spectra'] = moonSpec

    hPlank = 6.626068e-27  # erg s
    cLight = 2.99792458e10 # cm/s

    # Convert spectra from ph/s/m2/micron/arcsec2 to erg/s/cm2/nm/arcsec2
    moonSpectra['spectra'] = moonSpectra['spectra']/(100.**2)*hPlank*cLight/(moonWave*1e-7)/1e3

    # Sort things since this might be helpful later
    moonSpectra.sort(order=['moonSunSep','moonAltitude', 'hpid'])

    # Crop off the incomplete ones

    good =np.where((moonSpectra['moonAltitude'] >= 0) & (moonSpectra['moonAltitude'] < 89.) )
    moonSpectra = moonSpectra[good]

    # Load LSST filters
    throughPath = os.path.join(getPackageDir('throughputs'),'baseline')
    keys = ['u','g','r','i','z','y']
    nfilt = len(keys)
    filters = {}
    for filtername in keys:
        bp = np.loadtxt(os.path.join(throughPath, 'filter_'+filtername+'.dat'),
                        dtype=zip(['wave','trans'],[float]*2 ))
        tempB = Bandpass()
        tempB.setBandpass(bp['wave'],bp['trans'])
        filters[filtername] = tempB

    filterWave = np.array([filters[f].calcEffWavelen()[0] for f in keys ])

    for i,spectrum in enumerate(moonSpectra['spectra']):
        tempSed = Sed()
        tempSed.setSED(moonWave,flambda=spectrum)
        for j,filtName in enumerate(keys):
            try:
                moonSpectra['mags'][i][j] = tempSed.calcMag(filters[filtName])
            except:
                pass

    nbreak=5
    nrec = np.size(moonSpectra)
    for i in np.arange(nbreak):
        np.savez(os.path.join(outDir,'moonSpectra_'+str(i)+'.npz'), wave = moonWave, spec=moonSpectra[i*nrec/nbreak:(i+1)*nrec/nbreak], filterWave=filterWave)
开发者ID:lsst-sims,项目名称:sims_skybrightness_fits,代码行数:104,代码来源:package_spec.py

示例12: len

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
throughPath = os.getenv('LSST_THROUGHPUTS_BASELINE')
keys = ['u', 'g', 'r', 'i', 'z', 'y']
nfilt = len(keys)
filters = {}
for filtername in keys:
    bp = np.loadtxt(os.path.join(throughPath, 'filter_'+filtername+'.dat'),
                    dtype=list(zip(['wave', 'trans'], [float]*2)))
    tempB = Bandpass()
    tempB.setBandpass(bp['wave'], bp['trans'])
    filters[filtername] = tempB

filterWave = np.array([filters[f].calcEffWavelen()[0] for f in keys])

for i, spectrum in enumerate(moonSpectra['spectra']):
    tempSed = Sed()
    tempSed.setSED(moonWave, flambda=spectrum)
    for j, filtName in enumerate(keys):
        try:
            moonSpectra['mags'][i][j] = tempSed.calcMag(filters[filtName])
        except:
            pass


nbreak = 5
nrec = np.size(moonSpectra)

for i in np.arange(nbreak):
    np.savez(os.path.join(outDir, 'moonSpectra_'+str(i)+'.npz'), wave=moonWave,
             spec=moonSpectra[i*nrec/nbreak:(i+1)*nrec/nbreak], filterWave=filterWave)

开发者ID:lsst,项目名称:sims_skybrightness,代码行数:31,代码来源:package_spec.py

示例13: Sed

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]
import numpy as np
import lsst.sims.photUtils.Sed as Sed
import os

dataDir = os.getenv('SIMS_SKYBRIGHTNESS_DATA_DIR')

data = np.genfromtxt(os.path.join(dataDir, 'solarSpec/solarSpec.dat'), dtype=zip(['microns','Irr'],[float]*2))
#data['Irr'] = data['Irr']*1 #convert W/m2/micron to erg/s/cm2/nm (HA, it's the same!)

sun = Sed()
sun.setSED(data['microns']*1e3, flambda=data['Irr'])

# Match the wavelenth spacing and range to the ESO spectra
airglowSpec = np.load(os.path.join(dataDir, 'ESO_Spectra/Airglow/airglowSpectra.npz'))
sun.resampleSED(wavelen_match=airglowSpec['wave'])

np.savez(os.path.join(dataDir,'solarSpec/solarSpec.npz'), wave=sun.wavelen, spec=sun.flambda)
开发者ID:jonathansick-shadow,项目名称:sims_skybrightness,代码行数:19,代码来源:package.py

示例14: matchToObserved

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import setSED [as 别名]

#.........这里部分代码省略.........
        @param [out] magNormMatches are the magnitude normalizations for the given magnitudes and
        matched SED.

        @param [out] matchErrors contains the Mean Squared Error between the colors of each object and 
        the colors of the matched SED.
        """

        #Set up photometry to calculate model Mags
        if bandpassDict is None:
            galPhot = BandpassDict.loadTotalBandpassesFromFiles(['u','g','r','i','z'],
                                            bandpassDir = os.path.join(lsst.utils.getPackageDir('throughputs'),'sdss'),
                                            bandpassRoot = 'sdss_')
        else:
            galPhot = bandpassDict

        #Calculate ebv from ra, dec coordinates if needed
        if reddening == True:
            #Check that catRA and catDec are included
            if catRA is None or catDec is None:
                raise RuntimeError("Reddening is True, but catRA and catDec are not included.")
            calcEBV = ebv()
            raDec = np.array((catRA,catDec))
            #If only matching one object need to reshape for calculateEbv
            if len(raDec.shape) == 1:
                raDec = raDec.reshape((2,1))
            ebvVals = calcEBV.calculateEbv(equatorialCoordinates = raDec)
            objMags = self.deReddenMags(ebvVals, catMags, extCoeffs)
        else:
            objMags = catMags

        minRedshift = np.round(np.min(catRedshifts), dzAcc)
        maxRedshift = np.round(np.max(catRedshifts), dzAcc)
        dz = np.power(10., (-1*dzAcc))

        redshiftRange = np.round(np.arange(minRedshift - dz, maxRedshift + (2*dz), dz), dzAcc)
        numRedshifted = 0
        sedMatches = [None] * len(catRedshifts)
        magNormMatches = [None] * len(catRedshifts)
        matchErrors = [None] * len(catRedshifts)
        redshiftIndex = np.argsort(catRedshifts)

        numOn = 0
        notMatched = 0
        lastRedshift = -100
        print('Starting Matching. Arranged by redshift value.')
        for redshift in redshiftRange:

            if numRedshifted % 10 == 0:
                print('%i out of %i redshifts gone through' % (numRedshifted, len(redshiftRange)))
            numRedshifted += 1

            colorSet = []
            for galSpec in sedList:
                sedColors = []
                fileSED = Sed()
                fileSED.setSED(wavelen = galSpec.wavelen, flambda = galSpec.flambda)
                fileSED.redshiftSED(redshift)
                sedColors = self.calcBasicColors([fileSED], galPhot, makeCopy = True)
                colorSet.append(sedColors)
            colorSet = np.transpose(colorSet)
            for currentIndex in redshiftIndex[numOn:]:
                matchMags = objMags[currentIndex]
                if lastRedshift < np.round(catRedshifts[currentIndex],dzAcc) <= redshift:
                    colorRange = np.arange(0, len(galPhot)-1)
                    matchColors = []
                    for colorNum in colorRange:
                        matchColors.append(matchMags[colorNum] - matchMags[colorNum+1])
                    #This is done to handle objects with incomplete magnitude data
                    filtNums = np.arange(0, len(galPhot))
                    if np.isnan(np.amin(matchColors))==True:
                        colorRange = np.where(np.isnan(matchColors)==False)[0]
                        filtNums = np.unique([colorRange, colorRange+1]) #Pick right filters in calcMagNorm
                    if len(colorRange) == 0:
                        print('Could not match object #%i. No magnitudes for two adjacent bandpasses.' \
                              % (currentIndex))
                        notMatched += 1
                        #Don't need to assign 'None' here in result array, b/c 'None' is default value
                    else:
                        distanceArray = [np.zeros(len(sedList))]
                        for colorNum in colorRange:
                            distanceArray += np.power((colorSet[colorNum] - matchColors[colorNum]),2)
                        matchedSEDNum = np.nanargmin(distanceArray)
                        sedMatches[currentIndex] = sedList[matchedSEDNum].name
                        magNormVal = self.calcMagNorm(np.array(matchMags), sedList[matchedSEDNum], 
                                                      galPhot, mag_error = mag_error,
                                                      redshift = catRedshifts[currentIndex],
                                                      filtRange = filtNums)
                        magNormMatches[currentIndex] = magNormVal
                        matchErrors[currentIndex] = (distanceArray[0,matchedSEDNum]/len(colorRange))
                    numOn += 1
                else:
                    break
            lastRedshift = redshift

        print('Done Matching. Matched %i of %i catalog objects to SEDs' % (len(catMags)-notMatched,
                                                                           len(catMags)))
        if notMatched > 0:
            print('%i objects did not get matched.' % (notMatched))

        return sedMatches, magNormMatches, matchErrors
开发者ID:lsst,项目名称:sims_catUtils,代码行数:104,代码来源:selectGalaxySED.py


注:本文中的lsst.sims.photUtils.Sed.setSED方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。