rafaqz / Rasters.jl

Raster manipulation for the Julia language
MIT License
214 stars 36 forks source link

`collect(skipmissing(::RasterStack))` fails #765

Open asinghvi17 opened 1 month ago

asinghvi17 commented 1 month ago
# Prepare a test dataset
rs = RasterStack((Raster(rand(X(1:10), Y(1:10)); missingval=NaN) for _ in 1:4)...; missingval = NaN)
# Create areas of known zero, just for verification
map(rs) do A
    A[1:2, 1:2] .= 0
    A[3:4, 3:4] .= NaN
    A
end
rs = replace_missing(rs, missing)
rs[Extent(X=(3,4),Y=(3,4))] |> skipmissing |> collect
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] iterate(::Base.SkipMissing{RasterStack{…}})
   @ Base ./missing.jl:252
 [4] _collect(cont::UnitRange{Int64}, itr::Base.SkipMissing{RasterStack{…}}, ::Base.HasEltype, isz::Base.SizeUnknown)
   @ Base ./array.jl:770
 [5] collect(itr::Base.SkipMissing{RasterStack{…}})
   @ Base ./array.jl:759
 [6] |>(x::Base.SkipMissing{RasterStack{…}}, f::typeof(collect))
   @ Base ./operators.jl:917
 [7] top-level scope
asinghvi17 commented 1 month ago

I specifically want to iterate over namedtuples here.

rafaqz commented 1 month ago

Yeah AbstractDimStack doesn't iterate like that.

Maybe it should. For now you can iterate over (stack[I] for I in DimIndices(stack))

rafaqz commented 2 weeks ago

This is fixed in the latest DD, so will be fixed here in the next breaking change

rafaqz commented 2 weeks ago

Opps actually not sure SkipMissing will work, lets test that it does