ncdata.netcdf4 module#
Interface routines for converting data between ncdata and netCDF4.
Converts ncdata.NcData
to and from netCDF4.Dataset
objects.
- ncdata.netcdf4.from_nc4(nc4_dataset_or_file)#
Load NcData from a
netCDF4.Dataset
or netCDF file.- Parameters:
nc4_dataset_or_file (Dataset | Group | Path | str) – source of load data. Can be either a
netCDF4.Dataset
, anetCDF4.Group
, apathlib.Path
or a string.- Returns:
ncdata
- Return type:
- ncdata.netcdf4.to_nc4(ncdata, nc4_dataset_or_file, var_kwargs=None)#
Save NcData to a netCDF file.
- Parameters:
ncdata (NcData) – input data
nc4_dataset_or_file (
netCDF4.Dataset
orpathlib.Path
or str) – output filepath ornetCDF4.Dataset
to write intovar_kwargs (dict or None) –
additional keys for variable creation. If present, each entry
var_kwargs[<var_name>]
is itself a dictionary, containing entries of the form<kwarg_name>: <kwarg_value>
, which specify additional keyword controls passed tonetCDF4.Dataset.createVariable()
for this variable. This allows control of e.g. compression or chunking.Keyword controls for variables in a sub-group can be given in a
var_kwargs['/<group-name>']
entry, which is itself avar_kwargs
- like dictionary.Note: this must not include keywords controlled by the
to_nc4
operation itself. That is, any of : [“data”, “dimensions”, “datatype”, “fill_value”].
- Return type:
None
Notes
If a filepath is provided, a file is written and closed afterwards. If a dataset is provided, it must be writeable and remains open afterward.