Dimensions
In the NetCDF data model, dimensions have names and a length (but possibly an unlimited length) and are defined for a NetCDF dataset (or group). For a given Variable
or CFVariable
,the names of the corresponding dimensions are obtained with using dimnames
.
Base.keys
— Methodkeys(d::Dimensions)
Return a list of all dimension names in NCDataset ds
.
Examples
ds = NCDataset("results.nc", "r");
dimnames = keys(ds.dim)
Base.haskey
— Methodhaskey(ds::NCDataset,name)
haskey(d::Dimensions,name)
haskey(ds::Attributes,name)
Return true if the NCDataset ds
(or dimension/attribute list) has a variable (dimension/attribute) with the name name
. For example:
ds = NCDataset("/tmp/test.nc","r")
if haskey(ds,"temperature")
println("The file has a variable 'temperature'")
end
if haskey(ds.dim,"lon")
println("The file has a dimension 'lon'")
end
This example checks if the file /tmp/test.nc
has a variable with the name temperature
and a dimension with the name lon
.
CommonDataModel.defDim
— FunctiondefDim(ds::NCDataset,name,len)
Define a dimension in the data set ds
with the given name
and length len
. If len
is the special value Inf
, then the dimension is considered as unlimited
, i.e. it will grow as data is added to the NetCDF file.
For example:
using NCDatasets
ds = NCDataset("/tmp/test.nc","c")
defDim(ds,"lon",100)
# [...]
close(ds)
This defines the dimension lon
with the size 100.
To create a variable with an unlimited dimensions use for example:
using NCDatasets
ds = NCDataset("/tmp/test2.nc","c")
defDim(ds,"lon",10)
defDim(ds,"lat",10)
defDim(ds,"time",Inf)
defVar(ds,"unlimited_variable",Float64,("lon","lat","time"))
@show ds.dim["time"]
# returns 0 as no data is added
ds["unlimited_variable"][:,:,1:4] = randn(10,10,4)
@show ds.dim["time"]
# returns now 4 as 4 time slice have been added
close(ds)
CommonDatamodel.defDim(ds::AbstractDataset,name::SymbolOrString,len)
Create dimension with the name name
in the data set ds
with the length len
. len
can be Inf
for unlimited dimensions.
CommonDataModel.unlimited
— Methodunlimited(d::Dimensions)
Return the names of all unlimited dimensions.
Base.setindex!
— Methodsetindex!(d::Dimensions,len,name::AbstractString)
Defines the dimension called name
to the length len
, for example:
ds = NCDataset("file.nc","c")
ds.dim["longitude"] = 100
If len
is the special value Inf
, then the dimension is considered as unlimited
, i.e. it will grow as data is added to the NetCDF file.
NCDatasets.renameDim
— MethodrenameDim(ds::NCDataset,oldname::SymbolOrString,newname::SymbolOrString)
Renames the dimenion oldname
in the dataset ds
with the name newname
.
One can iterate over a list of dimensions as follows:
for (dimname,dim) in ds.dim
# all dimensions
@show (dimname,dim)
end