pypsa.Network.export_to_netcdf

pypsa.Network.export_to_netcdf#

Network.export_to_netcdf(path: str | None = None, export_standard_types: bool = False, compression: dict | None = None, float32: bool = False) xr.Dataset#

Export network and components to a netCDF file.

Both static and series attributes of components are exported, but only if they have non-default values.

If path does not already exist, it is created.

If no path is passed, no file is exported, but the xarray.Dataset is still returned.

Be aware that this cannot export boolean attributes on the Network class, e.g. n.my_bool = False is not supported by netCDF.

Parameters:
  • path (string|None) – Name of netCDF file to which to export (if it exists, it is overwritten); if None is passed, no file is exported.

  • export_standard_types (boolean, default False) – If True, then standard types are exported too (upon reimporting you should then set “ignore_standard_types” when initialising the network).

  • compression (dict|None) – Compression level to use for all features which are being prepared. The compression is handled via xarray.Dataset.to_netcdf(…). For details see: https://docs.xarray.dev/en/stable/generated/xarray.Dataset.to_netcdf.html An example compression directive is {'zlib': True, 'complevel': 4}. The default is None which disables compression.

  • float32 (boolean, default False) – If True, typecasts values to float32.

Returns:

ds

Return type:

xarray.Dataset

Examples

>>> n.export_to_netcdf("my_file.nc")