question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weighted sum/mean/cumsum

See original GitHub issue

While 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:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rabernatcommented, Jul 13, 2019

@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

(ds.SST * ds.rA).sum()

(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.

0reactions
jbuseckecommented, Oct 22, 2019

Closed via #162

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found