Attributes
The NetCDF dataset (as returned by NCDataset
or NetCDF groups) and the NetCDF variables (as returned by getindex
, variable
or defVar
) have the field attrib
which has the type NCDatasets.Attributes
and behaves like a julia dictionary.
Base.getindex
— Methodgetindex(a::Attributes,name::SymbolOrString)
Return the value of the attribute called name
from the attribute list a
. Generally the attributes are loaded by indexing, for example:
ds = NCDataset("file.nc")
-title = ds.attrib["title"]
Base.setindex!
— MethodBase.setindex!(a::Attributes,data,name::SymbolOrString)
Set the attribute called name
to the value data
in the attribute list a
. data
can be a vector or a scalar. A scalar is handeld as a vector with one element in the NetCDF data model.
Generally the attributes are defined by indexing, for example:
ds = NCDataset("file.nc","c")
+Attributes · NCDatasets.jl Attributes
The NetCDF dataset (as returned by NCDataset
or NetCDF groups) and the NetCDF variables (as returned by getindex
, variable
or defVar
) have the field attrib
which has the type NCDatasets.Attributes
and behaves like a julia dictionary.
Base.getindex
— Methodgetindex(a::Attributes,name::SymbolOrString)
Return the value of the attribute called name
from the attribute list a
. Generally the attributes are loaded by indexing, for example:
using NCDatasets
+ds = NCDataset("file.nc")
+title = ds.attrib["title"]
Base.setindex!
— MethodBase.setindex!(a::Attributes,data,name::SymbolOrString)
Set the attribute called name
to the value data
in the attribute list a
. data
can be a vector or a scalar. A scalar is handeld as a vector with one element in the NetCDF data model.
Generally the attributes are defined by indexing, for example:
ds = NCDataset("file.nc","c")
ds.attrib["title"] = "my title"
-close(ds)
If data
is a string, then attribute is saved as a list of NetCDF characters (NC_CHAR
) with the appropriate length. To save the attribute as a string (NC_STRING
) you can use the following:
ds = NCDataset("file.nc","c")
-ds.attrib["title"] = ["my title"]
-close(ds)
sourceBase.keys
— MethodBase.keys(a::Attributes)
Return a list of the names of all attributes.
sourceBase.delete!
— MethodBase.delete!(a::Attributes, name)
Delete the attribute name
from the attribute list a
.
sourceLoading all attributes as a Dict
can be achieved by passing ds.attrib
(where ds
is the NCDataset
) as argument to Dict
.
using NCDatasets
+close(ds)
Base.keys
— MethodBase.keys(a::Attributes)
Return a list of the names of all attributes.
Base.delete!
— MethodBase.delete!(a::Attributes, name)
Delete the attribute name
from the attribute list a
.
Loading all attributes as a Dict
can be achieved by passing ds.attrib
(where ds
is the NCDataset
) as argument to Dict
.
using NCDatasets
ncfile = download("https://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3-example.nc");
ds = NCDataset(ncfile);
attributes_as_dictionary = Dict(ds.attrib)
@@ -29,4 +28,4 @@
))
Note that Dict
does not perserve the order of the attributes. Therefore an OrderedDict
from the package DataStructures
is preferable.
Or one could use simply the fillvalue
parameter of defVar
.
ncv1 = defVar(ds,"v1", UInt8, ("longitude", "latitude", "time"), fillvalue = UInt8(255), attrib = [
"add_offset" => -1.0,
"scale_factor" => 5.0,
-])
Settings
This document was generated with Documenter.jl version 0.27.25 on Thursday 2 November 2023. Using Julia version 1.9.3.