diff --git a/Project.toml b/Project.toml index 76e5a44a..addc1737 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" [compat] CFTime = "0.1.1, 0.2" -CommonDataModel = "0.3.4" +CommonDataModel = "0.4" DataStructures = "0.17, 0.18" DiskArrays = "0.4.5" NetCDF_jll = "=400.701.400, =400.702.400, =400.902.5, =400.902.208, =400.902.209, =400.902.211, =401.900.300" diff --git a/src/NCDatasets.jl b/src/NCDatasets.jl index 945e38c8..21d6c20c 100644 --- a/src/NCDatasets.jl +++ b/src/NCDatasets.jl @@ -41,7 +41,7 @@ import CommonDataModel: AbstractDataset, AbstractVariable, varbyattrib, CFStdName, @CF_str, ancillaryvariables, filter, coord, bounds, MFDataset, MFCFVariable, DeferDataset, metadata, Resource, - SubDataset, SubVariable, subsub, + SubDataset, SubVariable, chunking, deflate, checksum, fillmode, iswritable, sync, CatArrays, SubDataset, @@ -74,9 +74,6 @@ include("multifile.jl") include("ncgen.jl") include("precompile.jl") -DiskArrays.@implement_diskarray NCDatasets.Variable - - export CatArrays export CFTime export daysinmonth, daysinyear, yearmonthday, yearmonth, monthday diff --git a/src/variable.jl b/src/variable.jl index 7c319131..f4b53353 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -37,8 +37,6 @@ Return a tuple of integers with the size of the variable `var`. Base.size(v::Variable{T,N}) where {T,N} = ntuple(i -> nc_inq_dimlen(v.ds.ncid,v.dimids[i]),Val(N)) -Base.view(v::Variable,indices::Union{Int,Colon,AbstractVector{Int}}...) = SubVariable(v,indices...) - """ renameVar(ds::NCDataset,oldname,newname) @@ -433,6 +431,15 @@ function _write_data_to_nc(v::Variable{T}, data, indexes::AbstractRange{<:Intege return nc_put_vars(v.ds.ncid,v.varid,start,count,stride,T.(data)) end +# materialize disk arrays +function _write_data_to_nc(v::Variable{T,N},data::DiskArrays.AbstractDiskArray,indexes::Integer...) where {T,N} + return _write_data_to_nc(v,Array(data),indexes...) +end + +function _write_data_to_nc(v::Variable{T}, data::DiskArrays.AbstractDiskArray, indexes::AbstractRange{<:Integer}...) where T + return _write_data_to_nc(v,Array(data),indexes...) +end + function eachchunk(v::Variable) # storage will be reported as chunked for variables with unlimited dimension # by _chunking and chunksizes will 1 for the unlimited dimensions diff --git a/test/test_subvariable.jl b/test/test_subvariable.jl index eb77376b..c211a9dd 100644 --- a/test/test_subvariable.jl +++ b/test/test_subvariable.jl @@ -1,25 +1,10 @@ using NCDatasets -using NCDatasets: subsub, SubDataset +using NCDatasets: SubDataset using DataStructures using Test - -@test subsub((1:10,),(2:10,)) == (2:10,) -@test subsub((2:10,),(2:9,)) == (3:10,) -@test subsub((2:2:10,),(2:3,)) == (4:2:6,) -@test subsub((:,),(2:4,)) == (2:4,) -@test subsub((2:2:10,),(3,)) == (6,) -@test subsub((2:2:10,:),(2:3,2:4)) == (4:2:6,2:4) -@test subsub((2:2:10,:),(2:3,2)) == (4:2:6,2) -@test subsub((1,:),(2:3,)) == (1,2:3) -@test subsub((1,:),(1,)) == (1,1) - -A = rand(10,10) -ip = (2:2:10,:) -i = (2:3,2:4) -j = subsub(ip,i) -A[ip...][i...] == A[j...] - +import CommonDataModel +import DiskArrays fname = tempname() @@ -90,6 +75,9 @@ ncvar_view = view(view(ncvar,:,1:2),1:2:6,:) @test data_view == Array(ncvar_view) @test data_view == ncvar_view +@test ncvar_view isa CommonDataModel.SubVariable +@test ncvar_view isa DiskArrays.AbstractSubDiskArray + ind = CartesianIndex(1,1) @test ncvar_view[ind] == data_view[ind] diff --git a/test/test_variable.jl b/test/test_variable.jl index 7b07ceab..65a252be 100644 --- a/test/test_variable.jl +++ b/test/test_variable.jl @@ -3,6 +3,7 @@ using Dates using Printf using NCDatasets using DataStructures +import DiskArrays sz = (4,5) filename = tempname() @@ -11,6 +12,8 @@ filename = tempname() # rm(filename) #end +@test NCDatasets.Variable <: DiskArrays.AbstractDiskArray + # The mode "c" stands for creating a new file (clobber) NCDataset(filename,"c") do ds