Convert the Dataset to another calendar. Only converts the individual timestamps, does not modify any data except in dropping invalid/surplus dates or inserting missing dates. If the source and target calendars are either no_leap, all_leap or a standard type, only t
(
self,
calendar: CFCalendar,
dim: Hashable = "time",
align_on: Literal["date", "year"] | None = None,
missing: Any | None = None,
use_cftime: bool | None = None,
)
| 9956 | return self.isel(indexes) |
| 9957 | |
| 9958 | def convert_calendar( |
| 9959 | self, |
| 9960 | calendar: CFCalendar, |
| 9961 | dim: Hashable = "time", |
| 9962 | align_on: Literal["date", "year"] | None = None, |
| 9963 | missing: Any | None = None, |
| 9964 | use_cftime: bool | None = None, |
| 9965 | ) -> Self: |
| 9966 | """Convert the Dataset to another calendar. |
| 9967 | |
| 9968 | Only converts the individual timestamps, does not modify any data except |
| 9969 | in dropping invalid/surplus dates or inserting missing dates. |
| 9970 | |
| 9971 | If the source and target calendars are either no_leap, all_leap or a |
| 9972 | standard type, only the type of the time array is modified. |
| 9973 | When converting to a leap year from a non-leap year, the 29th of February |
| 9974 | is removed from the array. In the other direction the 29th of February |
| 9975 | will be missing in the output, unless `missing` is specified, |
| 9976 | in which case that value is inserted. |
| 9977 | |
| 9978 | For conversions involving `360_day` calendars, see Notes. |
| 9979 | |
| 9980 | This method is safe to use with sub-daily data as it doesn't touch the |
| 9981 | time part of the timestamps. |
| 9982 | |
| 9983 | Parameters |
| 9984 | ---------- |
| 9985 | calendar : str |
| 9986 | The target calendar name. |
| 9987 | dim : Hashable, default: "time" |
| 9988 | Name of the time coordinate. |
| 9989 | align_on : {None, 'date', 'year'}, optional |
| 9990 | Must be specified when either source or target is a `360_day` calendar, |
| 9991 | ignored otherwise. See Notes. |
| 9992 | missing : Any or None, optional |
| 9993 | By default, i.e. if the value is None, this method will simply attempt |
| 9994 | to convert the dates in the source calendar to the same dates in the |
| 9995 | target calendar, and drop any of those that are not possible to |
| 9996 | represent. If a value is provided, a new time coordinate will be |
| 9997 | created in the target calendar with the same frequency as the original |
| 9998 | time coordinate; for any dates that are not present in the source, the |
| 9999 | data will be filled with this value. Note that using this mode requires |
| 10000 | that the source data have an inferable frequency; for more information |
| 10001 | see :py:func:`xarray.infer_freq`. For certain frequency, source, and |
| 10002 | target calendar combinations, this could result in many missing values, see notes. |
| 10003 | use_cftime : bool or None, optional |
| 10004 | Whether to use cftime objects in the output, only used if `calendar` |
| 10005 | is one of {"proleptic_gregorian", "gregorian" or "standard"}. |
| 10006 | If True, the new time axis uses cftime objects. |
| 10007 | If None (default), it uses :py:class:`numpy.datetime64` values if the |
| 10008 | date range permits it, and :py:class:`cftime.datetime` objects if not. |
| 10009 | If False, it uses :py:class:`numpy.datetime64` or fails. |
| 10010 | |
| 10011 | Returns |
| 10012 | ------- |
| 10013 | Dataset |
| 10014 | Copy of the dataarray with the time coordinate converted to the |
| 10015 | target calendar. If 'missing' was None (default), invalid dates in |