本文整理汇总了Python中cf_units.Unit.convert方法的典型用法代码示例。如果您正苦于以下问题:Python Unit.convert方法的具体用法?Python Unit.convert怎么用?Python Unit.convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cf_units.Unit
的用法示例。
在下文中一共展示了Unit.convert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gregorian_calendar_conversion_setup
# 需要导入模块: from cf_units import Unit [as 别名]
# 或者: from cf_units.Unit import convert [as 别名]
def test_gregorian_calendar_conversion_setup(self):
# Reproduces a situation where a unit's gregorian calendar would not
# match (using the `is` operator) to the literal string 'gregorian',
# causing an `is not` test to return a false negative.
cal_str = cf_units.CALENDAR_GREGORIAN
calendar = self.MyStr(cal_str)
self.assertIsNot(calendar, cal_str)
u1 = Unit('hours since 1970-01-01 00:00:00', calendar=calendar)
u2 = Unit('hours since 1969-11-30 00:00:00', calendar=calendar)
u1point = np.array([8.], dtype=np.float32)
expected = np.array([776.], dtype=np.float32)
result = u1.convert(u1point, u2)
return expected, result
示例2: test_non_gregorian_calendar_conversion_dtype
# 需要导入模块: from cf_units import Unit [as 别名]
# 或者: from cf_units.Unit import convert [as 别名]
def test_non_gregorian_calendar_conversion_dtype(self):
data = np.arange(4, dtype=np.float32)
u1 = Unit('hours since 2000-01-01 00:00:00', calendar='360_day')
u2 = Unit('hours since 2000-01-02 00:00:00', calendar='360_day')
result = u1.convert(data, u2)
self.assertEqual(result.dtype, np.float32)