-
Notifications
You must be signed in to change notification settings - Fork 39
[WIP] mapzonal, allowing you to apply some operation per raster cell, then zonal it
#775
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
Conversation
rafaqz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not do this already with mapslices when skipmissing=false?
Or is it a performance issue
| function _mapzonal(reducer, operator, x, ext::Extents.Extent; skipmissing = true) | ||
| cropped = crop(x; to = ext, touches = true) | ||
| prod(size(cropped)) > 0 || return missing | ||
| # We can't use skipmissing here, since it doesn't work on rasterstacks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just make this work, but it's just not totally clear what the rule is - any missing or all missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In here I've implemented the "all missing" variant but it's up for debate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the question is, does skipmissing mean "skip all values that are missing in general" or "skip all values that are missing because of my mask"? The first is the most useful because there can be functions that don't tolerate missings
|
To do this with |
|
I mean inside the zonal function, can you just call mapslices on the RasterStack it gives you? (The idea is good, I'm just wary of feature creep) |
|
It doesn't give you a rasterstack though, since it iterates over layers... Unless you mean changing the implementation? That would be breaking I think |
|
Hmm yes that's annoying. How do we get the best of both behaviours... But can we workshop how to get this all into |
|
Hmm, it could be a switch that does this internally? |
|
False gives you the whole stack, or iterates over NamedTuples when skipmissing=true But we need to fix skipmissing on RasterStack for that to work (Guess this might be a useful keyword in many places a function is used on stack values) |
|
There are two scenarios here - "set of rasters" (where you return multiple columns) or "linked rasters" (where you want a slice at those x and y coordinates) |
|
The thing is that methods won't necessarily work the same in both, or work at all... |
|
Hmm, with context |
|
But if we have |
With With |
|
Succeeded by #820 |
This PR introduces a function
mapzonalthat looks like this:operatoris fed each slice of the raster in all dimensions except X and Y. For a RasterStack that has onlyXandYdimensions, for example,operatorwould be passed the output ofrasterstack[X(ind), Y(ind)]for each valid index of X and Y.If you wanted to calculate NDVI from some super-high-fidelity rasterstack, for example, you would perform the computation on demand in
operator.Then,
reduceris passed the vector generated byoperator.(each_cell_of_rasterstack). This can be e.g.sum, or even a histogram function.Motivation
The motivation here is that
zonaliterates over the layers of a rasterstack before passing them to the reducer - this can be good, and necessary for the most common workflows, but we needed to operate on the raw values of the individual layers simultaneously.Some interesting usecases might be:
TODOs