NetworkIOMixin
ΒΆ
Mixin class for network I/O methods.
Class inherits to pypsa.Network. All attributes and methods can be used within any Network instance.
Methods:
-
export_to_csv_folderβExport network and components to a folder of CSVs.
-
export_to_excelβExport network and components to an Excel file.
-
export_to_hdf5βExport network and components to an HDF store.
-
export_to_netcdfβExport network and components to a netCDF file.
-
import_from_csv_folderβImport network data from CSVs in a folder.
-
import_from_excelβImport network data from an Excel file.
-
import_from_hdf5βImport network data from HDF5 store at
path. -
import_from_netcdfβImport network data from netCDF file or xarray Dataset at
path. -
import_from_pandapower_netβImport PyPSA network from pandapower net.
-
import_from_pypower_ppcβImport network from PYPOWER PPC dictionary format version 2.
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")
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")
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")
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")
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)