MCPcopy
hub / github.com/pydata/xarray / convert_calendar

Function convert_calendar

xarray/coding/calendar_ops.py:32–232  ·  view source on GitHub ↗

Transform a time-indexed Dataset or DataArray to one that uses another calendar. This function only converts the individual timestamps; it does not modify any data except in dropping invalid/surplus dates, or inserting values for missing dates. If the source and target calendars are bo

(
    obj,
    calendar,
    dim="time",
    align_on=None,
    missing=None,
    use_cftime=None,
)

Source from the content-addressed store, hash-verified

30
31
32def convert_calendar(
33 obj,
34 calendar,
35 dim="time",
36 align_on=None,
37 missing=None,
38 use_cftime=None,
39):
40 """Transform a time-indexed Dataset or DataArray to one that uses another calendar.
41
42 This function only converts the individual timestamps; it does not modify any
43 data except in dropping invalid/surplus dates, or inserting values for missing dates.
44
45 If the source and target calendars are both from a standard type, only the
46 type of the time array is modified. When converting to a calendar with a
47 leap year from to a calendar without a leap year, the 29th of February will
48 be removed from the array. In the other direction the 29th of February will
49 be missing in the output, unless `missing` is specified, in which case that
50 value is inserted. For conversions involving the `360_day` calendar, see Notes.
51
52 This method is safe to use with sub-daily data as it doesn't touch the time
53 part of the timestamps.
54
55 Parameters
56 ----------
57 obj : DataArray or Dataset
58 Input DataArray or Dataset with a time coordinate of a valid dtype
59 (:py:class:`numpy.datetime64` or :py:class:`cftime.datetime`).
60 calendar : str
61 The target calendar name.
62 dim : str
63 Name of the time coordinate in the input DataArray or Dataset.
64 align_on : {None, 'date', 'year', 'random'}
65 Must be specified when either the source or target is a `"360_day"`
66 calendar; ignored otherwise. See Notes.
67 missing : any, optional
68 By default, i.e. if the value is None, this method will simply attempt
69 to convert the dates in the source calendar to the same dates in the
70 target calendar, and drop any of those that are not possible to
71 represent. If a value is provided, a new time coordinate will be
72 created in the target calendar with the same frequency as the original
73 time coordinate; for any dates that are not present in the source, the
74 data will be filled with this value. Note that using this mode requires
75 that the source data have an inferable frequency; for more information
76 see :py:func:`xarray.infer_freq`. For certain frequency, source, and
77 target calendar combinations, this could result in many missing values, see notes.
78 use_cftime : bool, optional
79 Whether to use cftime objects in the output, only used if `calendar` is
80 one of {"proleptic_gregorian", "gregorian" or "standard"}.
81 If True, the new time axis uses cftime objects.
82 If None (default), it uses :py:class:`numpy.datetime64` values if the date
83 range permits it, and :py:class:`cftime.datetime` objects if not.
84 If False, it uses :py:class:`numpy.datetime64` or fails.
85
86 Returns
87 -------
88 Copy of source with the time coordinate converted to the target calendar.
89 If `missing` was None (default), invalid dates in the new calendar are

Calls 15

_should_cftime_be_usedFunction · 0.90
is_np_datetime_likeFunction · 0.90
DataArrayClass · 0.90
convert_timesFunction · 0.90
get_date_typeFunction · 0.90
CFTimeIndexClass · 0.90
date_range_likeFunction · 0.90
_interpolate_day_of_yearFunction · 0.85
anyMethod · 0.45
copyMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…