本文整理汇总了Python中lsst.sims.photUtils.Sed.Sed.readSED_flambda方法的典型用法代码示例。如果您正苦于以下问题:Python Sed.readSED_flambda方法的具体用法?Python Sed.readSED_flambda怎么用?Python Sed.readSED_flambda使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lsst.sims.photUtils.Sed.Sed
的用法示例。
在下文中一共展示了Sed.readSED_flambda方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testApplyIGM
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testApplyIGM(self):
"""Test application of IGM from Lookup Tables to SED objects"""
#Test that a warning comes up if input redshift is out of range and that no changes occurs to SED
testSed = Sed()
testSed.readSED_flambda(os.environ['SIMS_SED_LIBRARY_DIR'] + '/galaxySED/Inst.80E09.25Z.spec.gz')
testFlambda = []
for fVal in testSed.flambda:
testFlambda.append(fVal)
testIGM = ApplyIGM()
testIGM.initializeIGM()
with warnings.catch_warnings(record=True) as wa:
testIGM.applyIGM(1.1, testSed)
self.assertEqual(len(wa), 1)
self.assertTrue('IGM Lookup tables' in str(wa[-1].message))
np.testing.assert_equal(testFlambda, testSed.flambda)
#Test that lookup table is read in correctly
testTable15 = np.genfromtxt(str(os.environ['SIMS_SED_LIBRARY_DIR'] + '/igm/' +
'MeanLookupTable_zSource1.5.tbl'))
np.testing.assert_equal(testTable15, testIGM.meanLookups['1.5'])
#Test output by making sure that an incoming sed with flambda = 1.0 everywhere will return the
#transmission values of the lookup table as its flambda output
testSed.setSED(testSed.wavelen, flambda = np.ones(len(testSed.wavelen)))
testIGM.applyIGM(1.5, testSed)
testTable15Above300 = testTable15[np.where(testTable15[:,0] >= 300.0)]
testSed.resampleSED(wavelen_match = testTable15Above300[:,0])
np.testing.assert_allclose(testTable15Above300[:,1], testSed.flambda, 1e-4)
示例2: testAlternateBandpassesStars
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testAlternateBandpassesStars(self):
"""
This will test our ability to do photometry using non-LSST bandpasses.
It will first calculate the magnitudes using the getters in cartoonPhotometryStars.
It will then load the alternate bandpass files 'by hand' and re-calculate the magnitudes
and make sure that the magnitude values agree. This is guarding against the possibility
that some default value did not change and the code actually ended up loading the
LSST bandpasses.
"""
obs_metadata_pointed = ObservationMetaData(
mjd=2013.23, boundType="circle", unrefractedRA=200.0, unrefractedDec=-30.0, boundLength=1.0
)
bandpassDir = os.path.join(lsst.utils.getPackageDir("sims_photUtils"), "tests", "cartoonSedTestData")
cartoon_dict = BandpassDict.loadTotalBandpassesFromFiles(
["u", "g", "r", "i", "z"], bandpassDir=bandpassDir, bandpassRoot="test_bandpass_"
)
testBandPasses = {}
keys = ["u", "g", "r", "i", "z"]
bplist = []
for kk in keys:
testBandPasses[kk] = Bandpass()
testBandPasses[kk].readThroughput(os.path.join(bandpassDir, "test_bandpass_%s.dat" % kk))
bplist.append(testBandPasses[kk])
sedObj = Sed()
phiArray, waveLenStep = sedObj.setupPhiArray(bplist)
sedFileName = os.path.join(lsst.utils.getPackageDir("sims_sed_library"), "starSED", "kurucz")
sedFileName = os.path.join(sedFileName, "km20_5750.fits_g40_5790.gz")
ss = Sed()
ss.readSED_flambda(sedFileName)
controlBandpass = Bandpass()
controlBandpass.imsimBandpass()
ff = ss.calcFluxNorm(22.0, controlBandpass)
ss.multiplyFluxNorm(ff)
testMags = cartoon_dict.magListForSed(ss)
ss.resampleSED(wavelen_match=bplist[0].wavelen)
ss.flambdaTofnu()
mags = -2.5 * numpy.log10(numpy.sum(phiArray * ss.fnu, axis=1) * waveLenStep) - ss.zp
self.assertTrue(len(mags) == len(testMags))
self.assertTrue(len(mags) > 0)
for j in range(len(mags)):
self.assertAlmostEqual(mags[j], testMags[j], 10)
示例3: loadKuruczSEDs
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def loadKuruczSEDs(self, subset = None):
"""
By default will load all seds in kurucz directory. The user can also define a subset of
what's in the directory and load only those SEDs instead. Will skip over extraneous
files in sed folder.
@param [in] subset is the list of the subset of files wanted if one doesn't want all files
in the kurucz directory.
@param [out] sedList is the set of model SED spectra objects to be passed onto the matching
routines.
"""
files = []
if subset is None:
for fileName in os.listdir(self.kuruczDir):
files.append(fileName)
else:
for fileName in subset:
files.append(fileName)
numFiles = len(files)
numOn = 0
sedList = []
for fileName in files:
if numOn % 100 == 0:
print 'Loading %i of %i: Kurucz SEDs' % (numOn, numFiles)
try:
spec = Sed()
spec.readSED_flambda(str(self.kuruczDir + '/' + fileName))
logZTimesTen, temp, gravity, fineTemp = [x.split(".")[0] for x in fileName.split("_")]
if logZTimesTen[1] == 'm':
spec.logZ = -1.0 * float(logZTimesTen[2:]) * 0.1
else:
spec.logZ = float(logZTimesTen[2:]) * 0.1
spec.logg = float(gravity[1:]) * 0.1
spec.temp = float(fineTemp)
spec.name = fileName
except:
continue
sedList.append(spec)
numOn += 1
return sedList
示例4: loadwdSEDs
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def loadwdSEDs(self, subset = None):
"""
By default will load all seds in wd directory. The user can also define a subset of
what's in the directory and load only those SEDs instead. Will skip over extraneous
files in sed folder.
@param [in] subset is the list of the subset of files wanted if one doesn't want all files
in the kurucz directory.
@param [out] sedListH is the set of model SED spectra objects for Hydrogen WDs to be passed onto
the matching routines.
@param [out] sedListHE is the set of model SED spectra objects for Helium WDs to be passed onto
the matching routines.
"""
files = []
if subset is None:
for fileName in os.listdir(self.wdDir):
files.append(fileName)
else:
for fileName in subset:
files.append(fileName)
numFiles = len(files)
numOn = 0
sedListH = []
sedListHE = []
for fileName in files:
if numOn % 100 == 0:
print 'Loading %i of %i: WD SEDs' % (numOn, numFiles)
try:
spec = Sed()
spec.readSED_flambda(str(self.wdDir + '/' + fileName))
spec.name = fileName
if fileName.split("_")[1] == 'He':
sedListHE.append(spec)
else:
sedListH.append(spec)
except:
continue
numOn += 1
return sedListH, sedListHE
示例5: loadBC03
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def loadBC03(self, subset = None):
"""
This loads the Bruzual and Charlot SEDs that are currently in the SIMS_SED_LIBRARY.
If the user wants to use different SEDs another loading method can be created and used in place
of this.
@param [in] subset is the list of the subset of files in the galDir that the user
can specify if using all the SEDs in the directory is not desired.
@param [out] sedList is the set of model SED spectra objects to be passed onto the matching routines.
"""
files = []
if subset is None:
for fileName in os.listdir(self.galDir):
files.append(fileName)
else:
for fileName in subset:
files.append(fileName)
numFiles = len(files)
numOn = 0
sedList = []
for fileName in files:
if numOn % 100 == 0:
print 'Loading %i of %i: BC Galaxy SEDs' % (numOn, numFiles)
try:
spec = Sed()
spec.readSED_flambda(str(self.galDir + '/' + fileName))
spec.name = fileName
fileNameAsList = fileName.split('.')
spec.type = fileNameAsList[0]
spec.age = float(fileNameAsList[1])
metallicity = fileNameAsList[2].split('Z')[0]
#Final form is z/zSun
spec.metallicity = float(metallicity) * (10 ** ((len(metallicity)-1)*-1))
except:
continue
sedList.append(spec)
numOn += 1
return sedList
示例6: testSignalToNoise
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testSignalToNoise(self):
"""
Test that calcSNR_m5 and calcSNR_sed give similar results
"""
defaults = LSSTdefaults()
photParams = PhotometricParameters()
totalDict, hardwareDict = BandpassDict.loadBandpassesFromFiles()
skySED = Sed()
skySED.readSED_flambda(os.path.join(lsst.utils.getPackageDir("throughputs"), "baseline", "darksky.dat"))
m5 = []
for filt in totalDict:
m5.append(calcM5(skySED, totalDict[filt], hardwareDict[filt], photParams, seeing=defaults.seeing(filt)))
sedDir = lsst.utils.getPackageDir("sims_sed_library")
sedDir = os.path.join(sedDir, "starSED", "kurucz")
fileNameList = os.listdir(sedDir)
numpy.random.seed(42)
offset = numpy.random.random_sample(len(fileNameList)) * 2.0
for ix, name in enumerate(fileNameList):
if ix > 100:
break
spectrum = Sed()
spectrum.readSED_flambda(os.path.join(sedDir, name))
ff = spectrum.calcFluxNorm(m5[2] - offset[ix], totalDict.values()[2])
spectrum.multiplyFluxNorm(ff)
magList = []
controlList = []
magList = []
for filt in totalDict:
controlList.append(
calcSNR_sed(
spectrum, totalDict[filt], skySED, hardwareDict[filt], photParams, defaults.seeing(filt)
)
)
magList.append(spectrum.calcMag(totalDict[filt]))
testList, gammaList = calcSNR_m5(
numpy.array(magList), numpy.array(totalDict.values()), numpy.array(m5), photParams
)
for tt, cc in zip(controlList, testList):
msg = "%e != %e " % (tt, cc)
self.assertTrue(numpy.abs(tt / cc - 1.0) < 0.001, msg=msg)
示例7: __init__
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def __init__(self, catsim_cat, om10_cat='twinkles_lenses_v2.fits',
density_param=1.):
"""
Parameters
----------
catsim_cat: catsim catalog
The results array from an instance catalog.
om10_cat: optional, defaults to 'twinkles_tdc_rung4.fits
fits file with OM10 catalog
density_param: `np.float`, optioanl, defaults to 1.0
the fraction of eligible agn objects that become lensed and should
be between 0.0 and 1.0.
Returns
-------
updated_catalog:
A new results array with lens systems added.
"""
twinklesDir = getPackageDir('Twinkles')
om10_cat = os.path.join(twinklesDir, 'data', om10_cat)
self.catalog = catsim_cat
# ****** THIS ASSUMES THAT THE ENVIRONMENT VARIABLE OM10_DIR IS SET *******
lensdb = om10.DB(catalog=om10_cat)
self.lenscat = lensdb.lenses.copy()
self.density_param = density_param
self.bandpassDict = BandpassDict.loadTotalBandpassesFromFiles(bandpassNames=['i'])
specFileStart = 'Burst'
for key, val in sorted(iteritems(SpecMap.subdir_map)):
if re.match(key, specFileStart):
galSpecDir = str(val)
galDir = str(getPackageDir('sims_sed_library') + '/' + galSpecDir + '/')
self.LRG_name = 'Burst.25E09.1Z.spec'
self.LRG = Sed()
self.LRG.readSED_flambda(str(galDir + self.LRG_name))
#return
#Calculate imsimband magnitudes of source galaxies for matching
agn_sed = Sed()
agn_fname = str(getPackageDir('sims_sed_library') + '/agnSED/agn.spec.gz')
agn_sed.readSED_flambda(agn_fname)
src_iband = self.lenscat['MAGI_IN']
self.src_mag_norm = []
for src in src_iband:
self.src_mag_norm.append(matchBase().calcMagNorm([src],
agn_sed,
self.bandpassDict))
示例8: testSystematicUncertainty
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testSystematicUncertainty(self):
"""
Test that systematic uncertainty is added correctly.
"""
sigmaSys = 0.002
m5 = [23.5, 24.3, 22.1, 20.0, 19.5, 21.7]
photParams = PhotometricParameters(sigmaSys=sigmaSys)
bandpassDict = BandpassDict.loadTotalBandpassesFromFiles()
obs_metadata = ObservationMetaData(unrefractedRA=23.0, unrefractedDec=45.0, m5=m5, bandpassName=self.bandpasses)
magnitudes = bandpassDict.magListForSed(self.starSED)
skySeds = []
for i in range(len(self.bandpasses)):
skyDummy = Sed()
skyDummy.readSED_flambda(os.path.join(lsst.utils.getPackageDir("throughputs"), "baseline", "darksky.dat"))
normalizedSkyDummy = setM5(
obs_metadata.m5[self.bandpasses[i]],
skyDummy,
self.totalBandpasses[i],
self.hardwareBandpasses[i],
seeing=LSSTdefaults().seeing(self.bandpasses[i]),
photParams=PhotometricParameters(),
)
skySeds.append(normalizedSkyDummy)
for i in range(len(self.bandpasses)):
snr = calcSNR_sed(
self.starSED,
self.totalBandpasses[i],
skySeds[i],
self.hardwareBandpasses[i],
seeing=LSSTdefaults().seeing(self.bandpasses[i]),
photParams=PhotometricParameters(),
)
testSNR, gamma = calcSNR_m5(
numpy.array([magnitudes[i]]),
[self.totalBandpasses[i]],
numpy.array([m5[i]]),
photParams=PhotometricParameters(sigmaSys=0.0),
)
self.assertAlmostEqual(snr, testSNR[0], 10, msg="failed on calcSNR_m5 test %e != %e " % (snr, testSNR[0]))
control = numpy.sqrt(numpy.power(magErrorFromSNR(testSNR), 2) + numpy.power(sigmaSys, 2))
示例9: loadmltSEDs
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def loadmltSEDs(self, subset = None):
"""
By default will load all seds in mlt directory. The user can also define a subset of
what's in the directory and load only those SEDs instead. Will skip over extraneous
files in sed folder.
@param [in] subset is the list of the subset of files wanted if one doesn't want all files
in the mlt directory.
@param [out] sedList is the set of model SED spectra objects to be passed onto the matching
routines.
"""
files = []
if subset is None:
for fileName in os.listdir(self.mltDir):
files.append(fileName)
else:
for fileName in subset:
files.append(fileName)
numFiles = len(files)
numOn = 0
sedList = []
for fileName in files:
if numOn % 100 == 0:
print 'Loading %i of %i: MLT SEDs' % (numOn, numFiles)
try:
spec = Sed()
spec.readSED_flambda(str(self.mltDir + '/' + fileName))
spec.name = fileName
except:
continue
sedList.append(spec)
numOn += 1
return sedList
示例10: testCalcBasicColors
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testCalcBasicColors(self):
"""Tests the calculation of the colors of an SED in given bandpasses."""
testUtils = matchBase()
testSED = Sed()
testPhot = BandpassDict.loadTotalBandpassesFromFiles(self.filterList,
bandpassDir = os.path.join(lsst.utils.getPackageDir('throughputs'),'sdss'),
bandpassRoot = 'sdss_')
testSED.readSED_flambda(str(self.galDir + os.listdir(self.galDir)[0]))
testMags = testPhot.magListForSed(testSED)
testColors = []
for filtNum in range(0, len(self.filterList)-1):
testColors.append(testMags[filtNum] - testMags[filtNum+1])
testOutput = testUtils.calcBasicColors([testSED], testPhot)
np.testing.assert_equal([testColors], testOutput)
示例11: testInitializeIGM
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testInitializeIGM(self):
"Test Initialization Method"
#Make sure that if we initialize IGM with new inputs that it is initializing with them
testIGM = ApplyIGM()
testSed = Sed()
testSed.readSED_flambda(os.environ['SIMS_SED_LIBRARY_DIR'] + '/galaxySED/Inst.80E09.25Z.spec.gz')
testIGM.applyIGM(1.8, testSed)
testZmin = 1.8
testZmax = 2.2
#Want new values for testing,
#so make sure we are not just putting in the same values as are already there
self.assertNotEqual(testZmin, testIGM.zMin)
self.assertNotEqual(testZmax, testIGM.zMax)
testIGM.initializeIGM(zMin = testZmin, zMax = testZmax)
self.assertEqual(testZmin, testIGM.zMin)
self.assertEqual(testZmax, testIGM.zMax)
示例12: testPhotometricIndicesRaw
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testPhotometricIndicesRaw(self):
"""
Use manMagCalc_list with specified indices on an Sed. Make sure
that the appropriate magnitudes are or are not Nan
"""
starName = os.path.join(getPackageDir('sims_sed_library'), defaultSpecMap['km20_5750.fits_g40_5790'])
starPhot = BandpassDict.loadTotalBandpassesFromFiles()
testSed = Sed()
testSed.readSED_flambda(starName)
indices = [1, 3]
mags = starPhot.magListForSed(testSed, indices=indices)
np.testing.assert_equal(mags[0], np.NaN)
self.assertFalse(np.isnan(mags[1]), msg='mags[1] is NaN; should not be')
np.testing.assert_equal(mags[2], np.NaN)
self.assertFalse(np.isnan(mags[3]), msg='mags[3] is NaN; should not be')
np.testing.assert_equal(mags[4], np.NaN)
np.testing.assert_equal(mags[5], np.NaN)
self.assertEqual(len(mags), 6)
示例13: testPhotometricIndicesRaw
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testPhotometricIndicesRaw(self):
"""
Use manMagCalc_list with specified indices on an Sed. Make sure
that the appropriate magnitudes are or are not Nan
"""
starName = os.path.join(lsst.utils.getPackageDir('sims_sed_library'),defaultSpecMap['km20_5750.fits_g40_5790'])
starPhot = PhotometryStars()
starPhot.loadTotalBandpassesFromFiles()
testSed = Sed()
testSed.readSED_flambda(starName)
indices = [1,3]
mags = starPhot.manyMagCalc_list(testSed, indices=indices)
self.assertTrue(numpy.isnan(mags[0]))
self.assertFalse(numpy.isnan(mags[1]))
self.assertTrue(numpy.isnan(mags[2]))
self.assertFalse(numpy.isnan(mags[3]))
self.assertTrue(numpy.isnan(mags[4]))
self.assertTrue(numpy.isnan(mags[5]))
self.assertTrue(len(mags)==6)
示例14: uncertaintyUnitTest
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
class uncertaintyUnitTest(unittest.TestCase):
"""
Test the calculation of photometric uncertainties
"""
def setUp(self):
starName = os.path.join(lsst.utils.getPackageDir('sims_sed_library'),defaultSpecMap['km20_5750.fits_g40_5790'])
self.starSED = Sed()
self.starSED.readSED_flambda(starName)
imsimband = Bandpass()
imsimband.imsimBandpass()
fNorm = self.starSED.calcFluxNorm(22.0, imsimband)
self.starSED.multiplyFluxNorm(fNorm)
self.totalBandpasses = []
self.hardwareBandpasses = []
componentList = ['detector.dat', 'm1.dat', 'm2.dat', 'm3.dat',
'lens1.dat', 'lens2.dat', 'lens3.dat']
hardwareComponents = []
for c in componentList:
hardwareComponents.append(os.path.join(lsst.utils.getPackageDir('throughputs'),'baseline',c))
self.bandpasses = ['u', 'g', 'r', 'i', 'z', 'y']
for b in self.bandpasses:
filterName = os.path.join(lsst.utils.getPackageDir('throughputs'),'baseline','filter_%s.dat' % b)
components = hardwareComponents + [filterName]
bandpassDummy = Bandpass()
bandpassDummy.readThroughputList(components)
self.hardwareBandpasses.append(bandpassDummy)
components = components + [os.path.join(lsst.utils.getPackageDir('throughputs'),'baseline','atmos.dat')]
bandpassDummy = Bandpass()
bandpassDummy.readThroughputList(components)
self.totalBandpasses.append(bandpassDummy)
def tearDown(self):
del self.starSED
del self.bandpasses
del self.hardwareBandpasses
del self.totalBandpasses
示例15: testSEDCopyBasicColors
# 需要导入模块: from lsst.sims.photUtils.Sed import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed.Sed import readSED_flambda [as 别名]
def testSEDCopyBasicColors(self):
"""Tests that when makeCopy=True in calcBasicColors the SED object is unchanged after calling
and that colors are still accurately calculated"""
testUtils = matchBase()
testSED = Sed()
copyTest = Sed()
testPhot = BandpassDict.loadTotalBandpassesFromFiles(self.filterList,
bandpassDir = os.path.join(lsst.utils.getPackageDir('throughputs'),'sdss'),
bandpassRoot = 'sdss_')
testSED.readSED_flambda(str(self.galDir + os.listdir(self.galDir)[0]))
copyTest.setSED(wavelen = testSED.wavelen, flambda = testSED.flambda)
testLambda = copyTest.wavelen[0]
testMags = testPhot.magListForSed(testSED)
testColors = []
for filtNum in range(0, len(self.filterList)-1):
testColors.append(testMags[filtNum] - testMags[filtNum+1])
testOutput = testUtils.calcBasicColors([copyTest], testPhot, makeCopy=True)
self.assertEqual(testLambda, copyTest.wavelen[0])
np.testing.assert_equal([testColors], testOutput)