Weighted sum/mean/cumsum
See original GitHub issueWhile thinking about #99, I would also consider adding a module for weighted mean/sum/cumsum to xgcm. I have been using my own code so far (https://github.com/jbusecke/xarrayutils/blob/master/xarrayutils/weighted_operations.py).
Currently I would use someting like this
from xarrayutils.weighted_ops import weighted_mean
w_mean = weighted_mean(da['varname'], da['weightname'], dims=['xc', 'yc'])
I would really like if I could do something like this in xgcm with a full dataset:
from xgcm import Grid
grid = Grid(ds)
ds_mean = grid.mean(['X', 'Y'], weights='area')
This would use the internal logic resulting from #99 and weigh all variables with the appropriate area depening on its dimensions.
@rabernat, would you consider this something that could make it into xgcm? This would obviously not be the first thing on the list, but I wanted to put it out here.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
CMIP6 Hackathon · GitHub
Weighted sum/mean/cumsum #102 opened by jbusecke enhancement. From Done ... WIP: Adding weighted average and cumsum #162 opened by jbusecke enhancement.
Read more >Twitter \ Julius Busecke, PhD على تويتر: "@BalwadaDhruv ...
We are currently on integration and then weighted ave (maybe others) that automatically weigh by the ... Weighted sum/mean/cumsum · Issue #102 ·...
Read more >Aim of course
sum, mean, cumsum, var, sd, IQR ... are all vectorized: ... weight. 1 casein 323.5833. 2 horsebean 160.2000. 3 linseed 218.7500. 4 meatmeal...
Read more >python 的numpy库中的mean()函数用法介绍 - CSDN博客
Array containing numbers whose mean is desired. If a is not an array, a conversion is attempted. axis : None or int or...
Read more >The xgcm from xgcm - GithubHelp
Weighted sum/mean/cumsum. While thinking about #99, I would also consider adding a module for weighted mean/sum/cumsum to xgcm.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dhruvbalwada - thanks for weighing in! (No pun intended 🤣 )
Here we are talking about reductions operations happening in grid space. Like a zonal mean or mean over the domain. It’s something we already do every day when we do
(area-weighted sum of SST)
The “weight” concept in xhistogram is about something related but different: what weights to assign to each point when calculating a histogram. The weights themselves will indeed often be the same arrays.
We could potentially attach histogram methods to xgcm Grids which would automatically figure out the weights.
Closed via #162