Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions src/NCDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
24 changes: 6 additions & 18 deletions test/test_subvariable.jl
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions test/test_variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Dates
using Printf
using NCDatasets
using DataStructures
import DiskArrays

sz = (4,5)
filename = tempname()
Expand All @@ -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

Expand Down
Loading