Skip to content

Commit aac6ded

Browse files
authored
Small edits to season grouping post (#784)
1 parent ee6b3a3 commit aac6ded

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed
Loading

src/posts/season-grouping/index.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ Data variables:
7070

7171
Overlapping seasons are supported:
7272

73-
```
74-
>>> ds.groupby(time=SeasonGrouper(["DJFM", "MAMJ", "JJAS", "SOND"])).count()
73+
```python
74+
>>> four_monthly = ds.groupby(time=SeasonGrouper(["DJFM", "MAMJ", "JJAS", "SOND"])).count()
75+
>>> four_monthly.count()
76+
7577
<xarray.Dataset> Size: 43kB
7678
Dimensions: (lat: 25, lon: 53, season: 4)
7779
Coordinates:
@@ -83,6 +85,18 @@ Data variables:
8385
Attributes: (5)
8486
```
8587

88+
Let's make a plot using [FacetGrid](https://docs.xarray.dev/en/stable/user-guide/plotting.html#faceting)!
89+
90+
```
91+
four_monthly.mean().air.plot(
92+
col="season", cmap="magma", robust=True, col_wrap=2
93+
)
94+
```
95+
96+
<p align='center'>
97+
<img src='/posts/season-grouping/four-month-seasons.png' width='70%' />
98+
</p>
99+
86100
### SeasonResampler
87101

88102
```python
@@ -137,7 +151,7 @@ Attributes: (5)
137151

138152
These new Grouper objects compose well with grouping over other arrays ([see blog post](https://xarray.dev/blog/multiple-groupers/)), for example
139153

140-
```
154+
```python
141155
>>> from xarray.groupers import BinGrouper
142156
>>>
143157
>>> ds.groupby(lat=BinGrouper(bins=2), time=SeasonResampler(["JF", "MAM", "JJAS", "OND"])).count()
@@ -162,8 +176,9 @@ Given the user's definition of seasons, we construct the appropriate array of in
162176

163177
## Limitations
164178

165-
1. `SeasonGrouper` does not support the `drop_incomplete` option yet. This would be a great contribution.
179+
1. `SeasonGrouper` does not support the `drop_incomplete` option yet. This would be a great contribution ([issue](https://github.com/pydata/xarray/issues/10426)).
166180
2. `SeasonResampler` does not support overlapping seasons. This seems much harder to solve.
181+
3. Rechunking to a seasonal frequency with `SeasonResampler`` is not supported yet. This would also be a great contribution ([issue](https://github.com/pydata/xarray/issues/10425)). Such rechunking is a remarkably useful technique in making climatology calculations much more parallel-friendly. For example: `ds.chunk(time=TimeResampler("10YS"))` rechunks so that 10 years of data is contained in a single chunk. See these two Pangeo discourse forum posts ([1](https://discourse.pangeo.io/t/xarray-memoryerror-with-groupby-workloads/4273/9), [2](https://discourse.pangeo.io/t/best-practice-advice-on-parallel-processing-a-suite-of-zarr-files-with-dask-and-xarray/5201/9)) for applications of this technique.
167182
168183
## Summary
169184

0 commit comments

Comments
 (0)