Skip to content

Commit

Permalink
use dims keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Freudenberg committed Oct 22, 2023
1 parent 54d7a2e commit 4d1d622
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/methods/crop_extend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,15 @@ function _crop_to(x, to; kw...)
return _crop_to(x, ext; kw...)
end
end
function _crop_to(A, to::RasterStackOrArray; kw...)
target_dims = get(kw, :dims, name.(dims(to)))
return _crop_to(A, dims(to, target_dims); kw...)
end
_crop_to(A, to::RasterStackOrArray; dims=DD.dims(to), kw...) = _crop_to(A, DD.dims(to, dims); kw...)
function _crop_to(x, to::DimTuple; kw...)
# We can only crop to sampled dims (e.g. not categorical dims like Band)
sampled = reduce(to; init=()) do acc, d
lookup(d) isa AbstractSampled ? (acc..., d) : acc
end
return _crop_to(x, Extents.extent(to); kw...)
end
function _crop_to(x, to::Extents.Extent; touches=false, kw...)
function _crop_to(x, to::Extents.Extent; touches=false)
ds = dims(x, map(key2dim, keys(to)))
# Take a view over the bounds
_without_mapped_crs(x) do x1
Expand Down
6 changes: 3 additions & 3 deletions test/sources/gdal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ gdalpath = maybedownload(url)

@testset "other fields" begin
# This file has an inorrect missing value
@test missingval(gdalarray) == nothing
@test missingval(gdalarray) === nothing
@test metadata(gdalarray) isa Metadata{GDALsource,Dict{String,Any}}
@test basename(metadata(gdalarray)["filepath"]) == "cea.tif"
metadata(gdalarray)["filepath"]
@test name(gdalarray) == :test
@test label(gdalarray) == "test"
@test units(gdalarray) == nothing
@test units(gdalarray) === nothing
@test crs(dims(gdalarray, Y)) isa WellKnownText
@test crs(dims(gdalarray, X)) isa WellKnownText
@test crs(gdalarray) isa WellKnownText
Expand Down Expand Up @@ -256,7 +256,7 @@ gdalpath = maybedownload(url)
@test dims(geoA) isa Tuple{<:X,Y}
@test refdims(geoA) isa Tuple{<:Band}
@test metadata(geoA) == metadata(gdalarray)
@test missingval(geoA) == nothing
@test missingval(geoA) === nothing
@test name(geoA) == :test
end

Expand Down

0 comments on commit 4d1d622

Please sign in to comment.