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


Python Sed.calcErgs方法代码示例

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


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

示例1: test_calcErgs

# 需要导入模块: from lsst.sims.photUtils import Sed [as 别名]
# 或者: from lsst.sims.photUtils.Sed import calcErgs [as 别名]
    def test_calcErgs(self):
        """
        Test that calcErgs actually calculates the flux of a source in
        ergs/s/cm^2 by running it on black bodies with flat bandpasses
        and comparing to the Stefan-Boltzmann law.
        """

        boltzmann_k = 1.3807e-16  # in ergs/Kelvin
        planck_h = 6.6261e-27  # in cm^2*g/s
        speed_of_light = 2.9979e10  # in cm/s
        stefan_boltzmann_sigma = 5.6705e-5  # in ergs/cm^2/s/Kelvin

        wavelen_arr = np.arange(10.0, 200000.0, 10.0)  # in nm
        bp = Bandpass(wavelen=wavelen_arr, sb=np.ones(len(wavelen_arr)))

        log10_bb_factor = np.log10(2.0) + np.log10(planck_h)
        log10_bb_factor += 2.0*np.log10(speed_of_light)
        log10_bb_factor -= 5.0*(np.log10(wavelen_arr) - 7.0)  # convert wavelen to cm

        for temp in np.arange(5000.0, 7000.0, 250.0):
            log10_exp_arg = np.log10(planck_h) + np.log10(speed_of_light)
            log10_exp_arg -= (np.log10(wavelen_arr) - 7.0)
            log10_exp_arg -= (np.log10(boltzmann_k) + np.log10(temp))

            exp_arg = np.power(10.0, log10_exp_arg)
            log10_bose_factor = -1.0*np.log10(np.exp(exp_arg)-1.0)

            # the -7.0 below is because, otherwise, flambda will be in
            # ergs/s/cm^2/cm and we want ergs/s/cm^2/nm
            #
            # the np.pi comes from the integral in the 'Stefan-Boltzmann'
            # section of
            # https://en.wikipedia.org/wiki/Planck%27s_law#Stefan.E2.80.93Boltzmann_law
            #
            bb_flambda = np.pi*np.power(10.0, log10_bb_factor+log10_bose_factor-7.0)

            sed = Sed(wavelen=wavelen_arr, flambda=bb_flambda)
            ergs = sed.calcErgs(bp)

            log10_ergs = np.log10(stefan_boltzmann_sigma) + 4.0*np.log10(temp)
            ergs_truth = np.power(10.0, log10_ergs)

            msg = '\ntemp:%e\nergs: %e\nergs_truth: %e' % (temp, ergs, ergs_truth)
            self.assertAlmostEqual(ergs/ergs_truth, 1.0, 3, msg=msg)

        # Now test it on a bandpass with throughput=0.25 and an wavelength
        # array that is not the same as the SED

        wavelen_arr = np.arange(10.0, 100000.0, 146.0)  # in nm
        bp = Bandpass(wavelen=wavelen_arr, sb=0.25*np.ones(len(wavelen_arr)))

        wavelen_arr = np.arange(5.0, 200000.0, 17.0)

        log10_bb_factor = np.log10(2.0) + np.log10(planck_h)
        log10_bb_factor += 2.0*np.log10(speed_of_light)
        log10_bb_factor -= 5.0*(np.log10(wavelen_arr) - 7.0)  # convert wavelen to cm

        for temp in np.arange(5000.0, 7000.0, 250.0):
            log10_exp_arg = np.log10(planck_h) + np.log10(speed_of_light)
            log10_exp_arg -= (np.log10(wavelen_arr) - 7.0)
            log10_exp_arg -= (np.log10(boltzmann_k) + np.log10(temp))

            exp_arg = np.power(10.0, log10_exp_arg)
            log10_bose_factor = -1.0*np.log10(np.exp(exp_arg)-1.0)

            # the -7.0 below is because, otherwise, flambda will be in
            # ergs/s/cm^2/cm and we want ergs/s/cm^2/nm
            #
            # the np.pi comes from the integral in the 'Stefan-Boltzmann'
            # section of
            # https://en.wikipedia.org/wiki/Planck%27s_law#Stefan.E2.80.93Boltzmann_law
            #
            bb_flambda = np.pi*np.power(10.0, log10_bb_factor+log10_bose_factor-7.0)

            sed = Sed(wavelen=wavelen_arr, flambda=bb_flambda)
            ergs = sed.calcErgs(bp)

            log10_ergs = np.log10(stefan_boltzmann_sigma) + 4.0*np.log10(temp)
            ergs_truth = np.power(10.0, log10_ergs)

            msg = '\ntemp: %e\nergs: %e\nergs_truth: %e' % (temp,ergs, ergs_truth)
            self.assertAlmostEqual(ergs/ergs_truth, 0.25, 3, msg=msg)
开发者ID:lsst,项目名称:sims_photUtils,代码行数:84,代码来源:testSed.py


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