Convert the DataArray 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
(
self,
calendar: str,
dim: str = "time",
align_on: str | None = None,
missing: Any | None = None,
use_cftime: bool | None = None,
)
| 6774 | return self._from_temp_dataset(deduplicated) |
| 6775 | |
| 6776 | def convert_calendar( |
| 6777 | self, |
| 6778 | calendar: str, |
| 6779 | dim: str = "time", |
| 6780 | align_on: str | None = None, |
| 6781 | missing: Any | None = None, |
| 6782 | use_cftime: bool | None = None, |
| 6783 | ) -> Self: |
| 6784 | """Convert the DataArray to another calendar. |
| 6785 | |
| 6786 | Only converts the individual timestamps, does not modify any data except |
| 6787 | in dropping invalid/surplus dates or inserting missing dates. |
| 6788 | |
| 6789 | If the source and target calendars are either no_leap, all_leap or a |
| 6790 | standard type, only the type of the time array is modified. |
| 6791 | When converting to a leap year from a non-leap year, the 29th of February |
| 6792 | is removed from the array. In the other direction the 29th of February |
| 6793 | will be missing in the output, unless `missing` is specified, |
| 6794 | in which case that value is inserted. |
| 6795 | |
| 6796 | For conversions involving `360_day` calendars, see Notes. |
| 6797 | |
| 6798 | This method is safe to use with sub-daily data as it doesn't touch the |
| 6799 | time part of the timestamps. |
| 6800 | |
| 6801 | Parameters |
| 6802 | ---------- |
| 6803 | calendar : str |
| 6804 | The target calendar name. |
| 6805 | dim : str |
| 6806 | Name of the time coordinate. |
| 6807 | align_on : {None, 'date', 'year'} |
| 6808 | Must be specified when either source or target is a `360_day` calendar, |
| 6809 | ignored otherwise. See Notes. |
| 6810 | missing : Optional[any] |
| 6811 | By default, i.e. if the value is None, this method will simply attempt |
| 6812 | to convert the dates in the source calendar to the same dates in the |
| 6813 | target calendar, and drop any of those that are not possible to |
| 6814 | represent. If a value is provided, a new time coordinate will be |
| 6815 | created in the target calendar with the same frequency as the original |
| 6816 | time coordinate; for any dates that are not present in the source, the |
| 6817 | data will be filled with this value. Note that using this mode requires |
| 6818 | that the source data have an inferable frequency; for more information |
| 6819 | see :py:func:`xarray.infer_freq`. For certain frequency, source, and |
| 6820 | target calendar combinations, this could result in many missing values, see notes. |
| 6821 | use_cftime : boolean, optional |
| 6822 | Whether to use cftime objects in the output, only used if `calendar` |
| 6823 | is one of {"proleptic_gregorian", "gregorian" or "standard"}. |
| 6824 | If True, the new time axis uses cftime objects. |
| 6825 | If None (default), it uses :py:class:`numpy.datetime64` values if the |
| 6826 | date range permits it, and :py:class:`cftime.datetime` objects if not. |
| 6827 | If False, it uses :py:class:`numpy.datetime64` or fails. |
| 6828 | |
| 6829 | Returns |
| 6830 | ------- |
| 6831 | DataArray |
| 6832 | Copy of the dataarray with the time coordinate converted to the |
| 6833 | target calendar. If 'missing' was None (default), invalid dates in |