@@ -35,10 +35,11 @@ Let's create a simple example dataset:
35
35
36
36
.. ipython :: python
37
37
38
- ds = xr.Dataset({' foo' : ((' x' , ' y' ), np.random.rand(4 , 3 ))},
39
- coords = {' x' : [10 , 20 , 30 , 40 ],
40
- ' letters' : (' x' , list (' abba' ))})
41
- arr = ds[' foo' ]
38
+ ds = xr.Dataset(
39
+ {" foo" : ((" x" , " y" ), np.random.rand(4 , 3 ))},
40
+ coords = {" x" : [10 , 20 , 30 , 40 ], " letters" : (" x" , list (" abba" ))},
41
+ )
42
+ arr = ds[" foo" ]
42
43
ds
43
44
44
45
If we groupby the name of a variable or coordinate in a dataset (we can also
@@ -93,15 +94,15 @@ Apply
93
94
~~~~~
94
95
95
96
To apply a function to each group, you can use the flexible
96
- :py:meth: `~xarray.DatasetGroupBy.apply ` method. The resulting objects are automatically
97
+ :py:meth: `~xarray.DatasetGroupBy.map ` method. The resulting objects are automatically
97
98
concatenated back together along the group axis:
98
99
99
100
.. ipython :: python
100
101
101
102
def standardize (x ):
102
103
return (x - x.mean()) / x.std()
103
104
104
- arr.groupby(' letters' ).apply (standardize)
105
+ arr.groupby(' letters' ).map (standardize)
105
106
106
107
GroupBy objects also have a :py:meth: `~xarray.DatasetGroupBy.reduce ` method and
107
108
methods like :py:meth: `~xarray.DatasetGroupBy.mean ` as shortcuts for applying an
@@ -202,7 +203,7 @@ __ http://cfconventions.org/cf-conventions/v1.6.0/cf-conventions.html#_two_dimen
202
203
dims = [' ny' ,' nx' ])
203
204
da
204
205
da.groupby(' lon' ).sum(... )
205
- da.groupby(' lon' ).apply (lambda x : x - x.mean(), shortcut = False )
206
+ da.groupby(' lon' ).map (lambda x : x - x.mean(), shortcut = False )
206
207
207
208
Because multidimensional groups have the ability to generate a very large
208
209
number of bins, coarse-binning via :py:meth: `~xarray.Dataset.groupby_bins `
0 commit comments