def build(self): """Build network""" path = os.path.join(self.data_loc, "networks", "elec_s") if self.reduction is None: network = pypsa.Network(path + ".nc") elif os.path.exists(path + f"_{self.reduction}_ec.nc"): network = pypsa.Network(path + f"_{self.reduction}_ec.nc") else: raise ValueError( "Invalid Resolution. Choose among: None | 1024 | 512 | 256 | 128 | 37" ) id2zone = {i: l for i, l in enumerate(network.buses.index)} zone2id = {l: i for i, l in id2zone.items()} if self.interconnect == ["Europe"]: self.network = network self.id2zone = id2zone self.zone2id = zone2id else: filter = list( # noqa: F841 interconnect2abv[interconnect_to_name(self.interconnect, model=self.grid_model)]) self.network = network[network.buses.query( "country == @filter").index] self.zone2id = {l: zone2id[l] for l in self.network.buses.index} self.id2zone = {i: l for l, i in self.zone2id.items()} self.model_immutables = self._generate_model_immutables()
def get_interconnect_mapping(zone, model): """Return interconnect mapping. :param pandas.DataFrame zone: information on zones of a grid model. :param str model: the grid model. :return: (*dict*) -- mappings of interconnect to other areas. """ mapping = dict() name = interconnect_to_name(zone["interconnect"], model=model) mapping["interconnect"] = name2component[name] | {name} mapping["name2interconnect"] = { i: name2interconnect[i] for i in mapping["interconnect"] } mapping["name2component"] = {i: name2component[i] for i in mapping["interconnect"]} mapping["interconnect2timezone"] = { i: interconnect2timezone[i] for i in mapping["interconnect"] } mapping["interconnect2abv"] = { i: interconnect2abv[i] for i in mapping["interconnect"] } if model == "europe_tub": mapping["interconnect2loadzone"] = {i: set() for i in mapping["interconnect"]} mapping["interconnect2id"] = {i: set() for i in mapping["interconnect"]} return mapping
def get_interconnect_mapping(zone, model): """Return interconnect mapping. :param pandas.DataFrame zone: information on zones of a grid model. :param str model: the grid model. :return: (*dict*) -- mappings of interconnect to other areas. """ def _substitute(entry): return { i: ast.literal_eval(repr(entry).replace("ERCOT", sub))[i] for i in mapping["interconnect"] } mapping = dict() sub = "Texas" if model == "usa_tamu" else "ERCOT" name = interconnect_to_name(zone["interconnect"].unique(), model=model) mapping["interconnect"] = ast.literal_eval( repr(name2component).replace("ERCOT", sub) )[name] | {name} mapping["name2interconnect"] = _substitute(name2interconnect) mapping["name2component"] = _substitute(name2component) mapping["interconnect2timezone"] = _substitute(interconnect2timezone) mapping["interconnect2abv"] = _substitute(interconnect2abv) mapping["interconnect2loadzone"] = { i: set(l) for i, l in zone.set_index("zone_name").groupby("interconnect").groups.items() } mapping["interconnect2id"] = { i: set(id) for i, id in zone.groupby("interconnect").groups.items() } return mapping
"MK", "NL", "PL", "PT", "RO", "RS", "SI", "SK", }, "Nordic": {"FI", "NO", "SE"}, "GreatBritain": {"GB"}, "Ireland": {"IE"}, "Baltic": {"EE", "LT", "LV"}, } for c in powerset(model2interconnect["europe_tub"], 2): interconnect2abv[interconnect_to_name(c, model="europe_tub")] = set( chain(*[interconnect2abv[i] for i in c]) ) name2interconnect = { interconnect_to_name(c, model="europe_tub"): set(c) for c in powerset(model2interconnect["europe_tub"], 1) } name2component = name2interconnect.copy() name2component.update({"Europe": set(name2interconnect) - {"Europe"}}) interconnect2timezone = { interconnect_to_name(c, model="europe_tub"): "ETC/GMT-1" for c in powerset(model2interconnect["europe_tub"], 1) }
"MN", "IA", "MO", "AR", "LA", "OK", "KS", "NE", "SD", "ND", }, "ERCOT": {"TX"}, "Western": {"WA", "OR", "CA", "NV", "AZ", "UT", "NM", "CO", "WY", "ID", "MT"}, } for c in powerset(model2interconnect["hifld"], 2): interconnect2abv[interconnect_to_name(c, model="hifld")] = set( chain(*[interconnect2abv[i] for i in c]) ) name2interconnect = { interconnect_to_name(c, model="hifld"): set(c) for c in powerset(model2interconnect["hifld"], 1) } name2component = name2interconnect.copy() name2component.update({"USA": set(name2interconnect) - {"USA"}}) interconnect2timezone = { interconnect_to_name("USA"): "ETC/GMT+6", interconnect_to_name("Eastern"): "ETC/GMT+5", interconnect_to_name("ERCOT"): "ETC/GMT+6",
def __init__(self, grid_model, interconnect, table): """Constructor.""" self.grid_model = grid_model self.interconnect = interconnect_to_name(interconnect, grid_model) self.existing = table[table.interconnect == self.interconnect]