Cropping a layer while omitting to specify one of the limits did not work properly. For example:
julia> temp = worldclim(1);
julia> temp[left = -145.0, right = -50.0, top = 75.0, bottom = 20.0];
julia> temp[left = -145.0, right = -50.0, top = 75.0];
ERROR: MethodError: no method matching #getindex#2(::Float64, ::Float64, ::Float64, ::Nothing, ::typeof(getindex), ::SimpleSDMPredictor{Float64})
Closest candidates are:
#getindex#2(::K, ::K, ::K, ::K, ::typeof(getindex), ::T) where {T<:SimpleSDMLayer, K<:Union{Nothing, AbstractFloat}} at /home/gdansereau/github/SimpleSDMLayers.jl/src/lib/overloads.jl:166
Stacktrace:
[1] top-level scope at none:0
I fixed it with two tweaks to the getindex overload (the match_longitude calls and the types).
While at it, I also added an overload to crop based on a NamedTuple. I think it's useful as it allows to crop with a variable, which can be reused easily.
coords = (left = 145.0, right = -50.0, top = 75.0, bottom = 20.0)
temp[coords]
Cropping a layer while omitting to specify one of the limits did not work properly. For example:
I fixed it with two tweaks to the
getindex
overload (thematch_longitude
calls and the types).While at it, I also added an overload to crop based on a
NamedTuple
. I think it's useful as it allows to crop with a variable, which can be reused easily.I've added tests for both of these.