diff --git a/tests/test_temporal.py b/tests/test_temporal.py index 67a5fcea..ffa49f6c 100644 --- a/tests/test_temporal.py +++ b/tests/test_temporal.py @@ -1606,6 +1606,7 @@ def test_weights_for_yearly_averages(self): ds.temporal._mode = "average" ds.temporal._freq = "year" ds.temporal._weighted = "True" + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="year", data=np.array( @@ -1668,6 +1669,7 @@ def test_weights_for_monthly_averages(self): ds.temporal._mode = "average" ds.temporal._freq = "month" ds.temporal._weighted = "True" + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="month", data=np.array( @@ -1734,6 +1736,7 @@ def test_weights_for_yearly_averages(self): ds.temporal._mode = "group_average" ds.temporal._freq = "year" ds.temporal._weighted = "True" + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="year", data=np.array( @@ -1796,6 +1799,7 @@ def test_weights_for_monthly_averages(self): ds.temporal._mode = "group_average" ds.temporal._freq = "month" ds.temporal._weighted = "True" + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="year_month", data=np.array( @@ -1940,6 +1944,7 @@ def test_weights_for_seasonal_averages_with_DJF_and_drop_incomplete_seasons( ds.temporal._freq = "season" ds.temporal._weighted = "True" ds.temporal._season_config = {"dec_mode": "DJF"} + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="year_season", data=np.array( @@ -2001,6 +2006,7 @@ def test_weights_for_seasonal_averages_with_JFD(self): ds.temporal._freq = "season" ds.temporal._weighted = "True" ds.temporal._season_config = {"dec_mode": "JDF"} + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="year_season", data=np.array( @@ -2069,6 +2075,7 @@ def test_custom_season_time_series_weights(self): ds.temporal._mode = "group_average" ds.temporal._freq = "season" ds.temporal._weighted = "True" + ds.temporal._time_bounds = ds.time_bnds ds.temporal._season_config = { "custom_seasons": { "JanFebMar": ["Jan", "Feb", "Mar"], @@ -2145,6 +2152,7 @@ def test_weights_for_daily_averages(self): ds.temporal._mode = "group_average" ds.temporal._freq = "day" ds.temporal._weighted = "True" + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="year_month_day", data=np.array( @@ -2190,6 +2198,7 @@ def test_weights_for_hourly_averages(self): ds.temporal._freq = "hour" ds.temporal._weighted = "True" ds.temporal._season_config = {"dec_mode": "JDF"} + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="year_month_day_hour", data=np.array( @@ -2337,6 +2346,7 @@ def test_weights_for_seasonal_climatology_with_DJF(self): ds.temporal._freq = "season" ds.temporal._weighted = "True" ds.temporal._season_config = {"dec_mode": "DJF"} + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="season", data=np.array( @@ -2393,6 +2403,7 @@ def test_weights_for_seasonal_climatology_with_JFD(self): ds.temporal._freq = "season" ds.temporal._weighted = "True" ds.temporal._season_config = {"dec_mode": "JDF"} + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="season", data=np.array( @@ -2456,6 +2467,7 @@ def test_weights_for_annual_climatology(self): ds.temporal._mode = "climatology" ds.temporal._freq = "month" ds.temporal._weighted = "True" + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="month", data=np.array( @@ -2518,6 +2530,7 @@ def test_weights_for_daily_climatology(self): ds.temporal._mode = "climatology" ds.temporal._freq = "day" ds.temporal._weighted = "True" + ds.temporal._time_bounds = ds.time_bnds ds.temporal._labeled_time = xr.DataArray( name="month_day", data=np.array( diff --git a/xcdat/temporal.py b/xcdat/temporal.py index 0fe8d905..4342d9d1 100644 --- a/xcdat/temporal.py +++ b/xcdat/temporal.py @@ -146,10 +146,9 @@ class TemporalAccessor: def __init__(self, dataset: xr.Dataset): self._dataset: xr.Dataset = dataset + # The name of the time dimension. self._dim = get_axis_coord(self._dataset, "T").name - self._time_bounds = self._dataset.bounds.get_bounds("T").copy() - try: self.calendar = self._dataset[self._dim].encoding["calendar"] self.date_type = get_date_type(self.calendar) @@ -739,6 +738,9 @@ def _set_obj_attrs( ValueError If an incorrect ``dec_mode`` arg was passed. """ + # The time bounds. + self._time_bounds = self._dataset.bounds.get_bounds("T") + # General configuration attributes. if mode not in list(MODES): modes = ", ".join(f'"{word}"' for word in MODES)