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


Python units.MeV方法代码示例

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


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

示例1: test_constructor_complete

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_constructor_complete():

    p = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test',
                  free=False, unit=u.MeV, prior=Uniform_prior(), is_normalization=True,)

    assert p.min_value == -5.0
    assert p.max_value == 5.0
    assert p.value == 1.0
    assert p.delta == 0.2
    assert p.name == 'test_parameter'
    assert p.description == 'test'
    assert p.fix == True
    assert p.free == False
    assert p.has_prior() == True

    assert p.unit == u.MeV

    assert p.is_normalization

    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:22,代码来源:test_parameter.py

示例2: test_constructor_with_transform

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_constructor_with_transform():

    p = Parameter('test_parameter', 1.0, min_value=0.1, max_value=5.0, delta=0.2, desc='test',
                  free=False, unit=u.MeV, prior=Uniform_prior(), is_normalization=True,)

    assert p.min_value == 0.1
    assert p.max_value == 5.0
    assert p.value == 1.0
    assert p.delta == 0.2
    assert p.name == 'test_parameter'
    assert p.description == 'test'
    assert p.fix == True
    assert p.free == False
    assert p.has_prior() == True

    assert p.unit == u.MeV

    assert p.is_normalization

    assert p.has_transformation
    
    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:24,代码来源:test_parameter.py

示例3: test_conflicting_units_in_initial_value_and_unit_keyword

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_conflicting_units_in_initial_value_and_unit_keyword():

    p = Parameter('test_parameter', 1.0 * u.keV, desc='Description', unit=u.MeV)

    assert p.min_value is None
    assert p.max_value is None
    assert p.value == 1.0e-3
    assert isinstance(p.delta, float)
    assert p.name == 'test_parameter'
    assert p.description == 'Description'
    assert p.fix == False
    assert p.free == True
    assert p.has_prior() == False
    assert p.prior is None

    assert p.unit == u.MeV

    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:20,代码来源:test_parameter.py

示例4: test_set_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_set_units():

    p = Parameter('test_parameter',1.0, unit=u.keV)

    p.value = 3.0 * u.MeV

    assert p.value == 3000.0

    with pytest.raises(u.UnitConversionError):

        p.value = 3.0 * u.cm

    with pytest.raises(CannotConvertValueToNewUnits):

        p.unit = u.cm

    with pytest.raises(CannotConvertValueToNewUnits):

        p.unit = u.dimensionless_unscaled

    p.unit = u.MeV

    assert p.unit == u.MeV

    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:27,代码来源:test_parameter.py

示例5: evaluate

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def evaluate(self, x, mass, channel, sigmav, J):

        if isinstance(x, astropy_units.Quantity):

            # We need to convert to GeV
            xx = x.to(astropy_units.GeV)

        else:

            # We can assume that the input is in keV

            keVtoGeV = 1e-6

            xx = np.multiply(x, keVtoGeV)  # xm expects gamma ray energies in MeV

        xm = np.log10(np.divide(xx, mass))
        phip = 1. / (8. * np.pi) * np.power(mass, -2) * (sigmav * J)  # units of this should be 1 / cm**2 / s
        dn = self._dn_interp((mass, xm))
        dn[xm > 0] = 0

        return np.multiply(phip, np.divide(dn, x)) 
开发者ID:threeML,项目名称:astromodels,代码行数:23,代码来源:dm_models.py

示例6: find_shower_max_height

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def find_shower_max_height(self, energy, h_first_int, gamma_alt):
        """
        estimates the height of the shower maximum in the atmosphere
        according to equation (3) in [arXiv:0907.2610v3]

        Parameters
        ----------
        energy : astropy.Quantity
            energy of the parent gamma photon
        h_first_int : astropy.Quantity
            hight of the first interaction
        gamma_alt : astropy.Quantity or float
            altitude / pi-minus-zenith (in radians in case of float)
            of the parent gamma photon

        Returns
        -------
        shower_max_height : astropy.Quantity
            height of the shower maximum
        """

        # offset of the shower-maximum in radiation lengths
        c = 0.97 * log(energy / (83 * u.MeV)) - 1.32
        # radiation length in dry air at 1 atm = 36,62 g / cm**2 [PDG]
        c *= 36.62 * u.g * u.cm ** -2
        # showers with a more horizontal direction spend more path
        # length in each atm. layer the "effective transverse
        # thickness" they have to pass is reduced
        c *= np.sin(gamma_alt)

        # find the thickness at the height of the first interaction
        t_first_int = self.thickness_profile(h_first_int)

        # total thickness at shower maximum = thickness at first
        # interaction + thickness traversed to shower maximum
        t_shower_max = t_first_int + c

        # now find the height with the wanted thickness by solving for the
        # desired thickness
        return self.altitude_profile(t_shower_max) 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:42,代码来源:shower_max.py

示例7: test_set_within_bounds_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_set_within_bounds_units():

    p = Parameter('test_parameter',1.0 * u.keV, min_value = -2.0 * u.MeV, max_value = 2.0 * u.MeV, unit=u.keV)

    p.value = 1.2 * u.MeV

    assert p.value == 1200.0

    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:11,代码来源:test_parameter.py

示例8: test_set_bounds_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_set_bounds_units():

    p = Parameter('test_parameter', 1.0 * u.keV)

    p.bounds = (-2.0 * u.MeV, 2.0 * u.eV)

    assert p.min_value == -2000
    assert p.max_value == 2e-3

    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:12,代码来源:test_parameter.py

示例9: test_set_delta_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_set_delta_units():

    p = Parameter('test_parameter', 1.0, unit='GeV')

    p.delta = 500 * u.MeV

    assert p.delta == 0.5

    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:11,代码来源:test_parameter.py

示例10: test_duplicate

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_duplicate():

    p1 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV')

    p2 = p1.duplicate()

    assert p1.to_dict() == p2.to_dict()

    p1.display()
    p2.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:12,代码来源:test_parameter.py

示例11: test_get_randomized_value

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_get_randomized_value():

    # Test randomization no boundaries (normal distribution)
    p1 = Parameter('test_parameter', 1.0)

    val2 = p1.get_randomized_value(0.1)

    assert isinstance(val2, float)

    # Test the randomized value with truncated normal, i.e., with boundaries

    p2 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV')

    val1 = p2.get_randomized_value(0.1)

    assert p2.min_value <= val1 <= p2.max_value

    # Test the same but with a large variance

    val1 = p2.get_randomized_value(10.0)

    assert p2.min_value <= val1 <= p2.max_value

    p2.min_value = None

    val1 = p2.get_randomized_value(10.0)
    assert val1 <= p2.max_value

    p2.min_value = -5.0
    p2.max_value = None

    val1 = p2.get_randomized_value(10.0)
    assert val1 >= p2.min_value 
开发者ID:threeML,项目名称:astromodels,代码行数:35,代码来源:test_parameter.py

示例12: test_set_remove_minimum

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_set_remove_minimum():
    p1 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV')

    p1.remove_minimum()

    assert p1.min_value == None

    p1.value = -1000.0

    assert p1.value == -1000.0 
开发者ID:threeML,项目名称:astromodels,代码行数:12,代码来源:test_parameter.py

示例13: test_set_auxiliary_variable

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_set_auxiliary_variable():

    p1 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV')

    x = Parameter('aux_variable', 1.0)

    # ax + b

    law = Line()
    law.a = 1.0
    law.b = 2.0

    p1.add_auxiliary_variable(x, law)

    assert p1.has_auxiliary_variable() == True

    assert p1.value == 3.0

    assert p1.free == False

    x.value = 4.0

    assert p1.value == 6.0

    # Check that assigning to the parameter doesn't produce any effect
    p1.value = -1.0

    assert p1.value == 6.0

    # Now check errors reporting
    with pytest.raises(AttributeError):

        p1.add_auxiliary_variable(1.0, law)

    # Now add it twice to verify that it overwrites it
    p1.add_auxiliary_variable(x, law)
    p1.add_auxiliary_variable(x, law)

    p1.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:41,代码来源:test_parameter.py

示例14: test_remove_auxiliary_variable

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_remove_auxiliary_variable():

    p1 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV')

    x = Parameter('aux_variable', 1.0)

    # ax + b

    law = Line()
    law.a = 1.0
    law.b = 2.0

    p1.add_auxiliary_variable(x, law)

    assert p1.value == 3.0

    x.value = 4.0

    assert p1.value == 6.0

    p1.remove_auxiliary_variable()

    assert p1.has_auxiliary_variable() == False

    p1.value = -1.0

    assert p1.value == -1.0

    with pytest.warns(RuntimeWarning):

        p1.remove_auxiliary_variable() 
开发者ID:threeML,项目名称:astromodels,代码行数:33,代码来源:test_parameter.py

示例15: test_to_dict

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import MeV [as 别名]
def test_to_dict():

    p1 = IndependentVariable('time', 1.0, min_value=-5.0, max_value=5.0, desc='test', unit='MeV')

    repr = p1.to_dict(minimal=False)

    assert len(list(repr.keys())) == 5

    repr2 = p1.to_dict(minimal=True)

    assert len(list(repr2.keys())) == 1
    assert 'value' in repr2

    assert repr2['value'] == p1.value

    p = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0,
                   delta=0.2, desc='test', free=False, unit='MeV')

    p.to_dict()
    p.to_dict(minimal=True)

    p = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0,
                  delta=0.2, desc='test', free=False, unit='MeV', prior=Log_uniform_prior())

    p.to_dict()
    p.to_dict(minimal=True) 
开发者ID:threeML,项目名称:astromodels,代码行数:28,代码来源:test_parameter.py


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