From 9ea0f03d1722d5c419826a8777f1f5047f89df83 Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Thu, 16 Nov 2023 13:36:02 +0100 Subject: [PATCH] replace CFVariable by CFVariable{T,N,<:Variable} --- src/cfvariable.jl | 4 ++-- src/variable.jl | 12 ++++++------ test/test_multifile.jl | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cfvariable.jl b/src/cfvariable.jl index cb1087f9..3ad5b385 100644 --- a/src/cfvariable.jl +++ b/src/cfvariable.jl @@ -246,7 +246,7 @@ export cfvariable v = getindex(ds::NCDataset, varname::AbstractString) Return the NetCDF variable `varname` in the dataset `ds` as a -`NCDataset.CFVariable`. The following CF convention are honored when the +`CFVariable`. The following CF convention are honored when the variable is indexed: * `_FillValue` or `missing_value` (which can be a list) will be returned as `missing`. `NCDatasets` does not use implicitely the default NetCDF fill values when reading data. * `scale_factor` and `add_offset` are applied (output = `scale_factor` * `data_in_file` + `add_offset`) @@ -287,7 +287,7 @@ end dimsize(v::CFVariable) Get the size of a `CFVariable` as a named tuple of dimension → length. """ -function dimsize(v::Union{CFVariable,MFCFVariable,SubVariable}) +function dimsize(v::Union{CFVariable{T,N,<:Variable},MFCFVariable,SubVariable}) where {T,N} s = size(v) names = Symbol.(dimnames(v)) return NamedTuple{names}(s) diff --git a/src/variable.jl b/src/variable.jl index 4e2d5f8f..7c07de91 100644 --- a/src/variable.jl +++ b/src/variable.jl @@ -14,15 +14,15 @@ listVar(ncid) = String[nc_inq_varname(ncid,varid) """ - ds = dataset(var::Union{Variable,CFVariable}) - ds = NCDataset(var::Union{Variable,CFVariable}) + ds = dataset(var::Variable) + ds = NCDataset(var::Variable) Return the `NCDataset` containing the variable `var`. """ dataset(var::Variable) = var.ds # old function call, replace by CommonDataModel.dataset -NCDataset(v::Union{AbstractNCVariable,CFVariable}) = dataset(v) +NCDataset(v::AbstractNCVariable) = dataset(v) """ sz = size(var::Variable) @@ -286,7 +286,7 @@ function _chunking(v::Variable{T,N}) where {T,N} return storage,NTuple{N}(chunksizes) end -_chunking(v::CFVariable) = _chunking(v.var) +_chunking(v::CFVariable{T,N,<:Variable}) where {T,N} = _chunking(v.var) function _chunking(v) storage,chunksizes = chunking(v) @@ -449,8 +449,8 @@ function eachchunk(v::Variable) end haschunks(v::Variable) = (_chunking(v)[1] == :contiguous ? DiskArrays.Unchunked() : DiskArrays.Chunked()) -eachchunk(v::CFVariable) = eachchunk(v.var) -haschunks(v::CFVariable) = haschunks(v.var) +eachchunk(v::CFVariable{T,N,<:Variable}) where {T,N} = eachchunk(v.var) +haschunks(v::CFVariable{T,N,<:Variable}) where {T,N} = haschunks(v.var) _normalizeindex(n,ind::Base.OneTo) = 1:1:ind.stop _normalizeindex(n,ind::Colon) = 1:1:n diff --git a/test/test_multifile.jl b/test/test_multifile.jl index 0514072d..20e9a6cd 100644 --- a/test/test_multifile.jl +++ b/test/test_multifile.jl @@ -187,7 +187,7 @@ mfds = NCDataset(fnames,"a",deferopen = false); mfds[varname][2,2,:] = 1:length(fnames) mfds.attrib["history"] = "foo2" -@test_throws NCDatasets.NetCDFError NCDataset(fnames,"not-a-mode") +@test_throws Union{ArgumentError,NCDatasets.NetCDFError} NCDataset(fnames,"not-a-mode") @test keys(mfds) == [varname, "lat", "lon", "time"] @test keys(mfds.dim) == ["lon", "lat", "time"]