Skip to content

Commit 1e13b6e

Browse files
committed
Add AxisKeys
1 parent d233815 commit 1e13b6e

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

Project.toml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,3 @@ DataStructures = "0.17, 0.18"
1414
Requires = "1"
1515
julia = "1.6"
1616

17-
[extras]
18-
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
19-
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
20-
AxisIndices = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11"
21-
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
22-
NamedDims = "356022a1-0364-5f58-8944-0da4b18d706f"
23-
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
24-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
25-
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"
26-
27-
[targets]
28-
test = ["Test", "DimensionalData", "AxisArrays", "ArchGDAL", "AxisIndices", "NetCDF", "Zarr", "NamedDims"]

src/YAXArrayBase.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ function __init__()
3131

3232
@require AxisIndices="f52c9ee2-1b1c-4fd8-8546-6350938c7f11" include("axisarrays/axisindices.jl")
3333

34+
@require AxisKeys="94b1ba4f-4ee9-5380-92f1-94cde586c3c5" include("axisarrays/axiskeys.jl")
35+
3436
@require ArchGDAL="c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" begin
3537
include("axisarrays/archgdal.jl")
3638
include("datasets/archgdal.jl")

src/axisarrays/axiskeys.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import .AxisKeys
2+
3+
dimnames(a::AxisKeys.KeyedArray) = AxisKeys.dimnames(a)
4+
5+
dimvals(a::AxisKeys.KeyedArray,i) = AxisKeys.getproperty(a,AxisKeys.dimnames(a,i))
6+
7+
getdata(a::AxisKeys.KeyedArray) = parent(parent(a))
8+
9+
yaxcreate(::Type{<:AxisKeys.KeyedArray}, data, dnames, dvals, atts) =
10+
AxisKeys.KeyedArray(data; map(i->dnames[i]=>dvals[i],1:ndims(data))...)

test/Project.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[deps]
2+
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
3+
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
4+
AxisIndices = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11"
5+
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
6+
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
7+
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
8+
NamedDims = "356022a1-0364-5f58-8944-0da4b18d706f"
9+
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
10+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
11+
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"

test/arrays.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ YAXArrayBase.getattributes(::M) = Dict{String,Any}("a1"=>5, "a2"=>"att")
1818
@test dimvals(d,2) == 1.5:0.5:3.0
1919
end
2020

21+
@testset "AxisKeys" begin
22+
using AxisKeys: KeyedArray
23+
d = yaxconvert(KeyedArray,M())
24+
@test d isa KeyedArray
25+
@test getdata(d) == reshape(1:12,3,4)
26+
@test YAXArrayBase.dimnames(d) == (:x, :y)
27+
@test dimvals(d,1) == 0.5:1.0:2.5
28+
@test dimvals(d,2) == 1.5:0.5:3.0
29+
end
30+
31+
2132
@testset "AxisArrays" begin
2233
using AxisArrays: AxisArrays
2334
d = yaxconvert(AxisArrays.AxisArray,M())

0 commit comments

Comments
 (0)