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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

better filestack performance #614

Merged
merged 25 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more source fixes
  • Loading branch information
rafaqz committed Mar 23, 2024
commit 259f5a8cadaa03954b5500aef18c422704d0a952
4 changes: 2 additions & 2 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ end
function Raster(filename::AbstractString;
name=nothing, key=name, source=nothing, kw...
)::Raster
source = isnothing(source) ? _sourcetype(filename) : _sourcetype(source)
source = _sourcetype(filename, source)
Base.invokelatest() do
_open(filename; source) do ds
key = filekey(ds, key)
Expand All @@ -265,7 +265,7 @@ function Raster(ds, filename::AbstractString, key=nothing;
source=nothing, write=false, lazy=false, dropband=true,
metadata=_metadata(ds), missingval=missingval(ds)
)::Raster
source = isnothing(source) ? _sourcetype(filename) : _sourcetype(source)
source = _sourcetype(filename, source)
crs = defaultcrs(source, crs)
mappedcrs = defaultmappedcrs(source, mappedcrs)
dims = dims isa Nothing ? _dims(ds, crs, mappedcrs) : dims
Expand Down
4 changes: 3 additions & 1 deletion src/sources/sources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ function Base.showerror(io::IO, e::BackendException)
end

# Get the source backend for a file extension, falling back to GDALsource
_sourcetype(filename::AbstractString, s::Source) = s
_sourcetype(filename::AbstractString, s) = _sourcetype(s)
_sourcetype(filename::AbstractString, ::Nothing) = _sourcetype(filename)
_sourcetype(filename::AbstractString) = get(EXT2SOURCE, splitext(filename)[2], GDALsource())
_sourcetype(filenames::NamedTuple) = _sourcetype(first(filenames))
_sourcetype(filename, ext::Nothing) = _sourcetype(filename)
_sourcetype(filename, ext) = get(EXT2SOURCE, ext, GDALsource())
_sourcetype(source::Source) = source
_sourcetype(source::Type{<:Source}) = source()
Expand Down
6 changes: 3 additions & 3 deletions src/stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function RasterStack(filenames::NamedTuple{K,<:Tuple{<:AbstractString,Vararg}};
crs=nothing, mappedcrs=nothing, source=nothing, lazy=false, dropband=true, kw...
) where K
layers = map(keys(filenames), values(filenames)) do key, fn
source = source isa Nothing ? _sourcetype(fn) : _sourcetype(source)
source = _sourcetype(fn, source)
crs = defaultcrs(source, crs)
mappedcrs = defaultmappedcrs(source, mappedcrs)
_open(source, fn; key) do ds
Expand Down Expand Up @@ -237,7 +237,7 @@ end
function RasterStack(filename::AbstractString;
source=nothing, name=nothing, keys=name, lazy=false, dropband=true, kw...
)
source = isnothing(source) ? _sourcetype(filename) : _sourcetype(source)
source = _sourcetype(filename, source)
st = if isdir(filename)
# Load as a whole directory
filenames = readdir(filename)
Expand Down Expand Up @@ -298,7 +298,7 @@ function _layer_stack(filename;
missingval = missingval isa Nothing ? Rasters.missingval(ds) : missingval
tuplekeys = Tuple(map(Symbol, layers.keys))
data = if lazy
FileStack{source}(ds, filename; keys=tuplekeys, vars=Tuple(layers.vars))
FileStack{typeof(source)}(ds, filename; keys=tuplekeys, vars=Tuple(layers.vars))
else
NamedTuple{tuplekeys}(map(Array, layers.vars))
end
Expand Down
Loading