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:

  1. Coordinates are single dimensional, not multidimensional

  2. Coordinates are a length > 1 (not singleton)

  3. 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" and ds.time_bnds is present in the dataset.

  4. If method=freq, coordinates must be composed of datetime-like objects (np.datetime64 or cftime)

  • 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) – If method="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) – If freq=="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 daily

    • daily_subfreq=2 is twice daily

    • daily_subfreq=4 is 6-hourly

    • daily_subfreq=8 is 3-hourly

    • daily_subfreq=12 is 2-hourly

    • daily_subfreq=24 is hourly

  • end_of_month (bool, optional) – If freq=="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.


xr.Dataset – The dataset with time bounds added.