ncdata.dataset_like module#

An adaptor layer for ncdata to emulate netCDF4.

Primarily, allows an ncdata.NcData to masquerade as a netCDF4.Dataset object.

Note

This is a low-level interface, exposed publicly for extended experimental uses. If you only want to convert Iris data to + from NcData, please use the functions in ncdata.iris instead.


These classes contain NcData, NcDimension, and NcVariable objects, but emulate the access APIs of netCDF4.Dataset netCDF4.Dimension and netCDF4.Variable.

This is provided primarily to support a re-use of the iris.fileformats.netcdf file format load + save, to convert cubes to + from ncdata objects (and hence, especially, to convert Iris Cubes to + from an Xarray Dataset ).

Notes

Currently only supports what is required for Iris load/save capability. In principle, it should be possible to use these objects with other packages expecting a netCDF4.Dataset object. However the API simulation is far from complete, so this module may need to be extended, in future, to support other such uses.

class ncdata.dataset_like.Nc4DatasetLike#

Bases: _Nc4DatalikeWithNcattrs

An object which emulates a netCDF4.Dataset.

It can be both read and written (modified) via its emulated netCDF4.Dataset-like API.

The core, contained content object, self._ncdata, is a ncdata.NcData. This completely defines the parent object state. If not provided on init, a new, empty dataset is created.

file_format = 'NETCDF4'#
__init__(ncdata=None)#

Create an Nc4DatasetLike, wrapping an NcData.

Parameters:

ncdata (NcData)

property groups#
createDimension(dimname, size)#
Parameters:
createVariable(varname, datatype, dimensions=(), fill_value=None, **kwargs)#
Parameters:
sync()#
close()#
static filepath()#
Return type:

str

getncattr(attr)#
Parameters:

attr (str)

ncattrs()#
Return type:

List[str]

setncattr(attr, value)#
Parameters:

attr (str)

class ncdata.dataset_like.Nc4VariableLike#

Bases: _Nc4DatalikeWithNcattrs

An object which contains a ncdata.NcVariable and emulates a netCDF4.Variable.

The core, contained content object, self._ncdata, is a NcVariable. This completely defines the parent object state.

The property ._data_array is detected by Iris to do direct data transfer (copy-free and lazy-preserving).

At present, this object emulates only the default read/write behaviour of a netCDF4.Variable, i.e. :

  • the underlying NcVariable contains a ‘raw’ data array, which may be real (i.e. numpy) or lazy (i.e. dask).

  • The ._data_array property read/write interface then applies/removes any scaling and masking as it is to be “seen” from the outside.

That suits how Iris reads netCDF4 data, but it won’t work if the user wants to control the masking/saving behaviour, as you can do in netCDF4. Thus, at present, we do not provide any of the set_auto_mask/scale/maskandscale() methods.

__init__(ncvar, datatype)#
Parameters:
group()#
property dimensions: List[str]#
property dtype#
property dims#
property ndim#
property shape#
property size#
chunking()#

Return chunk sizes.

Actual datasets return a list of sizes by dimension, or ‘contiguous’.

For now, simply returns None. Could be replaced when required.

getncattr(attr)#
Parameters:

attr (str)

ncattrs()#
Return type:

List[str]

setncattr(attr, value)#
Parameters:

attr (str)

class ncdata.dataset_like.Nc4DimensionLike#

Bases: object

An object which emulates a netCDF4.Dimension object.

The core, contained content object, self._ncdata, is a ncdata.NcDimension. This completely defines the parent object state.

__init__(ncdim)#
Parameters:

ncdim (NcDimension)

property name#
property size#
isunlimited()#
group()#