Source code for powersimdata.network.helpers
import os
from itertools import chain, combinations
import pandas as pd
from powersimdata.network.constants.model import model2interconnect, model2region
[docs]def check_model(model):
"""Check that a grid model exists.
:param str model: grid model name
:raises TypeError: if ``model`` is not a str.
:raises ValueError: if grid model does not exist.
"""
if not isinstance(model, str):
raise TypeError("model must be a str")
if model not in model2region:
raise ValueError(f"Invalid model. Choose among {' | '.join(model2region)}")
[docs]def interconnect_to_name(interconnect, model="hifld"):
"""Return name of interconnect or collection of interconnects for a grid model.
:param str/iterable interconnect: interconnect name(s).
:param str model: the grid model.
:return: (*str*): name of grid model.
"""
return "_".join(sorted(check_and_format_interconnect(interconnect, model=model)))
[docs]def get_zone_info(model="hifld"):
"""Return information loacated in the zone CSV file of the model.
:param str model: the grid model.
:return: (*pandas.DataFrame*) -- information on the zones of the model.
:raises FileNotFoundError: if file enclosing the geographical information of the
grid model can't be found.
"""
check_model(model)
path = os.path.join(os.path.dirname(__file__), model, "data", "zone.csv")
if os.path.exists(path):
return pd.read_csv(path, index_col=0)
else:
raise FileNotFoundError(f"File {path} cannot be found")
[docs]def powerset(l, r):
return list(chain.from_iterable(combinations(l, i) for i in range(r, len(l) + 1)))