-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple temporal avg calls on same dataset breaking #329
Conversation
- This was caused by initializing the `ds.temporal` class once with `self._time_bounds`. Instead, it needs to be set every time the user runs temporal averaging because this `self._time_bounds` can change between each call depending on user settings (e.g., drop incomplete djf).
Hi @lee1043 and @gleckler1, this PR fixes the issue where multiple temporal averaging calls on the same dataset object breaks. This is what happens: import xcdat
infile = "/p/css03/esgf_publish/CMIP6/CMIP/CSIRO-ARCCSS/ACCESS-CM2/historical/r1i1p1f1/Amon/ts/gn/v20191108/ts_Amon_ACCESS-CM2_historical_r1i1p1f1_gn_185001-201412.nc"
d = xcdat.open_dataset(lf, data_var=var)
# `self._time_bounds is initialized in the `.temporal` class
d_ac = d.temporal.climatology(var, freq="month", weighted=True) # okay
# `self._time_bounds is reused since it is initialized already, and now have been adjusted to drop incomplete DJF seasons
d_clim = d.temporal.climatology(var, freq="season", weighted=True, season_config={"dec_mode": "DJF", "drop_incomplete_djf": True},) # okay
# `self._time_bounds is reused again, but with dropped incomplete DJF seasons. This results in mismatching bounds shape with the time coordinates.
d_ac = d.temporal.climatology(var, freq="month", weighted=True) # error when repeat after get seasonal climatology The solution: Initialize |
# The time bounds. | ||
self._time_bounds = self._dataset.bounds.get_bounds("T") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this line here originally, but made the silly mistake of moving it to the class__init__
method in another PR which caused this bug.
Codecov Report
@@ Coverage Diff @@
## main #329 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 1191 1191
=========================================
Hits 1191 1191
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Thank you @tomvothecoder for the quick update. I am taking this PR a look for verifying followings:
|
Description
This was caused by initializing the
ds.temporal
class once withself._time_bounds
. Instead, it needs to be set every time the user runs temporal averaging because thisself._time_bounds
can change between each call depending on user settings (e.g., drop incomplete djf).Checklist
If applicable: