From e7ad672645767b5dce963c869bd6c769539f6557 Mon Sep 17 00:00:00 2001 From: Datseris Date: Tue, 17 Nov 2020 13:31:50 +0100 Subject: [PATCH] extend indexing ala dimensional data for Coord --- src/physical_dimensions/spatial_equalarea.jl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/physical_dimensions/spatial_equalarea.jl b/src/physical_dimensions/spatial_equalarea.jl index 67e5912f..3b75a39b 100644 --- a/src/physical_dimensions/spatial_equalarea.jl +++ b/src/physical_dimensions/spatial_equalarea.jl @@ -111,9 +111,14 @@ function coord_latitudes_between(c, l1, l2) return idxs[i1][1]:idxs[i2][end] end -# function DimensionalData.dims2indices(c::Coord, sel::Lat{Between}) -# -# end +# This method is necessary so that I can do A[Coord(Lat(...))] +function DimensionalData._dims2indices(c::Coord, sel::Coord{ <: Lat{ <: Between}}, emptyval = Colon()) + l1, l2 = sel.val.val.val + return coord_latitudes_between(c, l1, l2) # this is Vector{Int} +end -# I need to extend dims2indices(c::Coord, selector inside coord)) -# where `c = dims(A, Coord)` for `A::ClimArray`. +# This allows Between to access Coord directly and be translated to latitude +function DimensionalData.sel2indices(c::Coord, sel::Between{Tuple{X,Y}}) where {X<:Real, Y<:Real} + l1, l2 = sel.val + return coord_latitudes_between(c, l1, l2) # this is Vector{Int} +end