-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add Rasters.sample
#791
Add Rasters.sample
#791
Conversation
What slows it down in some cases is the conversion that happens if Just something like A = [missing 7.0f0; 2.0f0 missing]
ga = Raster(A, (X(1.0:1:2.0), Y(1.0:1:2.0)); missingval=missing)
Rasters.sample(ga, 1_000_000, skipmissing = true) |
Tests fail because of |
Co-authored-by: Rafael Schouten <[email protected]>
Co-authored-by: Rafael Schouten <[email protected]>
Do we know the answer from the type? What do you think is stopping it propagating? It could be your (The segmentation fault is of course GDAL) |
Co-authored-by: Rafael Schouten <[email protected]>
Co-authored-by: Rafael Schouten <[email protected]>
…asters.jl into rasters_sample
rebase extract and rowtype changes
Sorry for all the mess with the rebases. I added an extra keyword to |
Somehow |
I tried this but it failed tests, because |
This should be type stable now in all cases. I would still like to change the |
Tests are still failing on a segmentation fault in resample 😭 |
Ahh that's interesting about the dimensions. I guess we need to be consistent and return a table of the same length every time. You can put the |
We can totally let users specify the geometry like that too. |
It's how we designed |
Maybe we should put that exact line in the |
ext/RastersStatsBaseExt/sample.jl
Outdated
_getindex(::Type{T}, x::AbstractRasterStack{<:Any, NT}, points, idx) where {T, NT} = | ||
RA._maybe_add_fields(T, NT(x[RA.commondims(idx, x)]), points[RA.commondims(idx, points)], val(idx)) |
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.
Explicitly using the eltype of the stack like this was the only way I could find in which this would compile away. But it looks somehow ugly and I don't know if there's a better way?
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.
Like what? Is this comment on the wrong line?
Maybe. This feature justifies the having the names keyword in the first place, but it probably has a limited number of use cases. |
I added the option to specify a geometry type, even though it now only works for Tuple and NamedTuple. For other types we can't just call |
ext/RastersStatsBaseExt/sample.jl
Outdated
broadcast(I -> _getindex(T, x, points, I), indices) | ||
|
||
_getindex(::Type{T}, x::AbstractRasterStack{<:Any, NT}, points, idx) where {T, NT} = | ||
RA._maybe_add_fields(T, NT(x[RA.commondims(idx, x)]), points[RA.commondims(idx, points)], val(idx)) |
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.
It's weird this NT trick is needed, maybe DD stack getindex stability is broken on 1.11?
Looks like something needs to be forced somewhere
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 know, nothing else worked. Even AbstractRasterStack{K}
and then NamedTuple{K}
wasn't type stable.
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.
No that makes sense, it's the eltype that's not propagating.
We might need some more Base.assume_effects
in DD indexing
Is there a test for the NamedTuple geometry? |
Co-authored-by: Rafael Schouten <[email protected]>
Yes, although it's pretty rudimentary.
|
Ok that's fine, I like the syntax of just passing the tuple. Does it work for symbols and constructed dims too? Probably want to convert those values to constructed |
It just calls NamedTuple types still allocate though, idk if/how to avoid that? |
That's what I mean. For NamedTuple you need to pass through a NamedTuple of constructed dimensions, not types or symbols. That can be type stable making NamedTuple points, the others can't be DD always tries to convert to constructed dims asap for this reason. If it can inline or constprop to the point of construction it can be totally stable using types. Otherwise it's super bad |
I just added a dispatch so |
Amazing let's merge |
Ohh maybe some links in the methods page of the docs would have helped |
True, I forgot about that |
This PR adds a
Rasters.sample
function in a StatsBase extension, as suggested here: #771The keywords correspond to
extract
keywords. Some of the internals are also re-used.I would suggest not exporting this to avoid confusion with StatsBase.sample, which has a totally different API.
If
skipmissing = true
, Rasters.sample and extract will always return the same types - otherwise it depends on the element type of the Raster. I tried to avoid creatingUnion{Missing, ...}
as much as possible.Closes #771