Skip to content

Commit

Permalink
fix resize
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Jul 29, 2023
1 parent b518251 commit 48033e3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ function RasterStack(
filenames::Union{AbstractArray{<:AbstractString},Tuple{<:AbstractString,Vararg}};
name=map(filekey, filenames), keys=name, kw...
)
_checkname(NTuple{<:Any,Symbol}, name)
RasterStack(NamedTuple{Tuple(keys)}(Tuple(filenames)); kw...)
end
function RasterStack(filenames::NamedTuple{K,<:Tuple{<:AbstractString,Vararg}};
Expand All @@ -193,7 +194,6 @@ function RasterStack(filenames::NamedTuple{K,<:Tuple{<:AbstractString,Vararg}};
end
# Multi Raster stack from Tuple of AbstractArray
function RasterStack(data::Tuple{Vararg{<:AbstractArray}}, dims::Tuple; name=nothing, keys=name, kw...)
isnothing(keys) && throw(ArgumentError("`name` or `keys` keyword must be a tuple of `Symbol`"))
return RasterStack(NamedTuple{cleankeys(keys)}(data), dims; kw...)
end
# Multi Raster stack from NamedTuple of AbstractArray
Expand Down Expand Up @@ -282,7 +282,7 @@ end
function _layer_stack(filename;
dims=nothing, refdims=(), metadata=nothing, crs=nothing, mappedcrs=nothing,
layerdims=nothing, layermetadata=nothing, missingval=nothing,
source=nothing, name=nothing, keys=name, kw...
source=nothing, name=nothing, keys=name, resize=nothing, kw...
)
crs = defaultcrs(source, crs)
mappedcrs = defaultmappedcrs(source, mappedcrs)
Expand All @@ -303,7 +303,6 @@ end
function RasterStack(A::Raster;
layersfrom=nothing, name=nothing, keys=name, metadata=metadata(A), refdims=refdims(A), kw...
)

keys = keys isa Union{AbstractString,Symbol,Name} ? (keys,) : keys
layers = if isnothing(layersfrom)
keys = if keys isa Nothing
Expand Down
1 change: 0 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,3 @@ function _float64_xy_extent(ext::Extents.Extent)
ybounds = map(Float64, ext.Y)
return Extents.Extent(X=xbounds, Y=ybounds)
end

5 changes: 5 additions & 0 deletions test/sources/gdal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ end
rm(no_ext)
end

@testset "name" begin
gdalstack_names = RasterStack((gdalpath, gdalpath); name=(:c, :d))
@test keys(gdalstack_names) == (:c, :d)
end

@testset "methods" begin
@testset "mean" begin
means = map(A -> mean(parent(A); dims=2), gdalstack)
Expand Down
12 changes: 12 additions & 0 deletions test/sources/ncdatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ end
@test mappedcrs(st) == EPSG(3857)
end

@testset "name" begin
@testset "multi name from single file" begin
@time small_stack = RasterStack(ncmulti; name=(:sofllac, :xlvi))
@test keys(small_stack) == (:sofllac, :xlvi)
end
@testset "multi file with single name" begin
tempnc = tempname() * ".nc"
write(tempnc, rebuild(ncarray; name=:tos2))
@time small_stack = RasterStack((ncsingle, tempnc); name=(:tos, :tos2))
end
end

@testset "load ncstack" begin
@test ncstack isa RasterStack
@test all(ismissing, missingval(ncstack))
Expand Down

0 comments on commit 48033e3

Please sign in to comment.