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

Python netcdftime.datetime函数代码示例

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

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



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

示例1: test_vector_lbft

 def test_vector_lbft(self):
     field = self._field()
     field.lbtim = 21
     field.t1 = netcdftime.datetime(1970, 1, 1, 12)
     field.t2 = netcdftime.datetime(1970, 1, 1, 18)
     lbft = ([18, 15, 12], [0])
     collation = mock.Mock(fields=[field], vector_dims_shape=(3,),
                           element_arrays_and_dims={'lbft': lbft})
     metadata = convert_collation(collation)
     self._check_phenomenon(metadata)
     coords_and_dims = [(LONGITUDE, 2),
                        (LATITUDE, 1),
                        (iris.coords.DimCoord([0, 3, 6],
                                              'forecast_reference_time',
                                              units='hours since epoch'),
                         (0,))]
     coords_and_dims = [
         (iris.coords.DimCoord(15, 'time', units='hours since epoch',
                               bounds=[[12, 18]]), None),
         (iris.coords.DimCoord([15, 12, 9], 'forecast_period',
                               units='hours',
                               bounds=[[12, 18], [9, 15], [6, 12]]),
          (0,))
     ]
     self.assertEqual(metadata.aux_coords_and_dims, coords_and_dims)
开发者ID:jcmt,项目名称:iris,代码行数:25,代码来源:test__convert_collation.py


示例2: test_vector_t2

 def test_vector_t2(self):
     field = self._field()
     field.lbtim = 11
     field.t1 = netcdftime.datetime(1970, 1, 1, 18)
     t2 = (
         [
             netcdftime.datetime(1970, 1, 1, 12),
             netcdftime.datetime(1970, 1, 1, 15),
             netcdftime.datetime(1970, 1, 1, 18),
         ],
         [0],
     )
     collation = mock.Mock(fields=[field], vector_dims_shape=(3,), element_arrays_and_dims={"t2": t2})
     metadata = convert_collation(collation)
     self._check_phenomenon(metadata)
     coords_and_dims = [
         (LONGITUDE, 2),
         (LATITUDE, 1),
         (iris.coords.DimCoord([12, 15, 18], "forecast_reference_time", units="hours since epoch"), (0,)),
     ]
     self.assertEqual(metadata.dim_coords_and_dims, coords_and_dims)
     coords_and_dims = [
         (iris.coords.DimCoord(18, "time", units="hours since epoch"), None),
         (iris.coords.DimCoord([6, 3, 0.0], "forecast_period", units="hours"), (0,)),
     ]
     self.assertEqual(metadata.aux_coords_and_dims, coords_and_dims)
开发者ID:Jozhogg,项目名称:iris,代码行数:26,代码来源:test__convert_collation.py


示例3: test_vector_t1

 def test_vector_t1(self):
     field = self._field()
     field.lbtim = 11
     field.t2 = netcdftime.datetime(1970, 1, 1, 12)
     t1 = ([netcdftime.datetime(1970, 1, 1, 18),
            netcdftime.datetime(1970, 1, 2, 0),
            netcdftime.datetime(1970, 1, 2, 6)], [0])
     collation = mock.Mock(fields=[field], vector_dims_shape=(3,),
                           element_arrays_and_dims={'t1': t1})
     metadata = convert_collation(collation)
     self._check_phenomenon(metadata)
     coords_and_dims = [(LONGITUDE, 2),
                        (LATITUDE, 1),
                        (iris.coords.DimCoord([18, 24, 30], 'time',
                                              units='hours since epoch'),
                         (0,))
                        ]
     self.assertEqual(metadata.dim_coords_and_dims, coords_and_dims)
     coords_and_dims = [
         (iris.coords.DimCoord(12, 'forecast_reference_time',
                               units='hours since epoch'), None),
         (iris.coords.DimCoord([6, 12, 18], 'forecast_period',
                               units='hours'), (0,))
     ]
     self.assertEqual(metadata.aux_coords_and_dims, coords_and_dims)
开发者ID:jcmt,项目名称:iris,代码行数:25,代码来源:test__convert_collation.py


示例4: test_vector_t1_and_t2

 def test_vector_t1_and_t2(self):
     field = self._field()
     field.lbtim = 11
     t1 = ([netcdftime.datetime(1970, 1, 2, 6),
            netcdftime.datetime(1970, 1, 2, 9),
            netcdftime.datetime(1970, 1, 2, 12)], [1])
     t2 = ([netcdftime.datetime(1970, 1, 1, 12),
            netcdftime.datetime(1970, 1, 2, 0)], [0])
     collation = mock.Mock(fields=[field], vector_dims_shape=(2, 3),
                           element_arrays_and_dims={'t1': t1, 't2': t2})
     metadata = convert_collation(collation)
     self._check_phenomenon(metadata)
     coords_and_dims = [(LONGITUDE, 3),
                        (LATITUDE, 2),
                        (iris.coords.DimCoord([30, 33, 36], 'time',
                                              units='hours since epoch'),
                         (1,)),
                        (iris.coords.DimCoord([12, 24],
                                              'forecast_reference_time',
                                              units='hours since epoch'),
                         (0,))]
     self.assertEqual(metadata.dim_coords_and_dims, coords_and_dims)
     coords_and_dims = [
         (iris.coords.AuxCoord([[18, 21, 24], [6, 9, 12]],
                               'forecast_period', units='hours'), (0, 1))
     ]
     self.assertEqual(metadata.aux_coords_and_dims, coords_and_dims)
开发者ID:jcmt,项目名称:iris,代码行数:27,代码来源:test__convert_collation.py


示例5: harmonize_hourly_timestamp

def harmonize_hourly_timestamp(time_range, dt):
    '''
    Adjust the ``time_range`` by setting hour value to datetime.datetime objects.
    
    :param time_range: time range selected by user   
    :type time_range: list of two datetime.datetime objects
    
    :param dt: any datetime step of input datetime vector
    :type dt: datetime.datetime object
    
    :rtype: list of two datetime.datetime objects
    
    WHY:
    if input time steps vector is from 1990-01-01 12:00 to 2000-12-31 12:00,
    and user's time_range is [datetime.datetime(1900, 1, 1), datetime.datetime(1905, 12, 31)],
    i.e. [datetime.datetime(1900, 1, 1, 0, 0), datetime.datetime(1905, 12, 31, 0, 0)],
    it will be not included in the input time steps (there will be the error message "The time range is not included in the input time steps array.").
    Thus, this function will adjust the hour of the user's time_range: [datetime.datetime(1900, 1, 1, 12, 0), datetime.datetime(1905, 12, 31, 12, 0)]

    '''

#     time_range_begin = datetime(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
#     time_range_end = datetime(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)

    time_range_begin = netcdftime.datetime(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
    time_range_end = netcdftime.datetime(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)
    
    return [time_range_begin, time_range_end]
开发者ID:andrejsim,项目名称:icclim,代码行数:28,代码来源:util_dt.py


示例6: test_365_day_calendar

 def test_365_day_calendar(self):
     unit = Unit('minutes since 2000-02-25 00:00:00', calendar='365_day')
     coord = AuxCoord([30, 60, 150], 'time', units=unit)
     result = _fixup_dates(coord, coord.points)
     expected_datetimes = [netcdftime.datetime(2000, 2, 25, 0, 30),
                           netcdftime.datetime(2000, 2, 25, 1, 0),
                           netcdftime.datetime(2000, 2, 25, 2, 30)]
     self.assertArrayEqual([cdt.datetime for cdt in result],
                           expected_datetimes)
开发者ID:cpelley,项目名称:iris,代码行数:9,代码来源:test__fixup_dates.py


示例7: test_t1

 def test_t1(self):
     collation = FieldCollation([_make_field(lbyr=2013),
                                 _make_field(lbyr=2014)])
     result = collation.element_arrays_and_dims
     self.assertEqual(list(result.keys()), ['t1'])
     values, dims = result['t1']
     self.assertArrayEqual(values, [datetime(2013, 1, 1),
                                    datetime(2014, 1, 1)])
     self.assertEqual(dims, (0,))
开发者ID:Jozhogg,项目名称:iris,代码行数:9,代码来源:test_FieldCollation.py


示例8: test_axis_default_limits

 def test_axis_default_limits(self):
     cal = '360_day'
     unit = (cal, 'days since 2000-02-25 00:00:00')
     result = NetCDFTimeConverter().axisinfo(unit, None)
     expected_dt = [netcdftime.datetime(2000, 1, 1),
                    netcdftime.datetime(2010, 1, 1)]
     np.testing.assert_array_equal(
         result.default_limits,
         [CalendarDateTime(edt, cal) for edt in expected_dt])
开发者ID:djkirkham,项目名称:nc-time-axis,代码行数:9,代码来源:test_NetCDFTimeConverter.py


示例9: test_data_frame_netcdftime_360

 def test_data_frame_netcdftime_360(self):
     data_frame = pandas.DataFrame(
         [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]],
         index=[netcdftime.datetime(2001, 1, 1, 1, 1, 1), netcdftime.datetime(2002, 2, 2, 2, 2, 2)],
         columns=[10, 11, 12, 13, 14],
     )
     self.assertCML(
         iris.pandas.as_cube(data_frame, calendars={0: cf_units.CALENDAR_360_DAY}),
         tests.get_result_path(("pandas", "as_cube", "data_frame_netcdftime_360.cml")),
     )
开发者ID:fionaRust,项目名称:iris,代码行数:10,代码来源:test_pandas.py


示例10: test_data_frame_netcdftime_360

 def test_data_frame_netcdftime_360(self):
     data_frame = pandas.DataFrame(
         [[0, 1, 2, 3, 4],
          [5, 6, 7, 8, 9]],
         index=[netcdftime.datetime(2001, 01, 01, 01, 01, 01),
                netcdftime.datetime(2002, 02, 02, 02, 02, 02)],
         columns=[10, 11, 12, 13, 14])
     self.assertCML(
         iris.pandas.as_cube(
             data_frame,
             calendars={0: iris.unit.CALENDAR_360_DAY}),
         tests.get_result_path(('pandas', 'as_cube',
                                'data_frame_netcdftime_360.cml')))
开发者ID:RachelNorth,项目名称:iris,代码行数:13,代码来源:test_pandas.py


示例11: test_series_netcdftime_360

 def test_series_netcdftime_360(self):
     series = pandas.Series(
         [0, 1, 2, 3, 4],
         index=[netcdftime.datetime(2001, 1, 1, 1, 1, 1),
                netcdftime.datetime(2002, 2, 2, 2, 2, 2),
                netcdftime.datetime(2003, 3, 3, 3, 3, 3),
                netcdftime.datetime(2004, 4, 4, 4, 4, 4),
                netcdftime.datetime(2005, 5, 5, 5, 5, 5)])
     self.assertCML(
         iris.pandas.as_cube(series,
                             calendars={0: cf_units.CALENDAR_360_DAY}),
         tests.get_result_path(('pandas', 'as_cube',
                                'series_netcdfimte_360.cml')))
开发者ID:cpelley,项目名称:iris,代码行数:13,代码来源:test_pandas.py


示例12: harmonize_hourly_timestamp

def harmonize_hourly_timestamp(time_range, calend, dt):
    '''
    Adjust the ``time_range`` by setting hour value to datetime.datetime objects.
    
    :param time_range: time range selected by user   
    :type time_range: list of two datetime.datetime objects
    
    :param dt: any datetime step of input datetime vector
    :type dt: datetime.datetime object
    
    :param calend: calendar attribute of variable "time" in netCDF file
    :type calend: str

    :rtype: list of two datetime.datetime objects
    
    WHY:
    if input time steps vector is from 1990-01-01 12:00 to 2000-12-31 12:00,
    and user's time_range is [datetime.datetime(1900, 1, 1), datetime.datetime(1905, 12, 31)],
    i.e. [datetime.datetime(1900, 1, 1, 0, 0), datetime.datetime(1905, 12, 31, 0, 0)],
    it will be not included in the input time steps (there will be the error message "The time range is not included in the input time steps array.").
    Thus, this function will adjust the hour of the user's time_range: [datetime.datetime(1900, 1, 1, 12, 0), datetime.datetime(1905, 12, 31, 12, 0)]

    '''

#     time_range_begin = datetime(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
#     time_range_end = datetime(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)

    if calend == 'noleap' or calend == '365_day':
        time_range_begin = netcdftime._netcdftime.DatetimeNoLeap(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
        time_range_end = netcdftime._netcdftime.DatetimeNoLeap(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)
    elif calend == '360_day':
        time_range_begin = netcdftime._netcdftime.Datetime360Day(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
        time_range_end = netcdftime._netcdftime.Datetime360Day(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)
    elif calend == 'gregorian':
        time_range_begin = netcdftime._netcdftime.DatetimeGregorian(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
        time_range_end = netcdftime._netcdftime.DatetimeGregorian(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)
    elif calend == 'proleptic_gregorian':
        time_range_begin = netcdftime._netcdftime.DatetimeProlepticGregorian(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
        time_range_end = netcdftime._netcdftime.DatetimeProlepticGregorian(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)
    elif calend == 'julian':
        time_range_begin = netcdftime._netcdftime.DatetimeJulian(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
        time_range_end = netcdftime._netcdftime.DatetimeJulian(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)
    elif calend == 'all_leap' or calend == '366_day':
        time_range_begin = netcdftime._netcdftime.DatetimeAllLeap(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
        time_range_end = netcdftime._netcdftime.DatetimeAllLeap(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)
    else:
        time_range_begin = netcdftime.datetime(time_range[0].year, time_range[0].month, time_range[0].day, dt.hour)
        time_range_end = netcdftime.datetime(time_range[1].year, time_range[1].month, time_range[1].day, dt.hour)

    return [time_range_begin, time_range_end]
开发者ID:cerfacs-globc,项目名称:icclim,代码行数:50,代码来源:util_dt.py


示例13: test_time_360

 def test_time_360(self):
     cube = Cube(np.array([0, 1, 2, 3, 4]), long_name="ts")
     time_unit = cf_units.Unit("days since 2000-01-01 00:00",
                               calendar=cf_units.CALENDAR_360_DAY)
     time_coord = DimCoord([0, 100.1, 200.2, 300.3, 400.4],
                           long_name="time", units=time_unit)
     cube.add_dim_coord(time_coord, 0)
     expected_index = [netcdftime.datetime(2000, 1, 1, 0, 0),
                       netcdftime.datetime(2000, 4, 11, 2, 24),
                       netcdftime.datetime(2000, 7, 21, 4, 48),
                       netcdftime.datetime(2000, 11, 1, 7, 12),
                       netcdftime.datetime(2001, 2, 11, 9, 36)]
     series = iris.pandas.as_series(cube)
     self.assertArrayEqual(series, cube.data)
     self.assertArrayEqual(series.index, expected_index)
开发者ID:djkirkham,项目名称:iris,代码行数:15,代码来源:test_pandas.py


示例14: _fixup_dates

def _fixup_dates(coord, values):
    if coord.units.calendar is not None and values.ndim == 1:
        # Convert coordinate values into tuples of
        # (year, month, day, hour, min, sec)
        dates = [coord.units.num2date(val).timetuple()[0:6]
                 for val in values]
        if coord.units.calendar == 'gregorian':
            r = [datetime.datetime(*date) for date in dates]
        else:
            try:
                import nc_time_axis
            except ImportError:
                msg = ('Cannot plot against time in a non-gregorian '
                       'calendar, because "nc_time_axis" is not available :  '
                       'Install the package from '
                       'https://github.com/SciTools/nc-time-axis to enable '
                       'this usage.')
                raise IrisError(msg)

            r = [nc_time_axis.CalendarDateTime(
                 netcdftime.datetime(*date), coord.units.calendar)
                 for date in dates]
        values = np.empty(len(r), dtype=object)
        values[:] = r
    return values
开发者ID:bjlittle,项目名称:iris,代码行数:25,代码来源:plot.py


示例15: test_all_scalar

 def test_all_scalar(self):
     field = self._field()
     field.lbtim = 11
     field.t1 = netcdftime.datetime(1970, 1, 1, 18)
     field.t2 = netcdftime.datetime(1970, 1, 1, 12)
     collation = mock.Mock(fields=[field], vector_dims_shape=(), element_arrays_and_dims={})
     metadata = convert_collation(collation)
     self._check_phenomenon(metadata)
     coords_and_dims = [(LONGITUDE, 1), (LATITUDE, 0)]
     self.assertEqual(metadata.dim_coords_and_dims, coords_and_dims)
     coords_and_dims = [
         (iris.coords.DimCoord(18, "time", units="hours since epoch"), None),
         (iris.coords.DimCoord(12, "forecast_reference_time", units="hours since epoch"), None),
         (iris.coords.DimCoord(6, "forecast_period", units="hours"), None),
     ]
     self.assertEqual(metadata.aux_coords_and_dims, coords_and_dims)
开发者ID:Jozhogg,项目名称:iris,代码行数:16,代码来源:test__convert_collation.py


示例16: axisinfo

    def axisinfo(unit, axis):
        """
        Return the :class:`~matplotlib.units.AxisInfo` for *unit*.

        *unit* is a tzinfo instance or None.
        The *axis* argument is required but not used.
        """
        calendar, date_unit = unit

        majloc = NetCDFTimeDateLocator(4, calendar=calendar, date_unit=date_unit)
        majfmt = NetCDFTimeDateFormatter(majloc, calendar=calendar, time_units=date_unit)
        datemin = netcdftime.datetime(2000, 1, 1)
        datemax = netcdftime.datetime(2010, 1, 1)
        datemin.calendar = datemax.calendar = calendar
        return munits.AxisInfo(majloc=majloc, majfmt=majfmt, label='Testing',
                               default_limits=(datemin, datemax))
开发者ID:bjlittle,项目名称:nc-time-axis,代码行数:16,代码来源:__init__.py


示例17: test_netcdftime_other

 def test_netcdftime_other(self):
     # Check that cell comparison to a netcdftime.datetime object
     # raises an exception otherwise this will fall back to id comparison
     # producing unreliable results.
     dt = netcdftime.datetime(2010, 3, 21)
     cell = Cell(mock.Mock(timetuple=mock.Mock()))
     self.assert_raises_on_comparison(cell, dt, TypeError, "determine the order of netcdftime")
开发者ID:scollis,项目名称:iris,代码行数:7,代码来源:test_Cell.py


示例18: test_360_day_calendar

 def test_360_day_calendar(self):
     calendar = '360_day'
     unit = 'days since 2000-01-01'
     val = [netcdftime.datetime(2014, 8, 12)]
     val[0].calendar = calendar
     result = NetCDFTimeConverter().default_units(val, None)
     self.assertEqual(result, (calendar, unit))
开发者ID:bjlittle,项目名称:nc-time-axis,代码行数:7,代码来源:test_NetCDFTimeConverter.py


示例19: test_360_day_calendar

 def test_360_day_calendar(self):
     datetimes = [netcdftime.datetime(1986, month, 30)
                  for month in range(1, 6)]
     cal_datetimes = [nc_time_axis.CalendarDateTime(dt, '360_day')
                      for dt in datetimes]
     line1, = plt.plot(cal_datetimes)
     result_ydata = line1.get_ydata()
     np.testing.assert_array_equal(result_ydata, cal_datetimes)
开发者ID:djkirkham,项目名称:nc-time-axis,代码行数:8,代码来源:test_plot.py


示例20: test_PartialDateTime_unbounded_cell

 def test_PartialDateTime_unbounded_cell(self):
     # Check that cell comparison works with PartialDateTimes.
     dt = PartialDateTime(month=6)
     cell = Cell(netcdftime.datetime(2010, 3, 1))
     self.assertLess(cell, dt)
     self.assertGreater(dt, cell)
     self.assertLessEqual(cell, dt)
     self.assertGreaterEqual(dt, cell)
开发者ID:MahatmaCane,项目名称:iris,代码行数:8,代码来源:test_Cell.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python netcdftime.nc_datetime函数代码示例发布时间:2022-05-27
下一篇:
Python netaddr.IPSet类代码示例发布时间: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