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


Python BandpassDict.magArrayForSedList方法代码示例

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


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

示例1: testMagArrayForSedList

# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import magArrayForSedList [as 别名]
    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)
开发者ID:lsst,项目名称:sims_photUtils,代码行数:52,代码来源:testBandpassDict.py

示例2: testIndicesOnMagnitudes

# 需要导入模块: from lsst.sims.photUtils import BandpassDict [as 别名]
# 或者: from lsst.sims.photUtils.BandpassDict import magArrayForSedList [as 别名]
    def testIndicesOnMagnitudes(self):
        """
        Test that, when you pass a list of indices into the calcMagList
        methods, you get the correct magnitudes out.
        """

        nBandpasses = 7
        nameList, bpList = self.getListOfBandpasses(nBandpasses)
        testBpDict = BandpassDict(bpList, nameList)

        # first try it with a single Sed
        wavelen = np.arange(10.0, 2000.0, 1.0)
        flux = (wavelen*2.0-5.0)*1.0e-6
        spectrum = Sed(wavelen=wavelen, flambda=flux)
        indices = [1, 2, 5]

        magList = testBpDict.magListForSed(spectrum, indices=indices)
        ctNaN = 0
        for ix, (name, bp, magTest) in enumerate(zip(nameList,
                                                     bpList,
                                                     magList)):
            if ix in indices:
                magControl = spectrum.calcMag(bp)
                self.assertAlmostEqual(magTest, magControl, 5)
            else:
                ctNaN += 1
                np.testing.assert_equal(magTest, np.NaN)

        self.assertEqual(ctNaN, 4)

        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

        # now try a SedList without a wavelenMatch
        testSedList = SedList(sedNameList, magNormList,
                              fileDir=self.sedDir,
                              internalAvList=internalAvList,
                              redshiftList=redshiftList,
                              galacticAvList=galacticAvList)

        magList = testBpDict.magListForSedList(testSedList, indices=indices)
        magArray = testBpDict.magArrayForSedList(testSedList, indices=indices)
        self.assertEqual(magList.shape[0], nSed)
        self.assertEqual(magList.shape[1], nBandpasses)
        self.assertEqual(magArray.shape[0], nSed)
        for bpname in testBpDict:
            self.assertEqual(len(magArray[bpname]), nSed)

        for ix, sedObj in enumerate(testSedList):
            dummySed = Sed(wavelen=copy.deepcopy(sedObj.wavelen),
                           flambda=copy.deepcopy(sedObj.flambda))

            ctNaN = 0
            for iy, bp in enumerate(testBpDict):
                if iy in indices:
                    mag = dummySed.calcMag(testBpDict[bp])
                    self.assertAlmostEqual(mag, magList[ix][iy], 2)
                    self.assertAlmostEqual(mag, magArray[ix][iy], 2)
                    self.assertAlmostEqual(mag, magArray[bp][ix], 2)
                else:
                    ctNaN += 1
                    np.testing.assert_equal(magList[ix][iy], np.NaN)
                    np.testing.assert_equal(magArray[ix][iy], np.NaN)
                    np.testing.assert_equal(magArray[bp][ix], np.NaN)

            self.assertEqual(ctNaN, 4)

        # now use wavelenMatch
        testSedList = SedList(sedNameList, magNormList,
                              fileDir=self.sedDir,
                              internalAvList=internalAvList,
                              redshiftList=redshiftList,
                              galacticAvList=galacticAvList,
                              wavelenMatch=testBpDict.wavelenMatch)

        magList = testBpDict.magListForSedList(testSedList, indices=indices)
        magArray = testBpDict.magArrayForSedList(testSedList, indices=indices)
        self.assertEqual(magList.shape[0], nSed)
        self.assertEqual(magList.shape[1], nBandpasses)
        self.assertEqual(magArray.shape[0], nSed)
        for bpname in testBpDict:
            self.assertEqual(len(magArray[bpname]), nSed)

        for ix, sedObj in enumerate(testSedList):
            dummySed = Sed(wavelen=copy.deepcopy(sedObj.wavelen),
                           flambda=copy.deepcopy(sedObj.flambda))

            ctNaN = 0
            for iy, bp in enumerate(testBpDict):
                if iy in indices:
                    mag = dummySed.calcMag(testBpDict[bp])
                    self.assertAlmostEqual(mag, magList[ix][iy], 2)
                    self.assertAlmostEqual(mag, magArray[ix][iy], 2)
                    self.assertAlmostEqual(mag, magArray[bp][ix], 2)
                else:
                    ctNaN += 1
#.........这里部分代码省略.........
开发者ID:lsst,项目名称:sims_photUtils,代码行数:103,代码来源:testBandpassDict.py


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