Skip to content

NetworkIOMixin


              flowchart TD
              pypsa.Network[NetworkIOMixin]
              pypsa.network.abstract._NetworkABC[_NetworkABC]

                              pypsa.network.abstract._NetworkABC --> pypsa.Network
                


              click pypsa.Network href "" "pypsa.Network"
              click pypsa.network.abstract._NetworkABC href "" "pypsa.network.abstract._NetworkABC"
            

Mixin class for network I/O methods.

Import Export

Class inherits to pypsa.Network. All attributes and methods can be used within any Network instance.

Methods:

pypsa.Network.export_to_csv_folder

export_to_csv_folder(path: Path | str, encoding: str | None = None, quotechar: str = '"', export_standard_types: bool = False) -> None

Export network and components to a folder of CSVs.

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

If path does not already exist, it is created.

path may also be a cloud object storage URI if cloudpathlib is installed.

Static attributes are exported in one CSV file per component, e.g. generators.csv.

Series attributes are exported in one CSV file per component per attribute, e.g. generators-p_set.csv.

Parameters:

  • path (Path | str) –

    Name of folder to which to export.

  • encoding (str, default: None ) –

    Encoding to use for UTF when reading (ex. 'utf-8'). See List of Python standard encodings

  • quotechar (str, default: '"' ) –

    String of length 1. Character used to quote fields.

  • 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).

Examples:

>>> n.export_to_csv_folder("my_network")
See Also

pypsa.Network.export_to_netcdf, pypsa.Network.export_to_hdf5, pypsa.Network.export_to_excel

pypsa.Network.export_to_excel

export_to_excel(path: str | Path, export_standard_types: bool = False, engine: str = 'openpyxl') -> None

Export network and components to an Excel file.

It is recommended to only use the Excel format if needed and for small networks. Excel files are not as efficient as other formats and can be slow to read/write.

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

If path does not already exist, it is created.

Static attributes are exported in one sheet per component, e.g. a sheet named generators.

Series attributes are exported in one sheet per component per attribute, e.g. a sheet named generators-p_set.

Parameters:

  • path (string or Path) –

    Path to the Excel file to which to export.

  • 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).

  • engine (string, default: "openpyxl" ) –

    The engine to use for writing the Excel file. See pandas.ExcelWriter .

Examples:

>>> n.export_to_excel("my_network.xlsx")
See Also

pypsa.Network.export_to_netcdf, pypsa.Network.export_to_hdf5, pypsa.Network.export_to_csv_folder

pypsa.Network.export_to_hdf5

export_to_hdf5(path: Path | str, export_standard_types: bool = False, **kwargs: Any) -> None

Export network and components to an HDF store.

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.

path may also be a cloud object storage URI if cloudpathlib is installed.

Parameters:

  • path (string) –

    Name of hdf5 file to which to export (if it exists, it is overwritten)

  • 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).

  • **kwargs (Any, default: {} ) –

    Extra arguments for pd.HDFStore to specify f.i. compression (default: complevel=4)

Examples:

>>> n.export_to_hdf5("my_network.h5")
See Also

pypsa.Network.export_to_netcdf, pypsa.Network.export_to_csv_folder, pypsa.Network.export_to_excel

pypsa.Network.export_to_netcdf

export_to_netcdf(path: Path | str | None = None, export_standard_types: bool = False, compression: dict | None = None, float32: bool = False) -> 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 (Path | string | None, default: None ) –

    Name of netCDF file to which to export (if it exists, it is overwritten); if None is passed, no file is exported and only the xarray.Dataset is returned.

  • 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, default: None ) –

    Compression level to use for all features which are being prepared. The compression is handled via xarray.Dataset.to_netcdf(...). For details see: xarray.Dataset.to_netcdf 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 ( Dataset ) –

Examples:

>>> n = pypsa.Network()
>>> n.export_to_netcdf("my_file.nc")
See Also

pypsa.Network.export_to_hdf5, pypsa.Network.export_to_csv_folder, pypsa.Network.export_to_excel

pypsa.Network.import_from_csv_folder

import_from_csv_folder(path: str | Path, encoding: str | None = None, quotechar: str = '"', skip_time: bool = False) -> None

Import network data from CSVs in a folder.

The CSVs must follow the standard form, see pypsa/examples.

Parameters:

  • path (string) –

    Name of folder

  • encoding (str, default: None ) –

    Encoding to use for UTF when reading (ex. 'utf-8'). See List of Python standard encodings

  • quotechar (str, default: '"' ) –

    String of length 1. Character used to denote the start and end of a quoted item. Quoted items can include "," and it will be ignored

  • skip_time (bool, default: False ) –

    Skip reading in time dependent attributes

Examples:

>>> n = pypsa.Network()
>>> n.import_from_csv_folder"./my_network")

pypsa.Network.import_from_excel

import_from_excel(path: str | Path, skip_time: bool = False, engine: str = 'calamine') -> None

Import network data from an Excel file.

The Excel file must follow the standard form with appropriate sheets.

Parameters:

  • path (string or Path) –

    Path to the Excel file

  • skip_time (bool, default: False ) –

    Skip reading in time dependent attributes

  • engine (string, default: "calamine" ) –

    The engine to use for reading the Excel file. See pandas.read_excel .

Examples:

>>> n = pypsa.Network()
>>> n.import_from_excel("my_network.xlsx")

pypsa.Network.import_from_hdf5

import_from_hdf5(path: str | Path, skip_time: bool = False) -> None

Import network data from HDF5 store at path.

Parameters:

  • path ((string, Path)) –

    Name of HDF5 store. The string could be a URL.

  • skip_time (bool, default: False ) –

    Skip reading in time dependent attributes

Examples:

>>> n = pypsa.Network()
>>> n.import_from_hdf5("my_network.h5")

pypsa.Network.import_from_netcdf

import_from_netcdf(path: str | Path | Dataset, skip_time: bool = False) -> None

Import network data from netCDF file or xarray Dataset at path.

path may also be a cloud object storage URI if cloudpathlib is installed.

Parameters:

  • path (string | Path | Dataset) –

    Path to netCDF dataset or instance of xarray Dataset. The string could be a URL.

  • skip_time (bool, default: False ) –

    Skip reading in time dependent attributes

Examples:

>>> n = pypsa.Network()
>>> n.import_from_netcdf("my_network.nc")

pypsa.Network.import_from_pandapower_net

import_from_pandapower_net(net: pandapowerNet, extra_line_data: bool = False, use_pandapower_index: bool = False) -> None

Import PyPSA network from pandapower net.

Importing from pandapower is still in beta; not all pandapower components are supported.

Unsupported features include: - three-winding transformers - switches - in_service status and - tap positions of transformers

Parameters:

  • net (pandapower network) –

    pandapower network to import from.

  • extra_line_data (boolean, default: False ) –

    if True, the line data for all parameters is imported instead of only the type

  • use_pandapower_index (boolean, default: False ) –

    if True, use integer numbers which is the pandapower index standard if False, use any net.name as index (e.g. 'Bus 1' (str) or 1 (int))

Examples:

>>> n.import_from_pandapower_net(net)
OR
>>> import pandapower as pp
>>> import pandapower.networks as pn
>>> net = pn.create_cigre_network_mv(with_der='all')
>>> n = pypsa.Network()
>>> n.import_from_pandapower_net(net, extra_line_data=True)

pypsa.Network.import_from_pypower_ppc

import_from_pypower_ppc(ppc: dict, overwrite_zero_s_nom: float | None = None) -> None

Import network from PYPOWER PPC dictionary format version 2.

Converts all baseMVA to base power of 1 MVA.

For the meaning of the pypower indices, see also pypower/idx_*.

Parameters:

  • ppc (PYPOWER PPC dict) –

    PYPOWER PPC dictionary to import from.

  • overwrite_zero_s_nom (Float or None, default: None ) –

    If a float, all branches with s_nom of 0 will be set to this value.

Examples:

>>> from pypower.api import case30
>>> ppc = case30()
>>> n.import_from_pypower_ppc(ppc)