Skip to content

Commit d779f74

Browse files
authored
Switch to extensions instead of requires for datasets (#24)
* Switch to extensions instead of requires for datasets * Move all array interface implementations to extensions This moves everything from using Requires to the new extensions setup. * Switch the array tests to testitems This ensures, that the tests for different backends are independent. * Remove the Requires setup for lower julia versions We decided to only support julia versions larger than 1.9 * Switch CI to test on julia 1.9 instead of 1.6 When we restrict the Julia version to 1.9 we should also stop testing on 1.6 * Remove Zarr and NetCDF as dependencies * Remove AxisIndices This seems to be not maintained anymore with the last commit three years ago * Stop tracking Manifest.toml * Remove AxisIndices also from test environment * Add testing on nightly * Bump version to 0.7.0
1 parent c9d7d6d commit d779f74

20 files changed

+1061
-230
lines changed

.github/workflows/CI.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
version:
16-
- '1.6'
16+
- '1.9'
1717
- '1'
18+
- 'nightly'
1819
os:
1920
- ubuntu-latest
2021
- macOS-latest

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.jl.mem
44
/deps/deps.jl
55
/docs/build
6+
Manifest.toml

Manifest.toml

-105
This file was deleted.

Project.toml

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
11
name = "YAXArrayBase"
22
uuid = "90b8fcef-0c2d-428d-9c56-5f86629e9d14"
33
authors = ["Fabian Gans <[email protected]>"]
4-
version = "0.6.1"
4+
version = "0.7.0"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
88
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
99
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
10-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
10+
1111

1212
[compat]
13-
DataStructures = "0.17, 0.18"
14-
Requires = "1"
15-
julia = "1.6"
13+
DataStructures = "0.17,0.18"
14+
julia = "1.9"
15+
ArchGDAL = "0.10"
16+
AxisArrays = "0.4"
17+
AxisKeys = "0.2"
18+
DimensionalData = "0.24"
19+
NetCDF = "0.11"
20+
Zarr = "0.8"
21+
22+
[extensions]
23+
ArchGDALExt = "ArchGDAL"
24+
AxisArraysExt = "AxisArrays"
25+
AxisKeysExt = "AxisKeys"
26+
DimensionalDataExt = "DimensionalData"
27+
NamedDimsExt = "NamedDims"
28+
NetCDFExt = "NetCDF"
29+
ZarrExt = "Zarr"
1630

31+
[weakdeps]
32+
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
33+
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
34+
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
35+
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
36+
NamedDims = "356022a1-0364-5f58-8944-0da4b18d706f"
37+
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
38+
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"

src/axisarrays/archgdal.jl renamed to ext/ArchGDALExt/ArchGDALExt.jl

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import .ArchGDAL: RasterDataset, AbstractRasterBand,
1+
module ArchGDALExt
2+
import ArchGDAL: RasterDataset, AbstractRasterBand,
23
getgeotransform, width, height, getname, getcolorinterp,
34
getband, nraster, getdataset
5+
using ArchGDAL: ArchGDAL as AG
6+
import YAXArrayBase: dimname, dimnames, dimvals, iscontdim, getattributes, getdata, yaxcreate
7+
8+
#include("archgdaldataset.jl")
49

510
function dimname(a::RasterDataset, i)
611
if i == 1
@@ -33,10 +38,10 @@ end
3338
iscontdim(a::RasterDataset, i) = i < 3 ? true : nraster(a)<8
3439
function getattributes(a::RasterDataset)
3540
globatts = Dict{String,Any}(
36-
"projection_PROJ4"=>ArchGDAL.toPROJ4(ArchGDAL.newspatialref(ArchGDAL.getproj(a))),
37-
"projection_WKT"=>ArchGDAL.toWKT(ArchGDAL.newspatialref(ArchGDAL.getproj(a))),
41+
"projection_PROJ4"=>AG.toPROJ4(AG.newspatialref(AG.getproj(a))),
42+
"projection_WKT"=>AG.toWKT(AG.newspatialref(AG.getproj(a))),
3843
)
39-
bands = (getbandattributes(ArchGDAL.getband(a, i)) for i in 1:size(a, 3))
44+
bands = (getbandattributes(AG.getband(a, i)) for i in 1:size(a, 3))
4045
allbands = mergewith(bands...) do a1,a2
4146
isequal(a1,a2) ? a1 : missing
4247
end
@@ -65,7 +70,7 @@ function dimvals(b::AbstractRasterBand, i)
6570
end
6671
iscontdim(a::AbstractRasterBand, i) = true
6772
function getattributes(a::AbstractRasterBand)
68-
atts = getattributes(ArchGDAL.RasterDataset(ArchGDAL.getdataset(a)))
73+
atts = getattributes(AG.RasterDataset(AG.getdataset(a)))
6974
bandatts = getbandattributes(a)
7075
merge(atts, bandatts)
7176
end
@@ -84,4 +89,5 @@ function getbandattributes(a::AbstractRasterBand)
8489
insertattifnot!(atts, AG.getoffset(a), "add_offset", iszero)
8590
insertattifnot!(atts, AG.getscale(a), "scale_factor", x->isequal(x, one(x)))
8691
atts
92+
end
8793
end

src/datasets/archgdal.jl renamed to ext/ArchGDALExt/archgdaldataset.jl

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import .ArchGDAL: RasterDataset, AbstractRasterBand,
2-
getgeotransform, width, height, getname, getcolorinterp,
3-
getband, nraster, getdataset, ArchGDAL
4-
using .ArchGDAL.DiskArrays: GridChunks, DiskArrays, eachchunk
5-
const AG = ArchGDAL
6-
71
struct GDALBand{T} <: AG.DiskArrays.AbstractDiskArray{T,2}
82
filename::String
93
band::Int
@@ -221,8 +215,10 @@ allow_parallel_write(::GDALDataset) = false
221215
allow_missings(::Type{<:GDALDataset}) = false
222216
allow_missings(::GDALDataset) = false
223217

224-
backendlist[:gdal] = GDALDataset
225-
push!(backendregex,r".tif$"=>GDALDataset)
226-
push!(backendregex,r".gtif$"=>GDALDataset)
227-
push!(backendregex,r".tiff$"=>GDALDataset)
228-
push!(backendregex,r".gtiff$"=>GDALDataset)
218+
function __init__()
219+
backendlist[:gdal] = GDALDataset
220+
push!(backendregex,r".tif$"=>GDALDataset)
221+
push!(backendregex,r".gtif$"=>GDALDataset)
222+
push!(backendregex,r".tiff$"=>GDALDataset)
223+
push!(backendregex,r".gtiff$"=>GDALDataset)
224+
end

src/axisarrays/axisarrays.jl renamed to ext/AxisArraysExt.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using .AxisArrays: AxisArrays, AxisArray
2-
1+
module AxisArraysExt
2+
using AxisArrays: AxisArrays, AxisArray
3+
import YAXArrayBase: dimname, dimnames, dimvals, iscontdim, getattributes, getdata, yaxcreate
34
dimname(a::AxisArray, i) = AxisArrays.axisnames(a)[i]
45
dimnames(a::AxisArray) = AxisArrays.axisnames(a)
56
dimvals(a::AxisArray, i) = AxisArrays.axisvalues(a)[i]
@@ -11,3 +12,4 @@ function yaxcreate(::Type{<:AxisArray}, data, dnames, dvals, atts)
1112
end
1213
AxisArray(data; d...)
1314
end
15+
end
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import .AxisKeys
2-
1+
module AxisKeysExt
2+
import AxisKeys
3+
import YAXArrayBase: dimname, dimnames, dimvals, iscontdim, getattributes, getdata, yaxcreate
34
dimnames(a::AxisKeys.KeyedArray) = AxisKeys.dimnames(a)
45

56
dimvals(a::AxisKeys.KeyedArray,i) = AxisKeys.getproperty(a,AxisKeys.dimnames(a,i))
@@ -8,3 +9,4 @@ getdata(a::AxisKeys.KeyedArray) = parent(parent(a))
89

910
yaxcreate(::Type{<:AxisKeys.KeyedArray}, data, dnames, dvals, atts) =
1011
AxisKeys.KeyedArray(data; map(i->dnames[i]=>dvals[i],1:ndims(data))...)
12+
end

src/axisarrays/dimensionaldata.jl renamed to ext/DimensionalDataExt.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using .DimensionalData: DimArray, DimensionalData, data, Dim, metadata
2-
1+
module DimensionalDataExt
2+
using DimensionalData: DimArray, DimensionalData, data, Dim, metadata
3+
import YAXArrayBase: dimname, dimnames, dimvals, iscontdim, getattributes, getdata, yaxcreate
34
_dname(::DimensionalData.Dim{N}) where N = N
45
_dname(d::DimensionalData.Dimension) = DimensionalData.name(d)
56
dimname(x::DimArray, i) = _dname(DimensionalData.dims(x)[i])
@@ -17,3 +18,4 @@ function yaxcreate(::Type{<:DimArray},data,dnames,dvals,atts)
1718
end
1819
DimArray(data,d,metadata = atts)
1920
end
21+
end
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
using .NamedDims: NamedDimsArray
1+
module NamedDimsExt
2+
using NamedDims: NamedDimsArray
3+
import YAXArrayBase: dimname, dimnames, dimvals, iscontdim, getattributes, getdata, yaxcreate
24
dimname(a::NamedDimsArray{N},i) where N = N[i]
35
dimnames(a::NamedDimsArray{N}) where N = N
46
getdata(a::NamedDimsArray) = parent(a)
57
function yaxcreate(::Type{<:NamedDimsArray},data, dnames, dvals, atts)
68
n = ntuple(i->dnames[i],ndims(data))
79
NamedDimsArray(data,n)
810
end
11+
end

src/datasets/netcdf.jl renamed to ext/NetCDFExt.jl

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using .NetCDF
1+
module NetCDFExt
2+
import YAXArrayBase: YAXArrayBase as YAB
3+
using NetCDF
24

35
"""
46
NetCDFDataset
@@ -43,37 +45,40 @@ function readblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...)
4345
aout .= aouttemp
4446
end
4547
end
46-
iscompressed(v::NetCDFVariable) = NetCDF.open(v->v.compress > 0, v.filename, v.varname)
48+
YAB.iscompressed(v::NetCDFVariable) = NetCDF.open(v->v.compress > 0, v.filename, v.varname)
4749

4850
Base.size(v::NetCDFVariable) = v.size
4951

50-
get_var_dims(ds::NetCDFDataset,name) = NetCDF.open(v->map(i->i.name,v[name].dim),ds.filename)
51-
get_varnames(ds::NetCDFDataset) = NetCDF.open(v->collect(keys(v.vars)),ds.filename)
52-
get_var_attrs(ds::NetCDFDataset, name) = NetCDF.open(v->v[name].atts,ds.filename)
53-
get_global_attrs(ds::NetCDFDataset) = NetCDF.open(nc->nc.gatts, ds.filename)
52+
YAB.get_var_dims(ds::NetCDFDataset,name) = NetCDF.open(v->map(i->i.name,v[name].dim),ds.filename)
53+
YAB.get_varnames(ds::NetCDFDataset) = NetCDF.open(v->collect(keys(v.vars)),ds.filename)
54+
YAB.get_var_attrs(ds::NetCDFDataset, name) = NetCDF.open(v->v[name].atts,ds.filename)
55+
YAB.get_global_attrs(ds::NetCDFDataset) = NetCDF.open(nc->nc.gatts, ds.filename)
5456
function Base.getindex(ds::NetCDFDataset, i)
5557
s,et = NetCDF.open(j->(size(j),eltype(j)),ds.filename,i)
5658
NetCDFVariable{et,length(s)}(ds.filename, i, s)
5759
end
5860
Base.haskey(ds::NetCDFDataset,k) = NetCDF.open(nc->haskey(nc.vars,k),ds.filename)
5961

60-
function add_var(p::NetCDFDataset, T::Type, varname, s, dimnames, attr;
62+
function YAB.add_var(p::NetCDFDataset, T::Type, varname, s, dimnames, attr;
6163
chunksize=s, compress = -1)
6264
dimsdescr = Iterators.flatten(zip(dimnames,s))
6365
nccreate(p.filename, varname, dimsdescr..., atts = attr, t=T, chunksize=chunksize, compress=compress)
6466
NetCDFVariable{T,length(s)}(p.filename,varname,(s...,))
6567
end
6668

67-
function create_empty(::Type{NetCDFDataset}, path, gatts=Dict())
69+
function YAB.create_empty(::Type{NetCDFDataset}, path, gatts=Dict())
6870
NetCDF.create(_->nothing, path, NcVar[], gatts = gatts)
6971
NetCDFDataset(path)
7072
end
7173

72-
allow_parallel_write(::Type{<:NetCDFDataset}) = false
73-
allow_parallel_write(::NetCDFDataset) = false
74+
YAB.allow_parallel_write(::Type{<:NetCDFDataset}) = false
75+
YAB.allow_parallel_write(::NetCDFDataset) = false
7476

75-
allow_missings(::Type{<:NetCDFDataset}) = false
76-
allow_missings(::NetCDFDataset) = false
77+
YAB.allow_missings(::Type{<:NetCDFDataset}) = false
78+
YAB.allow_missings(::NetCDFDataset) = false
7779

78-
backendlist[:netcdf] = NetCDFDataset
79-
push!(backendregex,r".nc$"=>NetCDFDataset)
80+
function __init__()
81+
YAB.backendlist[:netcdf] = NetCDFDataset
82+
push!(YAB.backendregex,r".nc$"=>NetCDFDataset)
83+
end
84+
end

0 commit comments

Comments
 (0)