scmdata.netcdf
NetCDF4 file operations
Reading and writing ScmRun to disk as binary
run_to_nc
- run_to_nc(run, fname, dimensions=('region',), extras=(), **kwargs)[source]
Write timeseries to disk as a netCDF4 file
Each unique variable will be written as a variable within the netCDF file. Choosing the dimensions and extras such that there are as few empty (or nan) values as possible will lead to the best compression on disk.
- Parameters:
fname (str | pathlib.Path) – Path to write the file into
dimensions (iterable of str) – Dimensions to include in the netCDF file. The time dimension is always included (if not provided it will be the last dimension). An additional dimension (specifically a co-ordinate in xarray terms), “_id”, will be included if
extrasis provided and any of the metadata inextrasis not uniquely defined bydimensions. “_id” maps the timeseries in each variable to their relevant metadata.extras (iterable of str) – Metadata columns to write as variables in the netCDF file (specifically as “non-dimension co-ordinates” in xarray terms, see xarray terminology for more details). Where possible, these non-dimension co-ordinates will use dimension co-ordinates as their own co-ordinates. However, if the metadata in
extrasis not defined by a single dimension indimensions, then theextrasco-ordinates will have dimensions of “_id”. This “_id” co-ordinate maps the values in theextrasco-ordinates to each timeseries in the serialised dataset. Where “_id” is required, an extra “_id” dimension will also be added todimensions.kwargs (Any) – Passed through to
xarray.Dataset.to_netcdf()
- Return type:
None
See also
scmdata.run.ScmRun.to_nc()
nc_to_run
inject_nc_methods
- inject_nc_methods(cls)[source]
Add the to/from nc methods to a class
- Parameters:
cls (
type[scmdata.run.BaseScmRun]) – Class to add methods to- Return type: