xarray.Dataset.bounds.add_time_bounds#
- Dataset.bounds.add_time_bounds(method, freq=None, daily_subfreq=None, end_of_month=False)#
Add bounds for an axis using its coordinate points.
This method loops over the time axis coordinate variables and attempts to add bounds for each of them if they don’t exist. To add time bounds for the time axis, its coordinates must be the following criteria:
Coordinates are single dimensional, not multidimensional
Coordinates are a length > 1 (not singleton)
Bounds must not already exist
Coordinates are mapped to bounds using the “bounds” attr. For example, bounds exist if
ds.time.attrs["bounds"]
is set to"time_bnds"
andds.time_bnds
is present in the dataset.
If
method=freq
, coordinates must be composed of datetime-like objects (np.datetime64
orcftime
)
- Parameters:
method (
{"freq", "midpoint"}
) – The method for creating time bounds for time coordinates, either “freq” or “midpoint”.“freq”: Create time bounds as the start and end of each timestep’s period using either the inferred or specified time frequency (
freq
parameter). For example, the time bounds will be the start and end of each month for each monthly coordinate point.“midpoint”: Create time bounds using time coordinates as the midpoint between their upper and lower bounds.
freq (
{"year", "month", "day", "hour"}
, optional) – Ifmethod="freq"
, this parameter specifies the time frequency for creating time bounds. By default None, which infers the frequency using the time coordinates.daily_subfreq (
{1, 2, 3, 4, 6, 8, 12, 24}
, optional) – Iffreq=="hour"
, this parameter sets the number of timepoints per day for time bounds, by default None.daily_subfreq=None
infers the daily time frequency from the time coordinates.daily_subfreq=1
is dailydaily_subfreq=2
is twice dailydaily_subfreq=4
is 6-hourlydaily_subfreq=8
is 3-hourlydaily_subfreq=12
is 2-hourlydaily_subfreq=24
is hourly
end_of_month (
bool
, optional) – Iffreq=="month"
, this flag notes that the timepoint is saved at the end of the monthly interval (see Note), by default False.Some timepoints are saved at the end of the interval, e.g., Feb. 1 00:00 for the time interval Jan. 1 00:00 - Feb. 1 00:00. Since this method determines the month and year from the time vector, the bounds will be set incorrectly if the timepoint is set to the end of the time interval. For these cases, set
end_of_month=True
.
- Returns:
xr.Dataset
– The dataset with time bounds added.