xarray.cftime_range#
- xarray.cftime_range(start=None, end=None, periods=None, freq=None, normalize=False, name=None, inclusive='both', calendar='standard')[source]#
Return a fixed frequency CFTimeIndex.
- Parameters:
start (
str
orcftime.datetime
, optional) – Left bound for generating dates.end (
str
orcftime.datetime
, optional) – Right bound for generating dates.periods (
int
, optional) – Number of periods to generate.freq (
str
orNone
, default:"D"
) – Frequency strings can have multiples, e.g. “5h” and negative values, e.g. “-1D”.normalize (
bool
, default:False
) – Normalize start/end dates to midnight before generating date range.inclusive (
{"both", "neither", "left", "right"}
, default"both"
) – Include boundaries; whether to set each bound as closed or open.New in version 2023.02.0.
calendar (
str
, default:"standard"
) – Calendar type for the datetimes.
- Returns:
Notes
This function is an analog of
pandas.date_range
for use in generating sequences ofcftime.datetime
objects. It supports most of the features ofpandas.date_range
(e.g. specifying how the index isclosed
on either side, or whether or not tonormalize
the start and end bounds); however, there are some notable exceptions:You cannot specify a
tz
(time zone) argument.Start or end dates specified as partial-datetime strings must use the ISO-8601 format.
It supports many, but not all, frequencies supported by
pandas.date_range
. For example it does not currently support any of the business-related or semi-monthly frequencies.Compound sub-monthly frequencies are not supported, e.g. ‘1H1min’, as these can easily be written in terms of the finest common resolution, e.g. ‘61min’.
Valid simple frequency strings for use with
cftime
-calendars include any multiples of the following.Alias
Description
YE
Year-end frequency
YS
Year-start frequency
QE
Quarter-end frequency
QS
Quarter-start frequency
ME
Month-end frequency
MS
Month-start frequency
D
Day frequency
h
Hour frequency
min
Minute frequency
s
Second frequency
ms
Millisecond frequency
us
Microsecond frequency
Any multiples of the following anchored offsets are also supported.
Alias
Description
Y(E,S)-JAN
Annual frequency, anchored at the (end, beginning) of January
Y(E,S)-FEB
Annual frequency, anchored at the (end, beginning) of February
Y(E,S)-MAR
Annual frequency, anchored at the (end, beginning) of March
Y(E,S)-APR
Annual frequency, anchored at the (end, beginning) of April
Y(E,S)-MAY
Annual frequency, anchored at the (end, beginning) of May
Y(E,S)-JUN
Annual frequency, anchored at the (end, beginning) of June
Y(E,S)-JUL
Annual frequency, anchored at the (end, beginning) of July
Y(E,S)-AUG
Annual frequency, anchored at the (end, beginning) of August
Y(E,S)-SEP
Annual frequency, anchored at the (end, beginning) of September
Y(E,S)-OCT
Annual frequency, anchored at the (end, beginning) of October
Y(E,S)-NOV
Annual frequency, anchored at the (end, beginning) of November
Y(E,S)-DEC
Annual frequency, anchored at the (end, beginning) of December
Q(E,S)-JAN
Quarter frequency, anchored at the (end, beginning) of January
Q(E,S)-FEB
Quarter frequency, anchored at the (end, beginning) of February
Q(E,S)-MAR
Quarter frequency, anchored at the (end, beginning) of March
Q(E,S)-APR
Quarter frequency, anchored at the (end, beginning) of April
Q(E,S)-MAY
Quarter frequency, anchored at the (end, beginning) of May
Q(E,S)-JUN
Quarter frequency, anchored at the (end, beginning) of June
Q(E,S)-JUL
Quarter frequency, anchored at the (end, beginning) of July
Q(E,S)-AUG
Quarter frequency, anchored at the (end, beginning) of August
Q(E,S)-SEP
Quarter frequency, anchored at the (end, beginning) of September
Q(E,S)-OCT
Quarter frequency, anchored at the (end, beginning) of October
Q(E,S)-NOV
Quarter frequency, anchored at the (end, beginning) of November
Q(E,S)-DEC
Quarter frequency, anchored at the (end, beginning) of December
Finally, the following calendar aliases are supported.
Alias
Date type
standard, gregorian
cftime.DatetimeGregorian
proleptic_gregorian
cftime.DatetimeProlepticGregorian
noleap, 365_day
cftime.DatetimeNoLeap
all_leap, 366_day
cftime.DatetimeAllLeap
360_day
cftime.Datetime360Day
julian
cftime.DatetimeJulian
Examples
This function returns a
CFTimeIndex
, populated withcftime.datetime
objects associated with the specified calendar type, e.g.>>> xr.cftime_range(start="2000", periods=6, freq="2MS", calendar="noleap") CFTimeIndex([2000-01-01 00:00:00, 2000-03-01 00:00:00, 2000-05-01 00:00:00, 2000-07-01 00:00:00, 2000-09-01 00:00:00, 2000-11-01 00:00:00], dtype='object', length=6, calendar='noleap', freq='2MS')
As in the standard pandas function, three of the
start
,end
,periods
, orfreq
arguments must be specified at a given time, with the other set toNone
. See the pandas documentation for more examples of the behavior ofdate_range
with each of the parameters.See also