xarray icon indicating copy to clipboard operation
xarray copied to clipboard

Groupby exclude dimension

Open pwolfram opened this issue 9 years ago • 10 comments

Is there some way to do a groupby operation where some dimension is excluded from the operation, e.g., a vectorized version of something like this:

vertlevels = [ds.vel.sel(nVertLevels=i).groupby('y').mean() for i in ds.nVertLevels]
xavgvel = xr.concat(vertlevels, 'nVertLevels')

The application here is to average 3D data in the x coordinate to the unique y coordinates, but not the vertical coordinate.

Thus, we are basically looking for something that allows a coordinate to be excluded from the groupby operation, e.g., in this case the vertical coordinate. Ideally this would also be possible within the context of the groupby_bins operation.

Any ideas on how this should work or a pointer on how to implement this type of operation more cleanly with existing infrastructure is greatly appreciated. This appears to be related to #324 and especially (perhaps identically) #924.

cc @vanroekel, @shoyer, @jhamman, @rabernat, @MaximilianR

pwolfram avatar Sep 20 '16 22:09 pwolfram

I explicitly listed this as a TODO in my multidimensional groupby PR (#818): https://github.com/pydata/xarray/blob/master/xarray/core/groupby.py#L166

It would definitely be useful and is totally doable!

rabernat avatar Sep 21 '16 00:09 rabernat

My guess is that this could be implemented pretty quickly on top of #924, which is currently on hold while I finish up #964.

shoyer avatar Sep 21 '16 00:09 shoyer

Thanks @rabernat and @shoyer!

pwolfram avatar Sep 21 '16 13:09 pwolfram

If only we could clone @shoyer!

rabernat avatar Sep 21 '16 14:09 rabernat

Isn't there a git command for that? ;-)

pwolfram avatar Sep 21 '16 14:09 pwolfram

Thanks for making everyone's life so much better via xarray and for helping us all to contribute to this process @shoyer!

pwolfram avatar Sep 21 '16 14:09 pwolfram

Note, this issue should be resolvable via #924.

pwolfram avatar Mar 22 '17 15:03 pwolfram

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

stale[bot] avatar Oct 04 '20 06:10 stale[bot]

Is this still current?

max-sixty avatar Sep 25 '24 00:09 max-sixty

Yes

dcherian avatar Sep 25 '24 00:09 dcherian

#10258 enables this with flox, the classic loopy version will still error.

dcherian avatar Apr 29 '25 05:04 dcherian