Skip to content
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

MBCn with 5days-OddWindow #79

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

MBCn with 5days-OddWindow #79

wants to merge 11 commits into from

Conversation

coxipi
Copy link
Contributor

@coxipi coxipi commented Feb 17, 2025

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes #xyz
  • (If applicable) Documentation has been added / updated (for bug fixes / features).
  • (If applicable) Tests have been added.
  • CHANGELOG.rst has been updated (with summary of main changes).
    • Link to issue (:issue:number) and pull request (:pull:number) has been added.

What kind of change does this PR introduce?

  • Small workaround to be able to use the 5 day grouping in MBCn, compatible with odd windows.

Does this PR introduce a breaking change?

No

Other information:

This doesn't respect the logic of Grouper, but to activate this functionality, I pass a Grouper("5D", window=7). I think only time, time.season, time.month, time.dayofyear would be allowed as strings in a proper implementation ("The usual grouping name as xarray understands it. Ex: "time.month" or "time".") To allow more complex group, I guess we would need to accept Pandas object or something.

Since MBCn doesn't currently use map_groups, implementing this hack was relatively easy.

This is also thought specifically for a 365-day calendar, that 5 is a factor of 365 (5*73).

@coveralls
Copy link

coveralls commented Feb 18, 2025

Coverage Status

coverage: 73.694% (-0.3%) from 73.962%
when pulling 46acbef on mbcn_5d
into 066c2cc on main.

@coxipi
Copy link
Contributor Author

coxipi commented Feb 18, 2025

It's about 5 times as faster, as expected (well, I just showed the training, but you get it)

from xclim.testing import open_dataset
import xsdba 
ds = open_dataset('sdba/ahccd_1950-2013.nc')
da = xsdba.stack_variables(ds)

group = xsdba.Grouper("5D", window=7)
ADJ = xsdba.MBCn.train(ref=da,hist=da,base_kws=dict(group=group))
ADJ.ds.af_q.compute()
# >>> 8.6 s
group = xsdba.Grouper("time.dayofyear", window=31)
ADJ = xsdba.MBCn.train(ref=da,hist=da,base_kws=dict(group=group))
ADJ.ds.af_q.compute()
# >>> 41.4 s ~ 5x slower, as expected

@coxipi coxipi changed the title MBCn with 5days-7window MBCn with 5days-OddWindow Feb 18, 2025
@Zeitsperre Zeitsperre requested a review from aulemahal February 18, 2025 15:38
@coxipi
Copy link
Contributor Author

coxipi commented Feb 22, 2025

In my tests, I had also created a specific class DQM_gpies to be able to compute DQM like MBCn, and use directly the 5d7w time grouping. I could release this version, but maybe we should instead investigate in a solution to accept 5d7w grouping in map_groups. I have a feeling it's gonna be rough though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants