Skip to content

Commit

Permalink
replace CFVariable by CFVariable{T,N,<:Variable}
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Nov 16, 2023
1 parent 21a9ba4 commit 9ea0f03
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/cfvariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test_multifile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 9ea0f03

Please sign in to comment.