本文整理汇总了Python中lsst.sims.photUtils.BandpassDict类的典型用法代码示例。如果您正苦于以下问题:Python BandpassDict类的具体用法?Python BandpassDict怎么用?Python BandpassDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BandpassDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testExceptions
def testExceptions(self):
"""
Test that the correct exceptions are thrown by BandpassDict
"""
nameList, bpList = self.getListOfBandpasses(4)
dummyNameList = copy.deepcopy(nameList)
dummyNameList[1] = dummyNameList[0]
with self.assertRaises(RuntimeError) as context:
testDict = BandpassDict(bpList, dummyNameList)
self.assertTrue('occurs twice' in context.exception.message)
testDict = BandpassDict(bpList, nameList)
with self.assertRaises(AttributeError) as context:
testDict.phiArray = None
with self.assertRaises(AttributeError) as context:
testDict.wavelenStep = 0.9
with self.assertRaises(AttributeError) as context:
testDict.wavelenMatch = numpy.arange(10.0,100.0,1.0)
示例2: testWavelenMatch
def testWavelenMatch(self):
"""
Test that when you load bandpasses sampled over different
wavelength grids, they all get sampled to the same wavelength
grid.
"""
dwavList = numpy.arange(5.0,25.0,5.0)
bpList = []
bpNameList = []
for ix, dwav in enumerate(dwavList):
name = 'bp_%d' % ix
wavelen = numpy.arange(10.0, 1500.0, dwav)
sb = numpy.exp(-0.5*(numpy.power((wavelen-100.0*ix)/100.0,2)))
bp = Bandpass(wavelen=wavelen, sb=sb)
bpList.append(bp)
bpNameList.append(name)
# First make sure that we have created distinct wavelength grids
for ix in range(len(bpList)):
for iy in range(ix+1,len(bpList)):
self.assertTrue(len(bpList[ix].wavelen)!=len(bpList[iy].wavelen))
testDict = BandpassDict(bpList, bpNameList)
# Now make sure that the wavelength grids in the dict were resampled, but that
# the original wavelength grids were not changed
for ix in range(len(bpList)):
numpy.testing.assert_array_almost_equal(testDict.values()[ix].wavelen, testDict.wavelenMatch, 19)
if ix!=0:
self.assertTrue(len(testDict.wavelenMatch)!=len(bpList[ix].wavelen))
示例3: testInitialization
def testInitialization(self):
"""
Test that all of the member variables of BandpassDict are set
to the correct value upon construction.
"""
for nBp in range(3,10,1):
nameList, bpList = self.getListOfBandpasses(nBp)
testDict = BandpassDict(bpList, nameList)
self.assertEqual(len(testDict), nBp)
for controlName, testName in zip(nameList, testDict):
self.assertEqual(controlName, testName)
for controlName, testName in zip(nameList, testDict.keys()):
self.assertEqual(controlName, testName)
for name, bp in zip(nameList, bpList):
numpy.testing.assert_array_almost_equal(bp.wavelen, testDict[name].wavelen, 10)
numpy.testing.assert_array_almost_equal(bp.sb, testDict[name].sb, 10)
for bpControl, bpTest in zip(bpList, testDict.values()):
numpy.testing.assert_array_almost_equal(bpControl.wavelen, bpTest.wavelen, 10)
numpy.testing.assert_array_almost_equal(bpControl.sb, bpTest.sb, 10)
示例4: testFluxListForSedList
def testFluxListForSedList(self):
"""
Test that fluxListForSedList calculates the correct fluxes
"""
nBandpasses = 7
bpNameList, bpList = self.getListOfBandpasses(nBandpasses)
testBpDict = BandpassDict(bpList, bpNameList)
nSed = 20
sedNameList = self.getListOfSedNames(nSed)
magNormList = self.rng.random_sample(nSed)*5.0 + 15.0
internalAvList = self.rng.random_sample(nSed)*0.3 + 0.1
redshiftList = self.rng.random_sample(nSed)*5.0
galacticAvList = self.rng.random_sample(nSed)*0.3 + 0.1
# first, test on an SedList without a wavelenMatch
testSedList = SedList(sedNameList, magNormList,
fileDir=self.sedDir,
internalAvList=internalAvList,
redshiftList=redshiftList,
galacticAvList=galacticAvList)
fluxList = testBpDict.fluxListForSedList(testSedList)
self.assertEqual(fluxList.shape[0], nSed)
self.assertEqual(fluxList.shape[1], nBandpasses)
for ix, sedObj in enumerate(testSedList):
dummySed = Sed(wavelen=copy.deepcopy(sedObj.wavelen),
flambda=copy.deepcopy(sedObj.flambda))
for iy, bp in enumerate(testBpDict):
flux = dummySed.calcFlux(bpList[iy])
self.assertAlmostEqual(flux/fluxList[ix][iy], 1.0, 2)
# now use wavelenMatch
testSedList = SedList(sedNameList, magNormList,
fileDir=self.sedDir,
internalAvList=internalAvList,
redshiftList=redshiftList,
galacticAvList=galacticAvList,
wavelenMatch=testBpDict.wavelenMatch)
fluxList = testBpDict.fluxListForSedList(testSedList)
self.assertEqual(fluxList.shape[0], nSed)
self.assertEqual(fluxList.shape[1], nBandpasses)
for ix, sedObj in enumerate(testSedList):
dummySed = Sed(wavelen=copy.deepcopy(sedObj.wavelen),
flambda=copy.deepcopy(sedObj.flambda))
for iy, bp in enumerate(testBpDict):
flux = dummySed.calcFlux(bpList[iy])
self.assertAlmostEqual(flux/fluxList[ix][iy], 1.0, 2)
示例5: testMagArrayForSedList
def testMagArrayForSedList(self):
"""
Test that magArrayForSedList calculates the correct magnitude
"""
nBandpasses = 7
bpNameList, bpList = self.getListOfBandpasses(nBandpasses)
testBpDict = BandpassDict(bpList, bpNameList)
nSed = 20
sedNameList = self.getListOfSedNames(nSed)
magNormList = self.rng.random_sample(nSed)*5.0 + 15.0
internalAvList = self.rng.random_sample(nSed)*0.3 + 0.1
redshiftList = self.rng.random_sample(nSed)*5.0
galacticAvList = self.rng.random_sample(nSed)*0.3 + 0.1
# first, test on an SedList without a wavelenMatch
testSedList = SedList(sedNameList, magNormList,
fileDir=self.sedDir,
internalAvList=internalAvList,
redshiftList=redshiftList,
galacticAvList=galacticAvList)
magArray = testBpDict.magArrayForSedList(testSedList)
for ix, sedObj in enumerate(testSedList):
dummySed = Sed(wavelen=copy.deepcopy(sedObj.wavelen),
flambda=copy.deepcopy(sedObj.flambda))
for iy, bp in enumerate(bpNameList):
mag = dummySed.calcMag(bpList[iy])
self.assertAlmostEqual(mag, magArray[bp][ix], 2)
# now use wavelenMatch
testSedList = SedList(sedNameList, magNormList,
fileDir=self.sedDir,
internalAvList=internalAvList,
redshiftList=redshiftList,
galacticAvList=galacticAvList,
wavelenMatch=testBpDict.wavelenMatch)
magArray = testBpDict.magArrayForSedList(testSedList)
for ix, sedObj in enumerate(testSedList):
dummySed = Sed(wavelen=copy.deepcopy(sedObj.wavelen),
flambda=copy.deepcopy(sedObj.flambda))
for iy, bp in enumerate(bpNameList):
mag = dummySed.calcMag(bpList[iy])
self.assertAlmostEqual(mag, magArray[bp][ix], 2)
示例6: testLSSTmags
def testLSSTmags(self):
"""
Test that PhotometrySSM properly calculates LSST magnitudes
"""
catName = os.path.join(getPackageDir('sims_catUtils'), 'tests', 'scratchSpace', 'lsstSsmPhotCat.txt')
cat=LSST_SSM_photCat(self.photDB)
cat.write_catalog(catName)
dtype = np.dtype([('id', np.int), ('u', np.float), ('g', np.float),
('r', np.float), ('i', np.float), ('z', np.float),
('y', np.float)])
testData = np.genfromtxt(catName, dtype=dtype, delimiter=',')
self.assertGreater(len(testData), 0)
controlData = np.genfromtxt(self.dbFile, dtype=self.dtype)
self.assertGreater(len(controlData), 0)
LSSTbandpasses = BandpassDict.loadTotalBandpassesFromFiles()
controlSedList = SedList(controlData['sedFilename'], controlData['magNorm'],
wavelenMatch=LSSTbandpasses.wavelenMatch)
controlMags = LSSTbandpasses.magListForSedList(controlSedList)
for ii in range(len(controlMags)):
for jj, bpName in enumerate(['u', 'g', 'r', 'i', 'z', 'y']):
self.assertAlmostEqual(controlMags[ii][jj], testData[bpName][ii], 10)
if os.path.exists(catName):
os.unlink(catName)
示例7: get_test_disk_mags
def get_test_disk_mags(self):
if not hasattr(self, 'testBandpassDict'):
self.testBandpassDict = BandpassDict.loadTotalBandpassesFromFiles()
return self._magnitudeGetter('disk', self.testBandpassDict,
self.get_test_disk_mags._colnames)
示例8: testLSSTmags
def testLSSTmags(self):
"""
Test that PhotometrySSM properly calculates LSST magnitudes
"""
cat = LSST_SSM_photCat(self.photDB)
dtype = np.dtype([('id', np.int), ('u', np.float), ('g', np.float),
('r', np.float), ('i', np.float), ('z', np.float),
('y', np.float)])
with lsst.utils.tests.getTempFilePath('.txt') as catName:
cat.write_catalog(catName)
testData = np.genfromtxt(catName, dtype=dtype, delimiter=',')
self.assertGreater(len(testData), 0)
controlData = np.genfromtxt(self.dbFile, dtype=self.dtype)
self.assertGreater(len(controlData), 0)
LSSTbandpasses = BandpassDict.loadTotalBandpassesFromFiles()
controlSedList = SedList(controlData['sedFilename'], controlData['magNorm'],
wavelenMatch=LSSTbandpasses.wavelenMatch,
fileDir=getPackageDir('sims_sed_library'),
specMap=defaultSpecMap)
controlMags = LSSTbandpasses.magListForSedList(controlSedList)
for ii in range(len(controlMags)):
for jj, bpName in enumerate(['u', 'g', 'r', 'i', 'z', 'y']):
self.assertAlmostEqual(controlMags[ii][jj], testData[bpName][ii], 10)
示例9: get_quiescent_lsst_magnitudes
def get_quiescent_lsst_magnitudes(self):
if not hasattr(self, 'lsstBandpassDict'):
self.lsstBandpassDict = BandpassDict.loadTotalBandpassesFromFiles()
return self._quiescentMagnitudeGetter(self.lsstBandpassDict,
self.get_quiescent_lsst_magnitudes._colnames)
示例10: testLoadTotalBandpassesFromFiles
def testLoadTotalBandpassesFromFiles(self):
"""
Test that the class method loadTotalBandpassesFromFiles produces the
expected result
"""
bandpassDir = os.path.join(getPackageDir('sims_photUtils'), 'tests', 'cartoonSedTestData')
bandpassNames = ['g', 'r', 'u']
bandpassRoot = 'test_bandpass_'
bandpassDict = BandpassDict.loadTotalBandpassesFromFiles(bandpassNames=bandpassNames,
bandpassDir=bandpassDir,
bandpassRoot = bandpassRoot)
controlBandpassList = []
for bpn in bandpassNames:
dummyBp = Bandpass()
dummyBp.readThroughput(os.path.join(bandpassDir,bandpassRoot+bpn+'.dat'))
controlBandpassList.append(dummyBp)
wMin = controlBandpassList[0].wavelen[0]
wMax = controlBandpassList[0].wavelen[-1]
wStep = controlBandpassList[0].wavelen[1]-controlBandpassList[0].wavelen[0]
for bp in controlBandpassList:
bp.resampleBandpass(wavelen_min=wMin, wavelen_max=wMax, wavelen_step=wStep)
for test, control in zip(bandpassDict.values(), controlBandpassList):
numpy.testing.assert_array_almost_equal(test.wavelen, control.wavelen, 19)
numpy.testing.assert_array_almost_equal(test.sb, control.sb, 19)
示例11: get_lsst_magnitudes
def get_lsst_magnitudes(self):
"""
getter for LSST magnitudes of solar system objects
"""
if not hasattr(self, 'lsstBandpassDict'):
self.lsstBandpassDict = BandpassDict.loadTotalBandpassesFromFiles()
return self._quiescentMagnitudeGetter(self.lsstBandpassDict, self.get_lsst_magnitudes._colnames)
示例12: get_test_mags
def get_test_mags(self):
if not hasattr(self, 'variabilitybandpassDict'):
self.variabilityBandpassDict = BandpassDict.loadTotalBandpassesFromFiles()
self._loadSedList(self.variabilityBandpassDict.wavelenMatch)
if not hasattr(self, '_sedList'):
return numpy.ones((6,0))
return self._magnitudeGetter(self.variabilityBandpassDict, self.get_test_mags._colnames)
示例13: testLoadBandpassesFromFiles
def testLoadBandpassesFromFiles(self):
"""
Test that running the classmethod loadBandpassesFromFiles produces
expected result
"""
fileDir = os.path.join(getPackageDir('sims_photUtils'),
'tests', 'cartoonSedTestData')
bandpassNames = ['g', 'z', 'i']
bandpassRoot = 'test_bandpass_'
componentList = ['toy_mirror.dat']
atmo = os.path.join(fileDir, 'toy_atmo.dat')
bandpassDict, hardwareDict = BandpassDict.loadBandpassesFromFiles(bandpassNames=bandpassNames,
filedir=fileDir,
bandpassRoot=bandpassRoot,
componentList=componentList,
atmoTransmission=atmo)
controlBandpassList = []
controlHardwareList = []
for bpn in bandpassNames:
componentList = [os.path.join(fileDir, bandpassRoot+bpn+'.dat'),
os.path.join(fileDir, 'toy_mirror.dat')]
dummyBp = Bandpass()
dummyBp.readThroughputList(componentList)
controlHardwareList.append(dummyBp)
componentList = [os.path.join(fileDir, bandpassRoot+bpn+'.dat'),
os.path.join(fileDir, 'toy_mirror.dat'),
os.path.join(fileDir, 'toy_atmo.dat')]
dummyBp = Bandpass()
dummyBp.readThroughputList(componentList)
controlBandpassList.append(dummyBp)
wMin = controlBandpassList[0].wavelen[0]
wMax = controlBandpassList[0].wavelen[-1]
wStep = controlBandpassList[0].wavelen[1]-controlBandpassList[0].wavelen[0]
for bp, hh in zip(controlBandpassList, controlHardwareList):
bp.resampleBandpass(wavelen_min=wMin, wavelen_max=wMax,
wavelen_step=wStep)
hh.resampleBandpass(wavelen_min=wMin, wavelen_max=wMax,
wavelen_step=wStep)
for test, control in zip(bandpassDict.values(), controlBandpassList):
np.testing.assert_array_almost_equal(test.wavelen,
control.wavelen, 19)
np.testing.assert_array_almost_equal(test.sb, control.sb, 19)
for test, control in zip(hardwareDict.values(), controlHardwareList):
np.testing.assert_array_almost_equal(test.wavelen,
control.wavelen, 19)
np.testing.assert_array_almost_equal(test.sb, control.sb, 19)
示例14: get_test_agn_mags
def get_test_agn_mags(self):
if not hasattr(self, 'testBandpassDict'):
self.testBandpassDict = BandpassDict.loadTotalBandpassesFromFiles()
mag = self._quiescentMagnitudeGetter('agn', self.testBandpassDict,
self.get_test_agn_mags._colnames)
mag += self._variabilityGetter(self.get_test_agn_mags._colnames)
return mag
示例15: testManyMagSystems
def testManyMagSystems(self):
"""
Test that the SSM photometry mixin can simultaneously calculate magnitudes
in multiple bandpass systems
"""
catName = os.path.join(getPackageDir('sims_catUtils'), 'tests', 'scratchSpace', 'compoundSsmPhotCat.txt')
cat=Compound_SSM_photCat(self.photDB)
cat.write_catalog(catName)
dtype = np.dtype([('id', np.int), ('lsst_u', np.float), ('lsst_g', np.float),
('lsst_r', np.float), ('lsst_i', np.float), ('lsst_z', np.float),
('lsst_y', np.float),
('cartoon_u', np.float), ('cartoon_g', np.float),
('cartoon_r', np.float), ('cartoon_i', np.float),
('cartoon_z', np.float)])
testData = np.genfromtxt(catName, dtype=dtype, delimiter=',')
self.assertGreater(len(testData), 0)
controlData = np.genfromtxt(self.dbFile, dtype=self.dtype)
self.assertGreater(len(controlData), 0)
LSSTbandpasses = BandpassDict.loadTotalBandpassesFromFiles()
cartoonBandpasses = BandpassDict.loadTotalBandpassesFromFiles(
['u', 'g', 'r', 'i', 'z'],
bandpassDir = os.path.join(getPackageDir('sims_photUtils'), 'tests', 'cartoonSedTestData'),
bandpassRoot = 'test_bandpass_'
)
controlSedList = SedList(controlData['sedFilename'], controlData['magNorm'],
wavelenMatch=LSSTbandpasses.wavelenMatch)
controlLsstMags = LSSTbandpasses.magListForSedList(controlSedList)
controlCartoonMags = cartoonBandpasses.magListForSedList(controlSedList)
for ii in range(len(controlLsstMags)):
for jj, bpName in enumerate(['lsst_u', 'lsst_g', 'lsst_r', 'lsst_i', 'lsst_z', 'lsst_y']):
self.assertAlmostEqual(controlLsstMags[ii][jj], testData[bpName][ii], 10)
for jj, bpName in enumerate(['cartoon_u', 'cartoon_g', 'cartoon_r', 'cartoon_i', 'cartoon_z']):
self.assertAlmostEqual(controlCartoonMags[ii][jj], testData[bpName][ii], 10)
if os.path.exists(catName):
os.unlink(catName)