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

Operations that call collect or iterate fail on some RasterStacks #810

Closed
asinghvi17 opened this issue Sep 30, 2024 · 1 comment · Fixed by #811
Closed

Operations that call collect or iterate fail on some RasterStacks #810

asinghvi17 opened this issue Sep 30, 2024 · 1 comment · Fixed by #811

Comments

@asinghvi17
Copy link
Collaborator

asinghvi17 commented Sep 30, 2024

Here's a running example (from my mapzonal code):

Setup:

using Rasters

r1 = Raster(rand(X(1:10), Y(1:10)))
r2 = Raster(rand(dims(r1)...))

rs = RasterStack(r1, r2)

bool_cond_raster = r1 .> 0.5

mask_inds = view(Rasters.DD.DimIndices(bool_cond_raster), bool_cond_raster)

masked_stack = rs[mask_inds] # fine so far

Operations on a directly masked stack

masked_stack[1] # also fine

collect(masked_stack) # errors

identity.(masked_stack) # errors
sum(masked_stack) # somehow fine and correct?

# errors for anything that calls `collect

Operations on a viewed stack

# If I try to view,

viewed_stack = view(rs, mask_inds)

viewed_stack[1] # also fine

collect(viewed_stack) # also errors

sum(viewed_stack) # also fine and correct

The error:

ERROR: Use iterate(layers(s)) rather than `iterate(s)`
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] iterate(::RasterStack{…})
   @ DimensionalData ~/.julia/dev/DimensionalData/src/stack/stack.jl:169
 [3] copyto!(dest::Vector{…}, src::RasterStack{…})
   @ Base ./abstractarray.jl:943
 [4] _collect(cont::UnitRange{…}, itr::RasterStack{…}, ::Base.HasEltype, isz::Base.HasLength)
   @ Base ./array.jl:765
 [5] collect(itr::RasterStack{…})
   @ Base ./array.jl:759
 [6] broadcastable(x::RasterStack{…})
   @ Base.Broadcast ./broadcast.jl:743
 [7] broadcasted(::typeof(identity), ::RasterStack{…})
   @ Base.Broadcast ./broadcast.jl:1339
 [8] top-level scope
   @ REPL[99]:1
Some type information was truncated. Use `show(err)` to see complete types.

```1
@rafaqz
Copy link
Owner

rafaqz commented Sep 30, 2024

Yeah, we need to define what iterate on a stack does and I never settled. It's like base with broadcast over a Dict. The fact that stack layers can have mixed sizes complicates things a little.

Edit: I already made the old version error, we can fix it now.

@rafaqz rafaqz transferred this issue from rafaqz/Rasters.jl Sep 30, 2024
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

Successfully merging a pull request may close this issue.

2 participants