From 3411bae14a6e68d39e75a5b200b658f279304059 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 28 Sep 2023 10:24:11 +0200 Subject: [PATCH 01/19] Add link to uploaded input data --- README.rst | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 3a5f9bb4..e16b97a3 100644 --- a/README.rst +++ b/README.rst @@ -29,13 +29,19 @@ instead part of 'eGo' https://github.com/openego/eGo eTraGo is documented on `readthedocs `_. -.. warning:: - From now on eTraGo depends on a sector coupled data-model. This is not published on - the oedb yet, the data has to be created using - `eGon-data `_. - Not all functions and features are compatible to the sector coupled model yet. - - When you want to use eTraGo for optimizations, please use the latest release 0.8.0. + +Input data +========== +The grid model data for eTraGo was created with the open source tool +`eGon-data `_. The resulting data will +be pubished on the `OpenEnergyPlatform `_. +As long as the data is not published there, a local database is needed. +We published a backup of the required tables and instruction on how to use it +on zenodo: + +.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.8376714.svg + :target: https://doi.org/10.5281/zenodo.8376714 + Installation ============ From 6f2cb1eb691d211592a92b52e7defede5ad2c49c Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 28 Sep 2023 10:50:06 +0200 Subject: [PATCH 02/19] Refer to build-in etrago module instead of ego.io --- doc/installation.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/installation.rst b/doc/installation.rst index a62a615a..f10ef989 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -63,9 +63,8 @@ environments. Setup database connection ========================= -The package `ego.io `_ will be installed -automatically when eTraGo is installed. The ``egoio`` -gives you python SQL-Alchemy representations of +The eTraGo module `db `_ +gives you a python SQL-Alchemy representations of the `OpenEnergy-Database(oedb) `_ and access to it by using the `oedialect `_, which is a SQL-Alchemy binding @@ -82,7 +81,7 @@ the oedialect enter the following connection parameter. For and you have to take your credentials which you obtained by registering at `openenergy-platform.org/login `_. -Your API access / login data will be saved in the folder ``.egoio`` in the file +Your API access / login data will be saved in the folder ``.etrago_database`` in the file ``config.ini``. Consequently, in the config.ini you can also change your connection parameters or add new ones. In the following you can see how the config.ini looks like when you use the From ba95ad888b5824589b6967e7e1e42b764ea6f803 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 28 Sep 2023 15:20:03 +0200 Subject: [PATCH 03/19] Remove egio.io from documentation --- doc/about.rst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/doc/about.rst b/doc/about.rst index a7b91cf1..ad11ac9a 100644 --- a/doc/about.rst +++ b/doc/about.rst @@ -78,14 +78,6 @@ eGon-data is a further development of the `Data processing `_, `ding0 `_ and `eDisGo `_ and delivers for example data on grid topologies, demands/demand curves and generation capacities in a high spatial resolution. The outputs of egon-data are published under open source and open data licenses. -ego.io -====== - -The ego.io serves as a SQLAlchemy Interface to the OpenEnergy database (oedb). The -oedb table ORM objects are defined here and small helpers for io tasks are contained. -`Learn more here `_. - - Dingo ===== From 6e55eca4d29d54dc1d2c2b5e8d854e8fadaf9379 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 28 Sep 2023 15:20:33 +0200 Subject: [PATCH 04/19] Fix typo --- doc/theoretical_background.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/theoretical_background.rst b/doc/theoretical_background.rst index 6df61b82..62c8e2d9 100644 --- a/doc/theoretical_background.rst +++ b/doc/theoretical_background.rst @@ -39,7 +39,7 @@ With the argument ‘pf_post_lopf’, after the LOPF a non-linear power flow sim Complexity Reduction --------------------- -The data model is characterised by a high spatial (abou 8,000 electrical and 600 gas nodes) and temporal resolution (8,760 timesteps). To reduce the complexity of the resulting optimisation problem, several methods can be applied. +The data model is characterised by a high spatial (about 8,000 electrical and 600 gas nodes) and temporal resolution (8,760 timesteps). To reduce the complexity of the resulting optimisation problem, several methods can be applied. Reduction in spatial dimension: From aad9b0f4f58cc4305c2be603f8fca8e342032d87 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Mon, 2 Oct 2023 15:05:02 +0200 Subject: [PATCH 05/19] Store disaggregated_network before all clustering steps --- etrago/cluster/electrical.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/etrago/cluster/electrical.py b/etrago/cluster/electrical.py index 44fc5526..1778e78b 100755 --- a/etrago/cluster/electrical.py +++ b/etrago/cluster/electrical.py @@ -1053,6 +1053,12 @@ def run_spatial_clustering(self): None """ if self.args["network_clustering"]["active"]: + + if self.args["disaggregation"] is not None: + self.disaggregated_network = self.network.copy() + else: + self.disaggregated_network = self.network.copy(with_time=False) + self.network.generators.control = "PV" elec_network, weight, n_clusters, busmap_foreign = preprocessing(self) @@ -1090,11 +1096,6 @@ def run_spatial_clustering(self): ) self.update_busmap(busmap) - if self.args["disaggregation"] is not None: - self.disaggregated_network = self.network.copy() - else: - self.disaggregated_network = self.network.copy(with_time=False) - self.network = self.clustering.network self.buses_by_country() From d2ee4f4fedaa8c751789a8ce32a007d6b343a0e2 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Mon, 2 Oct 2023 16:50:47 +0200 Subject: [PATCH 06/19] Use etrago.busmap instead of clustering.busmap --- etrago/cluster/disaggregation.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index 13c811e1..f760dda4 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -15,7 +15,7 @@ class Disaggregation: def __init__( - self, original_network, clustered_network, clustering, skip=() + self, original_network, clustered_network, busmap, skip=() ): """ :param original_network: Initial (unclustered) network structure @@ -25,11 +25,11 @@ def __init__( """ self.original_network = original_network self.clustered_network = clustered_network - self.clustering = clustering + self.busmap = busmap self.buses = pd.merge( original_network.buses, - self.clustering.busmap.to_frame(name="cluster"), + busmap.to_frame(name="cluster"), left_index=True, right_index=True, ) @@ -808,14 +808,14 @@ def run_disaggregation(self): disaggregation = MiniSolverDisaggregation( self.disaggregated_network, self.network, - self.clustering, + self.busmap, skip=skip, ) elif disagg == "uniform": disaggregation = UniformDisaggregation( original_network=self.disaggregated_network, clustered_network=self.network, - clustering=self.clustering, + busmap=pd.Series(self.busmap["busmap"]), skip=skip, ) From 79d6b4b2de125590a5132c91b1ce3e6a278d7804 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Mon, 2 Oct 2023 16:51:21 +0200 Subject: [PATCH 07/19] Use etrago.args to find out if disagregation is needed --- etrago/cluster/disaggregation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index f760dda4..749c9a78 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -799,7 +799,7 @@ def update_constraints(network, externals): def run_disaggregation(self): log.debug("Running disaggregation.") - if self.clustering: + if self.args["network_clustering"]["active"]: disagg = self.args.get("disaggregation") skip = () if self.args["pf_post_lopf"]["active"] else ("q",) t = time.time() From bd84371c2d596b9533be1a03d1d0d66a83e42d5c Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Mon, 2 Oct 2023 17:07:12 +0200 Subject: [PATCH 08/19] Exclude DC links from disaggregation --- etrago/cluster/disaggregation.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index 749c9a78..3cc5efe4 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -649,6 +649,13 @@ def solve_partial_network( if pnb.empty: continue + # Exclude DC links from the disaggregation because it does not + # make sense to disaggregated them uniformly. + # A new power flow calculation in the high resolution would + # be required. + if pnb.carrier.iloc[0] == "DC": + continue + if not ( pnb.loc[:, extendable_flag].all() or not pnb.loc[:, extendable_flag].any() From be13ecde38489c54fe41803d44e117df7dab9599 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Mon, 2 Oct 2023 17:24:34 +0200 Subject: [PATCH 09/19] Exclude not disaggregated DC links from checks --- etrago/cluster/disaggregation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index 3cc5efe4..351e7863 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -324,7 +324,9 @@ def solve(self, scenario, solver): ): log.info(f"Attribute sums, {bt}, clustered - disaggregated:") cnb = getattr(self.clustered_network, bt) + cnb = cnb[cnb.carrier!="DC"] onb = getattr(self.original_network, bt) + onb = onb[onb.carrier!="DC"] log.info( "{:>{}}: {}".format( "p_nom_opt", From 25c17ba6da5269ea61090d125a0d8824e0319ba9 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Mon, 2 Oct 2023 17:25:05 +0200 Subject: [PATCH 10/19] Disaggregate reactive power of generators and storages if pf was performed --- etrago/cluster/disaggregation.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index 351e7863..08b2a5e3 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -761,12 +761,23 @@ def solve_partial_network( def transfer_results(self, *args, **kwargs): kwargs["bustypes"] = ["generators", "links", "storage_units", "stores"] - kwargs["series"] = { - "generators": {"p"}, - "links": {"p0", "p1"}, - "storage_units": {"p", "state_of_charge"}, - "stores": {"e", "p"}, - } + + # Only disaggregate reactive power (q) if a pf_post_lopf was performed + # and there is data in resulting q time series + if self.original_network.generators_t.q.empty: + kwargs["series"] = { + "generators": {"p"}, + "links": {"p0", "p1"}, + "storage_units": {"p", "state_of_charge"}, + "stores": {"e", "p"}, + } + else: + kwargs["series"] = { + "generators": {"p", "q"}, + "links": {"p0", "p1"}, + "storage_units": {"p", "q", "state_of_charge"}, + "stores": {"e", "p"}, + } return super().transfer_results(*args, **kwargs) From afa531502e599ae79df8c81c66bd5168f8b2d43e Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Mon, 2 Oct 2023 17:26:01 +0200 Subject: [PATCH 11/19] Un-comment disaggregation --- etrago/appl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etrago/appl.py b/etrago/appl.py index 083d87b8..a60a7e09 100644 --- a/etrago/appl.py +++ b/etrago/appl.py @@ -677,7 +677,7 @@ def run_etrago(args, json_path): # spatial disaggregation # needs to be adjusted for new sectors - # etrago.disaggregation() + etrago.disaggregation() # calculate central etrago results etrago.calc_results() From f39140db6f347fa02afbc15aea2ccdab34946f8a Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Mon, 2 Oct 2023 17:28:43 +0200 Subject: [PATCH 12/19] Apply black --- etrago/cluster/disaggregation.py | 16 +++++++++++----- etrago/cluster/electrical.py | 5 ++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index 08b2a5e3..b878c18b 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -14,9 +14,7 @@ class Disaggregation: - def __init__( - self, original_network, clustered_network, busmap, skip=() - ): + def __init__(self, original_network, clustered_network, busmap, skip=()): """ :param original_network: Initial (unclustered) network structure :param clustered_network: Clustered network used for the optimization @@ -280,6 +278,7 @@ def solve(self, scenario, solver): } profile = cProfile.Profile() profile = noops + for i, cluster in enumerate(sorted(clusters)): log.info(f"Decompose {cluster=} ({i + 1}/{n})") profile.enable() @@ -287,6 +286,7 @@ def solve(self, scenario, solver): partial_network, externals = self.construct_partial_network( cluster, scenario ) + profile.disable() self.stats["clusters"].loc[cluster, "decompose"] = time.time() - t log.info( @@ -324,9 +324,9 @@ def solve(self, scenario, solver): ): log.info(f"Attribute sums, {bt}, clustered - disaggregated:") cnb = getattr(self.clustered_network, bt) - cnb = cnb[cnb.carrier!="DC"] + cnb = cnb[cnb.carrier != "DC"] onb = getattr(self.original_network, bt) - onb = onb[onb.carrier!="DC"] + onb = onb[onb.carrier != "DC"] log.info( "{:>{}}: {}".format( "p_nom_opt", @@ -624,6 +624,7 @@ def solve_partial_network( f" & (bus1 in {index})" ) pnb = pnb.query(query) + assert not pnb.empty or ( # In some cases, a district heating grid is connected to a # substation only via a resistive_heater but not e.g. by a @@ -684,6 +685,7 @@ def solve_partial_network( " it has on the buses of it's partial network." ) + print(clb.iloc[0].carrier) if clb.iloc[0].at[extendable_flag]: # That means, `p_nom` got computed via optimization and we # have to distribute it into the subnetwork first. @@ -753,6 +755,10 @@ def solve_partial_network( ) delta = abs((new_columns.sum(axis=1) - clt).sum()) epsilon = 1e-5 + if delta > epsilon: + import pdb + + pdb.set_trace() assert delta < epsilon, ( "Sum of disaggregated time series does not match" f" aggregated timeseries: {delta=} > {epsilon=}." diff --git a/etrago/cluster/electrical.py b/etrago/cluster/electrical.py index 1778e78b..6ddc8dec 100755 --- a/etrago/cluster/electrical.py +++ b/etrago/cluster/electrical.py @@ -1053,7 +1053,6 @@ def run_spatial_clustering(self): None """ if self.args["network_clustering"]["active"]: - if self.args["disaggregation"] is not None: self.disaggregated_network = self.network.copy() else: @@ -1091,12 +1090,12 @@ def run_spatial_clustering(self): busmap = pd.Series(dtype=str) medoid_idx = pd.Series(dtype=str) - self.clustering, busmap = postprocessing( + clustering, busmap = postprocessing( self, busmap, busmap_foreign, medoid_idx ) self.update_busmap(busmap) - self.network = self.clustering.network + self.network = clustering.network self.buses_by_country() From 9b63c4abd731f02e7fbfab72ffec00641728327e Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 18 Oct 2023 17:36:58 +0200 Subject: [PATCH 13/19] Only disaggregte time series if there is data after filtering This es especially needed when all generators are PQ-controlled (e.g. load shedding) and there is no reactive power time series that needs to be distributed --- etrago/cluster/disaggregation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index b878c18b..2e04c46c 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -729,7 +729,12 @@ def solve_partial_network( for s in bustypes[bustype]["series"]: if s in self.skip: continue + filtered = pnb.loc[filters.get(s, slice(None))] + + if filtered.empty: + continue + clt = cl_t[s].loc[:, clb.index[0]] weight = reduce( multiply, From 5f9bf72d9483a8a00e6ddc9c22ff8ab400408394 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 18 Oct 2023 17:38:39 +0200 Subject: [PATCH 14/19] Set load_shedding genartors control to PQ This happens within the pf_post_lopf anyhow. But before, the change was only done for the aggregated and not the disaggregated network which resulted into problems when disaggregating --- etrago/tools/utilities.py | 1 + 1 file changed, 1 insertion(+) diff --git a/etrago/tools/utilities.py b/etrago/tools/utilities.py index d44171bc..04d9c759 100755 --- a/etrago/tools/utilities.py +++ b/etrago/tools/utilities.py @@ -635,6 +635,7 @@ def load_shedding(self, temporal_disaggregation=False, **kwargs): p_nom=p_nom, carrier="load shedding", bus=network.buses.index, + control="PQ", ), index=index, ), From 48704b106a2c22cde460abe8ba9d8e669967f3a6 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 18 Oct 2023 18:08:33 +0200 Subject: [PATCH 15/19] Remove pdb statement --- etrago/cluster/disaggregation.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index 2e04c46c..21c49942 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -760,10 +760,7 @@ def solve_partial_network( ) delta = abs((new_columns.sum(axis=1) - clt).sum()) epsilon = 1e-5 - if delta > epsilon: - import pdb - pdb.set_trace() assert delta < epsilon, ( "Sum of disaggregated time series does not match" f" aggregated timeseries: {delta=} > {epsilon=}." From 1c40400520184399f07523ed5350d278de88b240 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 26 Oct 2023 11:47:11 +0200 Subject: [PATCH 16/19] Set control staregies for generators in one central function The control parameters are overwitten within pypsa's network clustering, because slack generators are selected. In order to not keep this change, the function set_contro_strategies needs to be called again after every spatial clustering. --- etrago/cluster/electrical.py | 24 +++++++++--------------- etrago/cluster/gas.py | 8 +++++++- etrago/tools/execute.py | 14 -------------- etrago/tools/network.py | 3 +++ etrago/tools/utilities.py | 36 +++++++++++++++++++++++++++++++++++- 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/etrago/cluster/electrical.py b/etrago/cluster/electrical.py index 6ddc8dec..207de3e1 100755 --- a/etrago/cluster/electrical.py +++ b/etrago/cluster/electrical.py @@ -47,6 +47,10 @@ strategies_one_ports, ) + from etrago.tools.utilities import ( + set_control_strategies, + ) + logger = logging.getLogger(__name__) __copyright__ = ( @@ -351,7 +355,6 @@ def cluster_on_extra_high_voltage(etrago, busmap, with_time=True): io.import_series_from_dataframe(network_c, df, "Link", attr) # dealing with generators - network.generators.control = "PV" network.generators["weight"] = 1 new_df, new_pnl = aggregategenerators( @@ -469,8 +472,6 @@ def ehv_clustering(self): if self.args["network_clustering_ehv"]: logger.info("Start ehv clustering") - self.network.generators.control = "PV" - delete_ehv_buses_no_lines(self.network) busmap = busmap_from_psql(self) @@ -677,13 +678,6 @@ def preprocessing(etrago): network = etrago.network settings = etrago.args["network_clustering"] - # prepare k-mean - # k-means clustering (first try) - network.generators.control = "PV" - network.storage_units.control[ - network.storage_units.carrier == "extendable_storage" - ] = "PV" - # problem our lines have no v_nom. this is implicitly defined by the # connected buses: network.lines["v_nom"] = network.lines.bus0.map(network.buses.v_nom) @@ -1058,8 +1052,6 @@ def run_spatial_clustering(self): else: self.disaggregated_network = self.network.copy(with_time=False) - self.network.generators.control = "PV" - elec_network, weight, n_clusters, busmap_foreign = preprocessing(self) if self.args["network_clustering"]["method"] == "kmeans": @@ -1101,9 +1093,11 @@ def run_spatial_clustering(self): self.geolocation_buses() - self.network.generators.control[ - self.network.generators.control == "" - ] = "PV" + # The control parameter is overwritten in pypsa's clustering. + # The function network.determine_network_topology is called, + # which sets slack bus(es). + set_control_strategies(self.network) + logger.info( "Network clustered to {} buses with ".format( self.args["network_clustering"]["n_clusters_AC"] diff --git a/etrago/cluster/gas.py b/etrago/cluster/gas.py index b25f64e6..eb5df003 100644 --- a/etrago/cluster/gas.py +++ b/etrago/cluster/gas.py @@ -43,6 +43,8 @@ sum_with_inf, ) + from etrago.tools.utilities import set_control_strategies + logger = logging.getLogger(__name__) __copyright__ = ( @@ -948,7 +950,6 @@ def run_spatial_clustering_gas(self): settings = self.args["network_clustering"] if settings["active"]: - self.network.generators.control = "PV" method = settings["method_gas"] logger.info(f"Start {method} clustering GAS") @@ -1000,6 +1001,11 @@ def run_spatial_clustering_gas(self): self.update_busmap(busmap) + # The control parameter is overwritten in pypsa's clustering. + # The function network.determine_network_topology is called, + # which sets slack bus(es). + set_control_strategies(self.network) + logger.info( """GAS Network clustered to {} DE-buses and {} foreign buses with {} algorithm.""".format( diff --git a/etrago/tools/execute.py b/etrago/tools/execute.py index ea643bf2..f7d7f5a6 100755 --- a/etrago/tools/execute.py +++ b/etrago/tools/execute.py @@ -803,20 +803,6 @@ def drop_foreign_components(network): network ) - # Assign generators control strategy - ac_bus = network.buses[network.buses.carrier == "AC"] - network.generators.control[ - network.generators.bus.isin(ac_bus.index) - ] = "PV" - network.generators.control[ - network.generators.carrier == "load shedding" - ] = "PQ" - - # Assign storage units control strategy - network.storage_units.control[ - network.storage_units.bus.isin(ac_bus.index) - ] = "PV" - # Find out the name of the main subnetwork main_subnet = str(network.buses.sub_network.value_counts().argmax()) diff --git a/etrago/tools/network.py b/etrago/tools/network.py index 88a1696e..1dfbb231 100644 --- a/etrago/tools/network.py +++ b/etrago/tools/network.py @@ -92,6 +92,7 @@ load_shedding, manual_fixes_datamodel, set_branch_capacity, + set_control_strategies, set_line_costs, set_q_foreign_loads, set_q_national_loads, @@ -405,5 +406,7 @@ def adjust_network(self): self.delete_dispensable_ac_buses() + set_control_strategies(self.network) + def _ts_weighted(self, timeseries): return timeseries.mul(self.network.snapshot_weightings, axis=0) diff --git a/etrago/tools/utilities.py b/etrago/tools/utilities.py index 04d9c759..a7cc09cd 100755 --- a/etrago/tools/utilities.py +++ b/etrago/tools/utilities.py @@ -531,7 +531,6 @@ def set_q_foreign_loads(self, cos_phi): ].values * math.tan( math.acos(cos_phi) ) - network.generators.control[network.generators.control == "PQ"] = "PV" # To avoid a problem when the index of the load is the weather year, # the column names were temporarily set to `int` and changed back to @@ -643,6 +642,41 @@ def load_shedding(self, temporal_disaggregation=False, **kwargs): ) +def set_control_strategies(network): + """Sets control strategies for AC generators and storage units + + Parameters + ---------- + network : :class:`pypsa.Network + Overall container of PyPSA + + Returns + ------- + None. + + """ + # Assign generators control strategy + network.generators.loc[:, "control"] = "PV" + + network.generators.loc[ + network.generators.carrier.isin( + [ + "load shedding", + "CH4", + "CH4_biogas", + "CH4_NG", + "central_biomass_CHP_heat", + "geo_thermal", + "solar_thermal_collector", + ] + ), + "control", + ] = "PQ" + + # Assign storage units control strategy + network.storage_units.loc[:, "control"] = "PV" + + def data_manipulation_sh(network): """Adds missing components to run calculations with SH scenarios. From 7d7d2e6097f0eaf0e03d69de8962afd8a000e0d8 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 26 Oct 2023 11:49:57 +0200 Subject: [PATCH 17/19] Remove print statement --- etrago/cluster/disaggregation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index 21c49942..babd0b3b 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -685,7 +685,6 @@ def solve_partial_network( " it has on the buses of it's partial network." ) - print(clb.iloc[0].carrier) if clb.iloc[0].at[extendable_flag]: # That means, `p_nom` got computed via optimization and we # have to distribute it into the subnetwork first. From 3d98b6ddd711cb8a5081f102786244441d39c0e0 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 26 Oct 2023 11:50:25 +0200 Subject: [PATCH 18/19] Apply black --- etrago/cluster/electrical.py | 1 + 1 file changed, 1 insertion(+) diff --git a/etrago/cluster/electrical.py b/etrago/cluster/electrical.py index 207de3e1..828e1576 100755 --- a/etrago/cluster/electrical.py +++ b/etrago/cluster/electrical.py @@ -634,6 +634,7 @@ def unify_foreign_buses(etrago): axis=1, ) n_clusters = (foreign_buses_load.country == country).sum() + if n_clusters < len(df): ( busmap_country, From c646270971929b3fc3d08bf3a029a32d5347d5da Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 26 Oct 2023 11:53:06 +0200 Subject: [PATCH 19/19] Apply isort --- etrago/cluster/electrical.py | 5 +---- etrago/cluster/gas.py | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/etrago/cluster/electrical.py b/etrago/cluster/electrical.py index 828e1576..ef15db6d 100755 --- a/etrago/cluster/electrical.py +++ b/etrago/cluster/electrical.py @@ -46,10 +46,7 @@ strategies_generators, strategies_one_ports, ) - - from etrago.tools.utilities import ( - set_control_strategies, - ) + from etrago.tools.utilities import set_control_strategies logger = logging.getLogger(__name__) diff --git a/etrago/cluster/gas.py b/etrago/cluster/gas.py index eb5df003..cca92bbf 100644 --- a/etrago/cluster/gas.py +++ b/etrago/cluster/gas.py @@ -42,7 +42,6 @@ kmedoids_dijkstra_clustering, sum_with_inf, ) - from etrago.tools.utilities import set_control_strategies logger = logging.getLogger(__name__)