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.
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.
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:
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)
This page is about loading/writing, examining and operating directly on entire NetCDF datasets. For functions regarding the variables stored in them, see the Variables page.
Both variables and datasets share the functionality of the Attributes section.
This page is about loading/writing, examining and operating directly on entire NetCDF datasets. For functions regarding the variables stored in them, see the Variables page.
Both variables and datasets share the functionality of the Attributes section.
Opens a multi-file dataset in read-only "r" or append mode "a". fnames is a vector of file names.
Variables are aggregated over the first unlimited dimension or over the dimension aggdim if specified. Variables without the dimensions aggdim are not aggregated. All variables containing the dimension aggdim are aggregated. The variable who do not contain the dimension aggdim are assumed constant.
If variables should be aggregated over a new dimension (not present in the NetCDF file), one should set isnewdim to true. All NetCDF files should have the same variables, attributes and groupes. Per default, all variables will have an additional dimension unless they are marked as constant using the constvars parameter.
The append mode is only implemented when deferopen is false. If deferopen is false, all files are opened at the same time. However the operating system might limit the number of open files. In Linux, the limit can be controled with the command ulimit.
All metadata (attributes and dimension length are assumed to be the same for all NetCDF files. Otherwise reading the attribute of a multi-file dataset would be ambiguous. An exception to this rule is the length of the dimension over which the data is aggregated. This aggregation dimension can varify from file to file.
Setting the experimental flag _aggdimconstant to true means that the length of the aggregation dimension is constant. This speeds up the creating of a multi-file dataset as only the metadata of the first file has to be loaded.
Examples:
You can use Glob.jl to make fnames from a file pattern, e.g.
using NCDatasets, Glob
ds = NCDataset(glob("ERA5_monthly3D_reanalysis_*.nc"))
Aggregation over a new dimension:
using NCDatasets
@@ -27,7 +27,7 @@
ds = NCDataset(["foo$i.nc" for i = 1:3],aggdim = "sample", isnewdim = true)
size(ds["data"])
# output
-# (4, 3)
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")
@@ -36,7 +36,7 @@
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.
v = getindex(ds::AbstractDataset, varname::SymbolOrString)
Return the variable varname in the dataset ds as a 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.
scale_factor and add_offset are applied (output = scale_factor * data_in_file + add_offset)
time variables (recognized by the units attribute and possibly the calendar attribute) are returned usually as DateTime object. Note that CFTime.DateTimeAllLeap, CFTime.DateTimeNoLeap and CF.TimeDateTime360Day cannot be converted to the proleptic gregorian calendar used in julia and are returned as such. (See CFTime.jl for more information about those date types.) If a calendar is defined but not among the ones specified in the CF convention, then the data in the file is not converted into a date structure.
A call getindex(ds, varname) is usually written as ds[varname].
If variable represents a cell boundary, the attributes calendar and units of the related variables are used, if they are not specified. For example:
dimensions:
+end
This example checks if the file /tmp/test.nc has a variable with the name temperature and a dimension with the name lon.
v = getindex(ds::AbstractDataset, varname::SymbolOrString)
Return the variable varname in the dataset ds as a 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.
scale_factor and add_offset are applied (output = scale_factor * data_in_file + add_offset)
time variables (recognized by the units attribute and possibly the calendar attribute) are returned usually as DateTime object. Note that CFTime.DateTimeAllLeap, CFTime.DateTimeNoLeap and CF.TimeDateTime360Day cannot be converted to the proleptic gregorian calendar used in julia and are returned as such. (See CFTime.jl for more information about those date types.) If a calendar is defined but not among the ones specified in the CF convention, then the data in the file is not converted into a date structure.
A call getindex(ds, varname) is usually written as ds[varname].
If variable represents a cell boundary, the attributes calendar and units of the related variables are used, if they are not specified. For example:
In this case, the variable time_bnds uses the units and calendar of time because both variables are related thought the bounds attribute following the CF conventions.
Return the NetCDF variable varname in the dataset ds as a NCDataset.Variable. No scaling or other transformations are applied when the variable v is indexed.
v = cfvariable(ds::NCDataset,varname::SymbolOrString; <attrib> = <value>)
Return the variable varname in the dataset ds as a NCDataset.CFVariable. The keyword argument <attrib> are the attributes (fillvalue, missing_value, scale_factor, add_offset, units and calendar) relevant to the CF conventions. By specifing the value of these attributes, the one can override the value specified in the data set. If the attribute is set to nothing, then the attribute is not loaded and the corresponding transformation is ignored. This function is similar to ds[varname] with the additional flexibility that some variable attributes can be overridden.
Example:
NCDataset("foo.nc","c") do ds
+ double time_bnds(time,nv);
In this case, the variable time_bnds uses the units and calendar of time because both variables are related thought the bounds attribute following the CF conventions.
Return the NetCDF variable varname in the dataset ds as a NCDataset.Variable. No scaling or other transformations are applied when the variable v is indexed.
v = cfvariable(ds::NCDataset,varname::SymbolOrString; <attrib> = <value>)
Return the variable varname in the dataset ds as a NCDataset.CFVariable. The keyword argument <attrib> are the attributes (fillvalue, missing_value, scale_factor, add_offset, units and calendar) relevant to the CF conventions. By specifing the value of these attributes, the one can override the value specified in the data set. If the attribute is set to nothing, then the attribute is not loaded and the corresponding transformation is ignored. This function is similar to ds[varname] with the additional flexibility that some variable attributes can be overridden.
Generate the Julia code that would produce a NetCDF file with the same metadata as the NetCDF file fname. The code is placed in the file jlname or printed to the standard output. By default the new NetCDF file is called filename.nc. This can be changed with the optional parameter newfname.
Returns a list of variable(s) which has the attribute attname matching the value attval in the dataset ds. The list is empty if the none of the variables has the match. The output is a list of CFVariables.
Examples
Load all the data of the first variable with standard name "longitude" from the NetCDF file results.nc.
write(dest::AbstractDataset, src::AbstractDataset; include = keys(src), exclude = [])
Write the variables of src dataset into an empty dest dataset (which must be opened in mode "a" or "c"). The keywords include and exclude configure which variable of src should be included (by default all), or which should be excluded (by default none).
If the first argument is a file name, then the dataset is open in create mode ("c").
This function is useful when you want to save the dataset from a multi-file dataset.
To save a subset, one can use the view function view to virtually slice a dataset:
Generate the Julia code that would produce a NetCDF file with the same metadata as the NetCDF file fname. The code is placed in the file jlname or printed to the standard output. By default the new NetCDF file is called filename.nc. This can be changed with the optional parameter newfname.
Returns a list of variable(s) which has the attribute attname matching the value attval in the dataset ds. The list is empty if the none of the variables has the match. The output is a list of CFVariables.
Examples
Load all the data of the first variable with standard name "longitude" from the NetCDF file results.nc.
write(dest::AbstractDataset, src::AbstractDataset; include = keys(src), exclude = [])
Write the variables of src dataset into an empty dest dataset (which must be opened in mode "a" or "c"). The keywords include and exclude configure which variable of src should be included (by default all), or which should be excluded (by default none).
If the first argument is a file name, then the dataset is open in create mode ("c").
This function is useful when you want to save the dataset from a multi-file dataset.
To save a subset, one can use the view function view to virtually slice a dataset:
Example
NCDataset(fname_src) do ds
write(fname_slice,view(ds, lon = 2:3))
end
All variables in the source file fname_src with a dimension lon will be sliced along the indices 2:3 for the lon dimension. All attributes (and variables without a dimension lon) will be copied over unmodified.
Notice that DateTime-structures from CFTime are used to represent time for non-standard calendars. Otherwise, we attempt to use standard structures from the Julia standard library Dates.
A NetCDF group is a dataset (with variables, attributes, dimensions and sub-groups) and can be arbitrarily nested. A group is created with defGroup and accessed via the group property of a NCDataset.
# create the variable "temperature" inside the group "forecast"
ds = NCDataset("results.nc", "c");
@@ -88,9 +88,9 @@
# load the variable "temperature" inside the group "forecast"
forecast_temp = ds.group["forecast"]["temperature"][:,:,:]
-close(ds)
One can iterate over a dataset, attribute list, dimensions and NetCDF groups.
for (varname,var) in ds
# all variables
@show (varname,size(var))
end
@@ -103,4 +103,4 @@
for (groupname,group) in ds.groups
# all groups
@show (groupname,group)
-end
Settings
This document was generated with Documenter.jl version 1.5.0 on Tuesday 16 July 2024. Using Julia version 1.10.4.
+end
Settings
This document was generated with Documenter.jl version 1.6.0 on Monday 26 August 2024. Using Julia version 1.10.4.
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.
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.
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
+end
This example checks if the file /tmp/test.nc has a variable with the name temperature and a dimension with the name lon.
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)
# [...]
@@ -24,8 +24,8 @@
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)
One can iterate over a list of dimensions as follows:
for (dimname,dim) in ds.dim
# all dimensions
@show (dimname,dim)
-end
Settings
This document was generated with Documenter.jl version 1.5.0 on Tuesday 16 July 2024. Using Julia version 1.10.4.
+end
Settings
This document was generated with Documenter.jl version 1.6.0 on Monday 26 August 2024. Using Julia version 1.10.4.
diff --git a/dev/index.html b/dev/index.html
index 56e0433a..cc3382da 100644
--- a/dev/index.html
+++ b/dev/index.html
@@ -135,4 +135,4 @@
# if the attribute does not exists
units = get(v,"units","adimensional")
-close(ds)
The package aims to following semantic versioning. As in julia, what is considered as public API and covered by semantic versioning is what documented and not marked as experimental or internal.
Settings
This document was generated with Documenter.jl version 1.5.0 on Tuesday 16 July 2024. Using Julia version 1.10.4.