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))
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)
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, 19) numpy.testing.assert_array_almost_equal(bp.sb, testDict[name].sb, 19) for bpControl, bpTest in zip(bpList, testDict.values()): numpy.testing.assert_array_almost_equal(bpControl.wavelen, bpTest.wavelen, 19) numpy.testing.assert_array_almost_equal(bpControl.sb, bpTest.sb, 19)
def testFluxDictForSed(self): """ Test that fluxDictForSed calculates the correct fluxes """ wavelen = numpy.arange(10.0,2000.0,1.0) flux = (wavelen*2.0-5.0)*1.0e-6 spectrum = Sed(wavelen=wavelen, flambda=flux) for nBp in range(3, 10, 1): nameList, bpList = self.getListOfBandpasses(nBp) testDict = BandpassDict(bpList, nameList) self.assertFalse(len(testDict.values()[0].wavelen)==len(spectrum.wavelen)) fluxDict = testDict.fluxDictForSed(spectrum) for ix, (name, bp) in enumerate(zip(nameList, bpList)): fluxControl = spectrum.calcFlux(bp) self.assertAlmostEqual(fluxDict[name]/fluxControl, 1.0, 2)
def testMagListForSed(self): """ Test that magListForSed calculates the correct magnitude """ wavelen = numpy.arange(10.0,2000.0,1.0) flux = (wavelen*2.0-5.0)*1.0e-6 spectrum = Sed(wavelen=wavelen, flambda=flux) for nBp in range(3, 10, 1): nameList, bpList = self.getListOfBandpasses(nBp) testDict = BandpassDict(bpList, nameList) self.assertFalse(len(testDict.values()[0].wavelen)==len(spectrum.wavelen)) magList = testDict.magListForSed(spectrum) for ix, (name, bp, magTest) in enumerate(zip(nameList, bpList, magList)): magControl = spectrum.calcMag(bp) self.assertAlmostEqual(magTest, magControl, 5)