cf.Data.change_calendar¶
-
Data.
change_calendar
(calendar, inplace=False, i=False)[source]¶ Change the calendar of date-time array elements.
Reinterprets the existing date-times for the new calendar by adjusting the underlying numerical values relative to the reference date-time defined by the units.
If a date-time value is not allowed in the new calendar then an exception is raised when the data array is accessed.
See also
- Parameters
- Returns
Examples
>>> d = cf.Data([0, 1, 2, 3, 4], 'days since 2004-02-27') >>> print(d.array) [0 1 2 3 4] >>> print(d.datetime_as_string) ['2004-02-27 00:00:00' '2004-02-28 00:00:00' '2004-02-29 00:00:00' '2004-03-01 00:00:00' '2004-03-02 00:00:00'] >>> e = d.change_calendar('360_day') >>> print(e.array) [0 1 2 4 5] >>> print(e.datetime_as_string) ['2004-02-27 00:00:00' '2004-02-28 00:00:00' '2004-02-29 00:00:00' '2004-03-01 00:00:00' '2004-03-02 00:00:00']
>>> d.change_calendar('noleap').array Traceback (most recent call last): ... ValueError: invalid day number provided in cftime.DatetimeNoLeap(2004, 2, 29, 0, 0, 0, 0, has_year_zero=True)