JuliaDataCubes / PyramidScheme.jl

Building and using pyramids for large raster data
MIT License
13 stars 1 forks source link

Make a new AbstractRange that would subset into the pyramid with a given size #52

Open felixcremer opened 1 week ago

felixcremer commented 1 week ago

From @timholy via Slack:

Hmm, looking at PyramidScheme, do you think there's room for something that brings in fewer dependencies? I was envisioning something like this: img[sizelimit(1000, xrng), sizelimit(1000, yrng)] where sizelimit(maxsz, rng) returns an AbstractRange for which the pyramid has a special slicing implementation. If img isn't a pyramid, then this just returns img[xrng, yrng]. So sizelimit is only a "hint" about what resolution you want for the output.

The core ideas of a slim package would be:

struct SizeLimitedUnitRange <: AbstractUnitRange{Int} r::UnitRange{Int} lim::Int end

Base.iterate(rng::SizeLimitedUnitRange, state...) = Base.iterate(rng.r, state...) # provides fallback behavior for non-pyramids

struct Pyramid{T,N,A<:AbstractArray{T,N},Ax<:NTuple{N,AbstractUnitRange}} <: AbstractArray{T,N} levels::Vector{A} axes::Ax end

function Base.getindex(A::Pyramid, I...) any(i -> isa(I, SizeLimitedUnitRange), I) || return invoke(getindex, Tuple{AbstractArray, Vararg{Any}}, A, I...)

implementation that picks the level goes here

end

timholy commented 1 week ago

Also xref https://github.com/JuliaImages/ImageBase.jl/issues/39. One other point worth noting, ImageBase.restrict would give you anti-aliasing. https://en.wikipedia.org/wiki/Spatial_anti-aliasing#Examples is a nice illustration of just how strange the artifacts can be if you don't anti-alias.