-
Notifications
You must be signed in to change notification settings - Fork 60
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
Correctly interpolate seasons in Grouper #2019
base: main
Are you sure you want to change the base?
Conversation
I just realised that the factor of 1/6 is assuming that all seasons have the same length which in gregorian calendars is not necessarily true but I am not sure it matters too much at least the function should be smooth. |
Warning This Pull Request is coming from a fork and must be manually tagged |
Weirdly and contrary to what I showed yesterday, today I am still getting clear transitions as if there still wasn't any linear interpolation. |
@saschahofmann We recently changed the layout of xclim to use a |
I reinstalled xclim but I am still getting very similar results to before the "fix". You have any advice on where else I could look? |
Could it be that you have obsolete |
I managed to install the environment, for some reason I only had the branch "main" when I cloned the fork yesterday
import inspect
print(inspect.getsource(sdba.base.Grouper.get_index))
I'll try to have look later. Maybe the |
I am pretty sure that the |
It's simply from xclim import sdba
QM = sdba.EmpiricalQuantileMapping.train(
ref, hist, nquantiles=15, group="time.season", kind="+"
)
scen = QM.adjust(sim, extrapolation="constant", interp="nearest")
scen_interp = QM.adjust(sim, extrapolation="constant", interp="linear")
outd = {
"Reference":ref,
"Model - biased":hist,
"Model - adjusted - no interp":scen,
"Model - adjusted - linear interp":scen_interp,
}
for k,da in outd.items():
da.groupby("time.dayofyear").mean().plot(label=k)
plt.legend() This doesn't reproduce your figure however. It seems your figure above was matching the reference very well, better than what I have even with the linear interpolation. But it does get rid of obvious discontinuities. |
@coxipi I think only mention this in the original issue: my analysis is done with |
Yes, I have seen simlilar things by playing with the choice of how |
And another fix for using sdba.Scaling in utils.pyL222 |
Merged @aulemahal fix and this is now ready for merging |
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.
Looks good! Thanks!
I think we can avoid a breaking change in test_timeseries
.
From my side this looks good not sure how to trigger the coverage pipeline? |
@Zeitsperre I added these two lines to allow linear interpolation with It was failing in a test |
I'm going to defer to @coxipi or @aulemahal here. This is a bit out of my depth haha |
I don't think there would be a point in doing linear interpolation for dayofyear. We have adjusting factors for each dayofyear, so we don't have in-between values where we need to interpolate the training data. I would say we probably need to change the failing test, let me see I don't see the failing, can you point to a specific commit? |
Yes. Its this test TestExtremeValues.test_real_data: https://github.com/Ouranosinc/xclim/actions/runs/12985440090/job/36210393696 I fixed it by allowing again linear interp of dayofyear. I think it was allowed previously but I slightly restructured the code so now by default it was disabled. |
I reverted the change that allows linear interp with dayofyear grouping and instead changed the test to use nearest |
@coxipi I think maybe reenabling linear interpolation from dayofyear for now is a better solution. Since otherwise it represents a breaking change, e.g. right now the tutorial does some similar (hence the breaking test in sdba-advanced.ipynb) where we do EQM with dayofyer with linear interp. Instead I could add a deprecation warning for maybe 0.57.0? |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
for more information, see https://pre-commit.ci
Pull Request Checklist:
number
) and pull request (:pull:number
) has been addedWhat kind of change does this PR introduce?
This PR adds a line to correctly interpolate seasonal values. It also changes the test_timeseries function that now accepts a
calendar
argument instead ofcftime
. Not providing it or providingNone
is equivalent tocftime=False
andcalendar='standard
to the previouscftime=True
. This allows for testing different calendar implementations e.g. 360_day calendars