-
Notifications
You must be signed in to change notification settings - Fork 23
Add TiledDiskArray #283
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
base: main
Are you sure you want to change the base?
Add TiledDiskArray #283
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """ | ||
| AbstractChunkTiledDiskArray <: AbstractDiskArray | ||
|
|
||
| An abstract supertype for disk arrays that have fast indexing | ||
| of tiled chunks already stored as separate arrays, such as [`CachedDiskArray`](@ref). | ||
| """ | ||
| abstract type AbstractChunkTiledDiskArray{T,N} <: AbstractDiskArray{T,N} end | ||
|
|
||
| Base.size(a::AbstractChunkTiledDiskArray) = arraysize_from_chunksize.(eachchunk(a).chunks) | ||
|
|
||
| function readblock!(A::AbstractChunkTiledDiskArray{T,N}, data, I...) where {T,N} | ||
| chunks = eachchunk(A) | ||
| chunk_indices = findchunk.(chunks.chunks, I) | ||
| data_offset = OffsetArray(data, map(i -> first(i) - 1, I)...) | ||
| foreach(CartesianIndices(chunk_indices)) do ci | ||
| @show ci | ||
| chunkindex = ChunkIndex(ci; offset=true) | ||
| @show chunkindex | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
| chunk = A[chunkindex] | ||
| # Find the overlapping indices | ||
| inner_indices = map(axes(chunk), axes(data_offset)) do ax1, ax2 | ||
| max(first(ax1), first(ax2)):min(last(ax1), last(ax2)) | ||
| end | ||
| for ii in CartesianIndices(inner_indices) | ||
| data_offset[ii] = chunk[ii] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| """ | ||
| TiledDiskArray <: AbstractChunkTiledDiskArray | ||
|
|
||
| Construct an array from a collection of tiles. | ||
| This needs a function to find the tile given a tile position and the overall size of the array. | ||
| """ | ||
| struct TiledDiskArray{T,N} <: AbstractChunkTiledDiskArray{T,N} | ||
| tilefunction | ||
| tilenum | ||
| tilesizes | ||
|
Comment on lines
+37
to
+39
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use this definition instead: struct TiledDiskArray{T,N,F} <: AbstractChunkTiledDiskArray{T,N}
tilefunction::F
tilenum::NTuple{N,Int}
tilesizes::NTuple{N,Int}
end
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth having the tile definition be GridChunks instead - for example the Copernicus DEM has irregular sizes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a link to that?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
| end | ||
|
|
||
|
|
||
| Base.size(A::TiledDiskArray) = A.tilenum .* A.tilesizes | ||
| eachchunk(A::TiledDiskArray) = DiskArrays.GridChunks(size(A), A.tilesizes) | ||
| haschunks(A::TiledDiskArray) = Chunked() | ||
|
|
||
| function Base.getindex(A::TiledDiskArray, i::ChunkIndex{N,OffsetChunks}) where {N} | ||
| tile = _getchunk(A,i) | ||
| inds = eachchunk(A)[i.I] | ||
| wrapchunk(tile, inds) | ||
| end | ||
|
|
||
| Base.getindex(A::TiledDiskArray, i::ChunkIndex{N,OneBasedChunks}) where {N} = | ||
| _getchunk(A, i) | ||
|
|
||
|
|
||
|
|
||
| function _getchunk(A::TiledDiskArray, i::ChunkIndex) | ||
| A.tilefunction(i.I.I...) | ||
| end | ||
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.
remove