Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to return sum instead of mean? #15

Open
bradyrx opened this issue Aug 9, 2021 · 1 comment
Open

Option to return sum instead of mean? #15

bradyrx opened this issue Aug 9, 2021 · 1 comment

Comments

@bradyrx
Copy link

bradyrx commented Aug 9, 2021

Is it feasible with the current code structure to have an option to return the sum over a polygon instead of the mean? I.e., something like http://xarray.pydata.org/en/stable/generated/xarray.core.weighted.DataArrayWeighted.sum.html instead of http://xarray.pydata.org/en/stable/generated/xarray.core.weighted.DataArrayWeighted.mean.html.

The rasterstats zonal statistics module allows one to return mean, sum, etc: https://pythonhosted.org/rasterstats/manual.html#zonal-statistics.

I realize this might not be super straight-forward since you can't guarantee the preservation of the integral. Since your package looks at how any pixels overlap with the shapefile, you might be reusing some pixels. Or maybe not, since the idea is that you're calculating the percentage overlap here, so even a small shapefile would only grab a small percentage of a given pixel.

I'm thinking this is useful if one wants to convert from something like total precipitation on a raster grid to total/accumulated precipitation over a larger shapefile.

@ks905383
Copy link
Owner

I realize this might not be super straight-forward since you can't guarantee the preservation of the integral. Since your package looks at how any pixels overlap with the shapefile, you might be reusing some pixels. Or maybe not, since the idea is that you're calculating the percentage overlap here, so even a small shapefile would only grab a small percentage of a given pixel.

I had considered doing this (I think I have a local branch that allows sum calculations somewhere), but I haven't stuck it into the main package for exactly this question. rasterstats (and other packages that are doing similar things, like regionmask's aggregating module) don't do area overlaps, so I wouldn't be as worried about that mass-preservation question, but here I'm worried that there's no good way to deal with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants