Skip to content

Commit

Permalink
Add AxisKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
meggart committed May 16, 2022
1 parent d233815 commit 1e13b6e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
12 changes: 0 additions & 12 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,3 @@ DataStructures = "0.17, 0.18"
Requires = "1"
julia = "1.6"

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

[targets]
test = ["Test", "DimensionalData", "AxisArrays", "ArchGDAL", "AxisIndices", "NetCDF", "Zarr", "NamedDims"]
2 changes: 2 additions & 0 deletions src/YAXArrayBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function __init__()

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

@require AxisKeys="94b1ba4f-4ee9-5380-92f1-94cde586c3c5" include("axisarrays/axiskeys.jl")

@require ArchGDAL="c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" begin
include("axisarrays/archgdal.jl")
include("datasets/archgdal.jl")
Expand Down
10 changes: 10 additions & 0 deletions src/axisarrays/axiskeys.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import .AxisKeys

dimnames(a::AxisKeys.KeyedArray) = AxisKeys.dimnames(a)

dimvals(a::AxisKeys.KeyedArray,i) = AxisKeys.getproperty(a,AxisKeys.dimnames(a,i))

getdata(a::AxisKeys.KeyedArray) = parent(parent(a))

yaxcreate(::Type{<:AxisKeys.KeyedArray}, data, dnames, dvals, atts) =
AxisKeys.KeyedArray(data; map(i->dnames[i]=>dvals[i],1:ndims(data))...)
11 changes: 11 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
AxisIndices = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11"
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
NamedDims = "356022a1-0364-5f58-8944-0da4b18d706f"
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"
11 changes: 11 additions & 0 deletions test/arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ YAXArrayBase.getattributes(::M) = Dict{String,Any}("a1"=>5, "a2"=>"att")
@test dimvals(d,2) == 1.5:0.5:3.0
end

@testset "AxisKeys" begin
using AxisKeys: KeyedArray
d = yaxconvert(KeyedArray,M())
@test d isa KeyedArray
@test getdata(d) == reshape(1:12,3,4)
@test YAXArrayBase.dimnames(d) == (:x, :y)
@test dimvals(d,1) == 0.5:1.0:2.5
@test dimvals(d,2) == 1.5:0.5:3.0
end


@testset "AxisArrays" begin
using AxisArrays: AxisArrays
d = yaxconvert(AxisArrays.AxisArray,M())
Expand Down

0 comments on commit 1e13b6e

Please sign in to comment.