-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add SeasonGrouper, SeasonResampler #9524
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
base: main
Are you sure you want to change the base?
Conversation
54b2ef1
to
594d4a7
Compare
First comment, but I have performed only quick test 1 -In your short example, it's probably : Or my Github knowledge is too limited, and I'm not testing the right branch. 2 - Season grouperSeems OK for all I have tested. In particular I can :
3 - Season resamplerWorks as expected from the example. It could be useful to have a NaN value for an incomplete season : the first DJF cannot not be computed, and is not. This mean that the first value is not a DJF one, but a MAM value. Could be a bit misleading. 4 - cftimeI have tested it with cftime calendars instead of datetime. It works with the traditional calendar (gregorian, standard). But not with others like 360_day, 365_day, julian., proleptic_gregorian : 5 - Simple dataI've build a dataset with the number ot the month as a variable. So I'm sure that the computation is correct. Thanks' for these features. They are quit easy and straigthforward to use. In particular, it allows to work on variables, as xcdat features work on Dataset only, which yields a more complicated syntax. I'm gonna try to imagine further tests. Olivier |
Thanks @oliviermarti ! this is incredibly helpful
Yes, my mistake. I fixed the snippet.
This should not work, did you really get correct results.
The |
In fact not ! Only the first value is correct. A bit dangerous that it returns a result and not an error.
Olivier |
Hi @dcherian, thank you for this PR! I've been looking forward to having this feature in Xarray. No guarantees on a timeline, but I plan to start looking at this PR this week. I'll experiment with this feature and see how I can leverage it to simplify xCDAT PR #423 for custom seasons. I'll also try to contribute any useful tests. |
These two groupers allow defining custom seasons, and dropping incomplete seasons from the output. Both cases are treated by adjusting the factorization -- conversion from group labels to integer codes -- appropriately.
9180536
to
77dc5e0
Compare
Hey @dcherian, quick question. Will this PR add support for using For example, if I wanted to perform grouped averaging on year and custom seasons it might look like: ds.air.groupby(time=[ds.time.dt.year, SeasonGrouper(["JF", "MAM", "JJAS", "OND"])]).mean() |
Another question: If we're defining custom seasons with months that span the calendar year, those months are from the previous year correct? For example for "NDJFM", "ND" should be from the previous year. air.groupby(year=UniqueGrouper(), time=SeasonGrouper(["NDJFM"])) |
Yes it tried to be that smart |
@tomvothecoder @oliviermarti i fixed the existing tests now, please try it out! FWIW the need to support |
7aaafb2
to
c66ad96
Compare
I'm writing a few tests right now. How do you want me to add them to your fork branch?
I noticed in a test I'm writing for the above code that "ND" is being taken from the same year, not the previous year. I think we expect the previous year "ND" to be used instead. I will show a clear example once I add the test. |
Ah nice find. A PR to this branch should be the easiest |
@oliviermarti & @tomvothecoder are you able to do one more test run here? It's basically complete though could use more tests as always. |
* main: Refactoring/fixing zarr-python v3 incompatibilities in xarray datatrees (pydata#10020) Refactor calendar fixtures (pydata#10150) Use flox for grouped first, last. (pydata#10148) Update flaky pydap test (pydata#10149)
07411f6
to
8d69e34
Compare
8d69e34
to
85d9217
Compare
* upstream/main: Move chunks-related functions to a new file (pydata#10172) Preserve label ordering for multi-variable GroupBy (pydata#10151) Update DataArray.to_zarr to match Dataset.to_zarr. (pydata#10164) Fix numpy advanced indexing docs link (pydata#10160) Forbid datatree to zarr append dim (pydata#10156) Fix GitHub Actions badge in README (pydata#10155) Add dev whats-new (pydata#10152) Release 2025.03.0 (pydata#10143)
e1ebb6b
to
6297c1c
Compare
Deepak,
I wish I could try the new Groupers which are promising (as seen at https://discourse.pangeo.io/t/pangeo-showcase-xarrays-groupby-oh-my/4666)
My question is : how can I get the correct xarray branch for that ? Is it possible ?
I’ve try to run 2024-pangeo-showcase.ipynb with a fresh extract of xarray (main branch), and I get :
from xarray.groupers import SeasonGrouper
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[17], line 1
----> 1 from xarray.groupers import SeasonGrouper
ImportError: cannot import name 'SeasonGrouper' from 'xarray.groupers' (/Users/marti/Unix/GitHub/xarray/xarray/groupers.py <http://localhost:60151/Users/marti/Unix/GitHub/xarray/xarray/groupers.py>)
Thanks for your help,
Olivier
Le 19 mars 2025 à 05:07, Deepak Cherian ***@***.***> a écrit :
dcherian
left a comment
(pydata/xarray#9524)
@oliviermarti & @tomvothecoder are you able to do one more test run here? It's basically complete though could use more tests as always.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
<https://github.com/oliviermarti> <https://github.com/tomvothecoder> <#9524 (comment)> <https://github.com/notifications/unsubscribe-auth/AAVYYTTQVRO5SKOBXZCFOCT2VDUQZAVCNFSM6AAAAABOREL7ECVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZVGI3DSOBQGY>
dcherian
left a comment
(pydata/xarray#9524)
<#9524 (comment)>
@oliviermarti <https://github.com/oliviermarti> & @tomvothecoder <https://github.com/tomvothecoder> are you able to do one more test run here? It's basically complete though could use more tests as always.
—
Reply to this email directly, view it on GitHub <#9524 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAVYYTTQVRO5SKOBXZCFOCT2VDUQZAVCNFSM6AAAAABOREL7ECVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZVGI3DSOBQGY>.
You are receiving this because you were mentioned.
—
Olivier Marti
LSCE Bât 714 p. 1049
MERMAID Team
Office : +33 1 69 08 77 27
Mobile : +33 6 45 36 43 74
***@***.***
|
This PR branch is the branch: https://github.com/dcherian/xarray/tree/custom-groupers |
If you like this PR/API please voice support here: #10198 (a 👍 on the OP would be enough) |
If I go there and search for I would be pleased to test Olivier |
Sure, I would like to. I just need more precision to get the right xarray version. |
I see it here: https://github.com/dcherian/xarray/blob/0d8210a6a5ffda32b80406ac077fec40a2a4fa15/xarray/groupers.py#L729 if you have the Github CLI it should be
or
|
Hi, My recent tests are really positive. The new Now I would like to ask for two important features :
Within a season, months have different lengths. So I need averages that reflect that, by weighting by the length of the months. When computing seasons from monthly means, it is not the case. My data (like model model outputs) have
I have data with time values at the middle of the time period (often middle of month), and time bounds at beginning/end of each period. This is very common in the CMIP database for instance. Model outputs are mainly averages on a given period (from the model time step to hour, day, month, etc ...). Period bounds are an important information. I would like to have seasonnal averages that keep this kind of time axis : value at the middle of the period, and bounds. This will allows further computation with the right weighting by periods length. And plots will better reflect the averaging period. Olivier |
I'll try testing if I can soon! Thanks again for this PR @dcherian. |
These two groupers allow defining custom seasons, and dropping incomplete seasons from the output. Both cases are treated by adjusting the factorization -- conversion from group labels to integer codes -- appropriately.
Docs are here: https://xray--9524.org.readthedocs.build/en/9524/user-guide/time-series.html#handling-seasons
The last piece from #8509
whats-new.rst
api.rst
Example:
TODO:
drop_incomplete
in SeasonGroupercc @tomvothecoder do you have time to contribute some tests? I bet we'll simplify a bunch of xcdat this way, and you probably already have tests :)