• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python units.unit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中units.unit函数的典型用法代码示例。如果您正苦于以下问题:Python unit函数的具体用法?Python unit怎么用?Python unit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_rmultiply_named_scalar

def test_rmultiply_named_scalar():
    """Scalars * Named quantities"""
    m_per_s = NamedComposedUnit('vel', 
                                unit('m') / unit('s'))

    assert (2 * Quantity(8, m_per_s) ==
            Quantity(16, m_per_s))
开发者ID:JerichoKain,项目名称:biscotti,代码行数:7,代码来源:test_simple_multiply_divide.py


示例2: test_divide_named_scalar

def test_divide_named_scalar():
    """Named quantities / scalars"""
    m_per_s = NamedComposedUnit('vel', 
                                unit('m') / unit('s'))

    assert (Quantity(8, m_per_s) / 2 ==
            Quantity(4, m_per_s))
开发者ID:JerichoKain,项目名称:biscotti,代码行数:7,代码来源:test_simple_multiply_divide.py


示例3: test_multiply_named_scalar

def test_multiply_named_scalar():
    """Named quantities * scalars"""
    m_per_s = NamedComposedUnit('vel', 
                                unit('m') / unit('s'))
    
    assert (Quantity(8, m_per_s) * 2 ==
            Quantity(16, m_per_s))
开发者ID:JerichoKain,项目名称:biscotti,代码行数:7,代码来源:test_simple_multiply_divide.py


示例4: test_valid_basic_to_composed

def test_valid_basic_to_composed():
    """Test conversion to composed units."""
    composed_cm = unit('cm').composed_unit
    
    one_m_in_cm = composed_cm(Quantity(1, unit('m')))
    
    assert one_m_in_cm == Quantity(1, unit('m'))
开发者ID:Manduka,项目名称:python-units,代码行数:7,代码来源:test_conversion.py


示例5: test_rdivide_named_scalar

def test_rdivide_named_scalar():
    """Scalars / Named quantities"""
    m_per_s = NamedComposedUnit('vel', 
                                unit('m') / unit('s'))

    assert (4 / Quantity(2, m_per_s) ==
            Quantity(2, unit('s') / unit('m')))
开发者ID:JerichoKain,项目名称:biscotti,代码行数:7,代码来源:test_simple_multiply_divide.py


示例6: test_valid_composed_to_basic

def test_valid_composed_to_basic():
    """Composed units should convert to basic equivalents."""
    metre = unit('m')
    
    hundred_cm_in_metres = metre(Quantity(100, unit('cm')))
    assert hundred_cm_in_metres == Quantity(1.0, metre)
    assert str(hundred_cm_in_metres) == '1.0 m'
开发者ID:Manduka,项目名称:python-units,代码行数:7,代码来源:test_conversion.py


示例7: test_valid_basic_to_named

def test_valid_basic_to_named():
    """Basic units should convert into named equivalents."""
    metre = unit('m')
    thousand_m_in_km = unit('km')(Quantity(1000, metre))
    
    assert thousand_m_in_km == Quantity(1, unit('km'))
    assert thousand_m_in_km.unit == unit('km')
    assert str(thousand_m_in_km) == '1 km'
开发者ID:Manduka,项目名称:python-units,代码行数:8,代码来源:test_conversion.py


示例8: test_valid_named_to_named

def test_valid_named_to_named():
    """Named units should convert to named equivalents."""
    
    gray = unit('Gy')
    sievert = unit('Sv')
    
    one_gray_in_sievert = sievert(Quantity(1, gray))
    assert one_gray_in_sievert == Quantity(1, gray)
    assert str(one_gray_in_sievert) == '1 Sv'
开发者ID:Manduka,项目名称:python-units,代码行数:9,代码来源:test_conversion.py


示例9: define_imperial_units

def define_imperial_units():
    """Define some common imperial units."""

    assert unit("m").is_si()  # Ensure SI units already defined

    # scaled_unit measures
    scaled_unit("inch", "cm", 2.54, name="inch")
    scaled_unit("in", "cm", 2.54, name="inch")  # 'in' is a python keyword
    scaled_unit("ft", "inch", 12.0, name="foot")
    scaled_unit("yd", "ft", 3.0, name="yard")
    scaled_unit("fm", "ft", 6.0, name="fathom")
    scaled_unit("rd", "yd", 5.5, name="rod")
    scaled_unit("fur", "rd", 40.0, name="furlong")
    scaled_unit("mi", "fur", 8.0, name="mile")
    scaled_unit("lea", "mi", 3.0, name="leage")

    # nautical scaled_unit measures
    scaled_unit("NM", "m", 1852.0, name="nautical mile")
    scaled_unit("cable", "NM", 0.1, name="cable length")

    # chain measure
    scaled_unit("li", "inch", 7.92, name="link")
    scaled_unit("ch", "li", 100.0, name="chain")

    # area measure
    NamedComposedUnit("acre", ComposedUnit([unit("rd")] * 2, [], 160.0), name="acre")

    # liquid measures
    NamedComposedUnit("pt", ComposedUnit([unit("inch")] * 3, [], 28.875), name="pint")

    scaled_unit("gi", "pt", 0.25, name="gills")
    scaled_unit("qt", "pt", 2.0, name="quarts")
    scaled_unit("gal", "qt", 4.0, name="gallons")

    scaled_unit("fl oz", "pt", 1.0 / 16.0, name="fluid ounce")
    scaled_unit("fl dr", "fl oz", 1.0 / 8.0, name="fluid drachm")
    scaled_unit("minim", "fl dr", 1.0 / 60.0, name="minim")

    # weight
    scaled_unit("oz", "g", 28.375, name="ounce")
    scaled_unit("lb", "oz", 16.0, name="pound")
    scaled_unit("ton", "lb", 2000.0, name="ton")
    scaled_unit("grain", "lb", 1.0 / 7000.0, name="grain")
    scaled_unit("dr", "lb", 1.0 / 256.0, name="dram")
    scaled_unit("cwt", "lb", 100.0, name="hundredweight")

    scaled_unit("dwt", "grain", 24.0, name="pennyweight")
    scaled_unit("oz t", "dwt", 20.0, name="ounce troy")
    scaled_unit("lb t", "oz t", 12.0, name="pound troy")

    # power
    scaled_unit("hpl", "W", 746.9999, name="mechanical")
    scaled_unit("hpm", "W", 735.49875, name="metric horsepower")
    scaled_unit("hpe", "W", 746.0, name="electric horsepower")

    # energy
    scaled_unit("BTU", "J", 1055.056, name="ISO BTU", is_si=True)
开发者ID:cuker,项目名称:python-units,代码行数:57,代码来源:predefined.py


示例10: test_volume

def test_volume():
    """Volume units should interchange correctly with cubed area units."""
    litres = unit('L')
    millilitres = unit('mL')
    centimetres = unit('cm')
    cm_cubed = centimetres * centimetres * centimetres
    
    assert Quantity(1, litres) == Quantity(1000, millilitres)
    assert Quantity(1, millilitres) == Quantity(1, cm_cubed)
开发者ID:Manduka,项目名称:python-units,代码行数:9,代码来源:test_predefined.py


示例11: test_valid_named_to_basic

def test_valid_named_to_basic():
    """Named units should convert to their basic equivalents"""
    
    kilometre = unit('km')
    one_km_in_m = unit('m')(Quantity(1, kilometre))
    
    assert one_km_in_m == Quantity(1000, unit('m'))
    assert one_km_in_m.unit == unit('m')
    assert str(one_km_in_m) == '1000 m'
开发者ID:Manduka,项目名称:python-units,代码行数:9,代码来源:test_conversion.py


示例12: setUp

 def setUp(self):
     self.laminate = CathodeLaminate(mass_active_material=0.9,
                                     mass_carbon=0.05,
                                     mass_binder=0.05,
                                     name="LMO-NEI")
     self.electrode = CoinCellElectrode(total_mass=unit('mg')(15),
                                        substrate_mass=unit('mg')(5),
                                        laminate=self.laminate,
                                        name="DummyElectrode",
                                        diameter=unit('mm')(12.7))
开发者ID:m3wolf,项目名称:scimap-tests,代码行数:10,代码来源:test_electrochem.py


示例13: test_composed_unit_repr

def test_composed_unit_repr():
    """Developer-friendly string representation of composed units."""
    
    test_repr = (repr(unit('m') * unit('g') / unit('s')))
    
    # non-deterministic
    assert test_repr in [
        "ComposedUnit([LeafUnit('g', True), " + "LeafUnit('m', True)], " + "[LeafUnit('s', True)], 1)",
        "ComposedUnit([LeafUnit('m', True), " + "LeafUnit('g', True)], " + "[LeafUnit('s', True)], 1)"
    ]
开发者ID:Manduka,项目名称:python-units,代码行数:10,代码来源:test_string_reps.py


示例14: test_good_named_add_w_mult

def test_good_named_add_w_mult():
    """A quantity with a named composed unit that carries a multiplier 
    should add to a composed unit that has a multiplier"""
    
    mile = unit('mi').composed_unit
    kilometre = unit('km')
                                               
    assert within_epsilon(Quantity(1, mile) + Quantity(1, kilometre), 
                          Quantity(1, kilometre) + Quantity(1, mile))
    assert within_epsilon(Quantity(2609.344, unit('m')),
                          Quantity(1, kilometre) + Quantity(1, mile))
开发者ID:JerichoKain,项目名称:biscotti,代码行数:11,代码来源:test_simple_add_subtract.py


示例15: test_good_named_add_w_mults

def test_good_named_add_w_mults():
    """Two quantities with compatible but differently-named and 
    differently-multiplied units should add together."""
    
    mile = unit('mi')
    kilometre = unit('km')
    
    assert within_epsilon(Quantity(1, mile) + Quantity(1, kilometre),
                          Quantity(1, kilometre) + Quantity(1, mile))
    assert within_epsilon(Quantity(2609.344, unit('m')),
                          Quantity(1, kilometre) + Quantity(1, mile))
开发者ID:JerichoKain,项目名称:biscotti,代码行数:11,代码来源:test_simple_add_subtract.py


示例16: ConvertElectricFieldAtomicFromIntensitySI

    def ConvertElectricFieldAtomicFromIntensitySI(self, intensity):
        """
        Intensity [W/cm**2] -> E-field strength [a.u.]

        Relation obtained from time-averaging over one cycle,

          E0 = sqrt( (2 <I>) / (eps0 * c) )

        """
        watt_per_squarecm = unit('W') / unit('cm')**2
        val = sqrt(2.0 * intensity / (self.electrostatic_constant.squeeze() /
                (4*pi) * self.lightspeed))
        return val * 100.0 / self.electric_field_strength.squeeze()
开发者ID:nepstad,项目名称:atomic-units,代码行数:13,代码来源:unit_converter.py


示例17: test_read_current

 def test_read_current(self):
     run = GalvanostatRun(mptfile)
     # These are practically equal but assertEqual fails due to rounding in units package
     self.assertApproximatelyEqual(
         run.charge_current,
         unit('mA')(0.33570),
         tolerance=10**-15
     )
     self.assertApproximatelyEqual(
         run.discharge_current,
         unit('mA')(-335.70),
         tolerance=10**-15
     )
开发者ID:m3wolf,项目名称:scimap-tests,代码行数:13,代码来源:test_electrochem.py


示例18: test_valid_composed_to_composed

def test_valid_composed_to_composed():
    """Valid composed units in terms of others."""
    metric_vel = unit('km') / unit('h')
    imp_vel = unit('mi') / unit('h')
    
    highway_kph = Quantity(100, metric_vel)
    highway_mph = Quantity(62.1371192237334, imp_vel)
    
    assert str(highway_kph) == '100 km / h'
    assert str(highway_mph) == '62.1371192237 mi / h'
    
    assert within_epsilon(imp_vel(highway_kph), highway_mph)
    
    assert str(imp_vel(highway_kph)) == '62.1371192237 mi / h'
开发者ID:Manduka,项目名称:python-units,代码行数:14,代码来源:test_conversion.py


示例19: define_computer_units

def define_computer_units():
    """Define some units for technology.
    
    >>> define_units()
    >>> unit('GiB')(200) > unit('GB')(200) # bastard marketers
    True
    """

    NamedComposedUnit("flop", unit("operation") / unit("s"), name="flop", is_si=True)
    scaled_unit("B", "bit", 8.0, name="byte", is_si=True)
    scaled_unit("KiB", "B", 1024.0, name="kilobyte")
    scaled_unit("MiB", "KiB", 1024.0, name="megabyte")
    scaled_unit("GiB", "MiB", 1024.0, name="gigabyte")
    scaled_unit("TiB", "GiB", 1024.0, name="terabyte")
    scaled_unit("PiB", "TiB", 1024.0, name="petabyte")
开发者ID:cuker,项目名称:python-units,代码行数:15,代码来源:predefined.py


示例20: test_good_sub_w_mults

def test_good_sub_w_mults():
    """Two quantities with compatible units should sub together 
    even when they have different multipliers"""
    
    mile = unit('mi').composed_unit
    kilometre = unit('km').composed_unit   
    
    m_on_left = Quantity(1, mile) - Quantity(1, kilometre)
    km_on_left = Quantity(1, kilometre) - Quantity(1, mile)
    m_on_left_diff = Quantity(609.344, unit('m'))
    km_on_left_diff = Quantity(-609.344, unit('m'))
            
    assert within_epsilon(m_on_left, m_on_left_diff)
    assert within_epsilon(km_on_left, km_on_left_diff)
    assert within_epsilon(m_on_left_diff, -km_on_left_diff)
开发者ID:JerichoKain,项目名称:biscotti,代码行数:15,代码来源:test_simple_add_subtract.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.set_module_args函数代码示例发布时间:2022-05-27
下一篇:
Python _testing._Monkey函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap