From e4e76e2c1769f56cda2851168a5b9220de94e1b8 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 16 Feb 2023 18:12:54 +0100 Subject: [PATCH 1/3] Update etrago integration --- ego/tools/io.py | 255 ++---------------------------------------------- 1 file changed, 8 insertions(+), 247 deletions(-) diff --git a/ego/tools/io.py b/ego/tools/io.py index 9b7cdac..a6c0b06 100644 --- a/ego/tools/io.py +++ b/ego/tools/io.py @@ -45,25 +45,9 @@ from egoio.db_tables.model_draft import EgoGridPfHvTempResolution as TempResolution from egoio.db_tables.model_draft import RenpassGisParameterRegion from egoio.tools import db - from etrago.appl import etrago - from etrago.tools.io import load_config_file - from etrago.tools.plot import ( - curtailment, - full_load_hours, - gen_dist, - gen_dist_diff, - max_load, - nodal_gen_dispatch, - nodal_production_balance, - plot_line_loading, - plot_line_loading_diff, - plot_q_flows, - plot_residual_load, - plot_stacked_gen, - plot_voltage, - storage_distribution, - storage_expansion, - ) + from etrago import Etrago + from etrago.appl import run_etrago + from geoalchemy2 import * from shapely.geometry import MultiPolygon, Point, Polygon from sqlalchemy import MetaData, and_, create_engine, func @@ -158,8 +142,6 @@ def __init__(self, *args, **kwargs): """ """ super(eTraGoResults, self).__init__(self, *args, **kwargs) self.etrago = None - self._etrago_network = None - self._etrago_disaggregated_network = None logger.info("eTraGo section started") @@ -217,237 +199,16 @@ def __init__(self, *args, **kwargs): if self.json_file["eGo"].get("csv_import_eTraGo") != False: - logger.info("Caution, import disaggregation " "data of former Cluster") - - # get pathway - pathway = self.json_file["eGo"].get("csv_import_eTraGo") - - try: - # create Network from csv - self._etrago_network = pypsa.Network() - self._etrago_network.import_from_csv_folder(pathway) - logger.info("Create eTraGo network from CSV result") - - # get disaggregation - self._etrago_disaggregated_network = pypsa.Network() - self._etrago_disaggregated_network.import_from_csv_folder( - pathway + "/disaggregated" - ) - logger.info( - "Create eTraGo disaggregated network " "from CSV result" - ) - - except TypeError: - file_path = "disaggregated/network.csv" - fix_leading_separator(pathway + "/" + file_path) + logger.info("Import eTraGo network from csv files") - file_path = "network.csv" - fix_leading_separator(pathway + "/" + file_path) - - self._etrago_network = pypsa.Network() - self._etrago_network.import_from_csv_folder(pathway) - logger.info("Create eTraGo network from CSV result") - - # get disaggregation - self._etrago_disaggregated_network = pypsa.Network() - self._etrago_disaggregated_network.import_from_csv_folder( - pathway + "/disaggregated" - ) - logger.info("Create eTraGo disaggregated network" "from CSV result") - - args_name = "args.json" - with open(pathway + "/" + args_name) as f: - etrago_args = json.load(f) - logger.info("Using argument file") - - if etrago_args.get("extendable") == ["network", "storages"]: - etrago_args.update({"extendable": ["network", "storage"]}) - logger.info("Changed naming of storages to storage of args") - - if etrago_args.get("extendable") == ["storages"]: - etrago_args.update({"extendable": ["storage"]}) - logger.info("Changed naming of storages to storage of args") - - for key in self.json_file["eTraGo"].keys(): - try: - self.json_file["eTraGo"][key] = etrago_args[key] - except KeyError: - pass + self.etrago = Etrago( + csv_folder_name = self.json_file['eGo'].get('csv_import_eTraGo')) else: logger.info("Create eTraGo network calcualted by eGo") - if self.json_file["eTraGo"]["disaggregation"] != False: - - etrago_network, etrago_disaggregated_network = etrago( - self.json_file["eTraGo"] - ) - - self._etrago_network = etrago_network - self._etrago_disaggregated_network = etrago_disaggregated_network - else: - logger.warning("Only one network is used.") - - etrago_network, etrago_disaggregated_network = etrago( - self.json_file["eTraGo"] - ) - - self._etrago_network = etrago_network - self._etrago_disaggregated_network = etrago_disaggregated_network - - # Add selected results to results container - # ----------------------------------------- - - self.etrago = pd.DataFrame() - self.etrago.network = self._etrago_network - self.etrago.disaggregated_network = self._etrago_disaggregated_network - - # Add function - self.etrago.storage_investment_costs = etrago_storages_investment( - self.etrago.network, self.json_file, self.session - ) - self.etrago.storage_charges = etrago_storages(self.etrago.network) - - self.etrago.operating_costs = etrago_operating_costs(self.etrago.network) - self.etrago.generator = create_etrago_results( - self.etrago.network, self.scn_name - ) - self.etrago.grid_investment_costs = etrago_grid_investment( - self.etrago.network, self.json_file, self.session - ) - - # add functions direct - # self._etrago_network.etrago_line_loading = etrago_line_loading - self.etrago.plot_line_loading = self._line_loading - self.etrago.plot_stacked_gen = self._stacked_gen - self.etrago.plot_curtailment = self._curtailment - self.etrago.plot_gen_dist = self._gen_dist - self.etrago.plot_storage_distribution = self._storage_distribution - self.etrago.plot_line_loading_diff = self._line_loading_diff - self.etrago.plot_residual_load = self._residual_load - self.etrago.plot_voltage = self._voltage - self.etrago.plot_nodal_gen_dispatch = self._nodal_gen_dispatch - self.etrago.plot_full_load_hours = self._full_load_hours - self.etrago.plot_q_flows = self._plot_q_flows - self.etrago.plot_max_load = self._max_load - self.etrago.plot_storage_expansion = self._storage_expansion - self.etrago.plot_nodal_production_balance = self._nodal_production_balance - self.etrago.plot_gen_dist_diff = self._gen_dist_diff - - if not "READTHEDOCS" in os.environ: - # include eTraGo functions and methods - def _gen_dist_diff(self, **kwargs): - """ - Integrate and use function from eTraGo. - For more information see: - """ - - return gen_dist_diff(networkA=self.etrago.network, **kwargs) - - def _nodal_production_balance(self, **kwargs): - """ - Integrate and use function from eTraGo. - For more information see: - """ - - return nodal_production_balance(network=self.etrago.network, **kwargs) - - def _storage_expansion(self, **kwargs): - """ - Integrate and use function from eTraGo. - For more information see: - """ - - return storage_expansion(network=self.etrago.network, **kwargs) - - def _max_load(self, **kwargs): - """ - Integrate and use function from eTraGo. - For more information see: - """ - - return max_load(network=self.etrago.network, **kwargs) - - def _plot_q_flows(self): - """ - Integrate and use function from eTraGo. - For more information see: - """ - - return plot_q_flows(network=self.etrago.network) - - def _line_loading(self, **kwargs): - """ - Integrate and use function from eTraGo. - For more information see: - """ - # add if time_step <1 -> plot - return plot_line_loading(network=self.etrago.network, **kwargs) - - def _stacked_gen(self, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return plot_stacked_gen(network=self.etrago.network, **kwargs) - - def _curtailment(self, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return curtailment(network=self.etrago.network, **kwargs) - - def _gen_dist(self, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return gen_dist(network=self.etrago.network, **kwargs) - - def _storage_distribution(self, scaling=1, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return storage_distribution( - network=self.etrago.network, scaling=1, **kwargs - ) - - def _voltage(self, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return plot_voltage(network=self.etrago.network, **kwargs) - - def _residual_load(self, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return plot_residual_load(network=self.etrago.network, **kwargs) - - def _line_loading_diff(self, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return plot_line_loading_diff(networkA=self.etrago.network, **kwargs) - - def _nodal_gen_dispatch(self, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return nodal_gen_dispatch(network=self.etrago.network, **kwargs) - - def _full_load_hours(self, **kwargs): - """ - Integrate function from eTraGo. - For more information see: - """ - return full_load_hours(network=self.etrago.network, **kwargs) + run_etrago(args= self.json_file['eTraGo'], + json_path=None) class eDisGoResults(eTraGoResults): From 5e94020019fd0738b012356f84138877c37f7228 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 16 Feb 2023 18:14:33 +0100 Subject: [PATCH 2/3] Delete import of old etrago plots --- ego/tools/plots.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ego/tools/plots.py b/ego/tools/plots.py index 40f7a90..2a4acdd 100644 --- a/ego/tools/plots.py +++ b/ego/tools/plots.py @@ -33,17 +33,6 @@ import pyproj as proj - from etrago.tools.plot import ( - add_coordinates, - coloring, - curtailment, - gen_dist, - plot_line_loading, - plot_residual_load, - plot_stacked_gen, - plot_voltage, - storage_distribution, - ) from geoalchemy2 import * from pypsa import Network as PyPSANetwork from shapely.geometry import MultiPolygon, Point, Polygon From 92eb1005d095908d0ed00f390bf7fd443da6895b Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Thu, 16 Feb 2023 18:17:04 +0100 Subject: [PATCH 3/3] Update etrago parameters --- ego/scenario_setting.json | 201 ++++++++++++++++++++++++++------------ 1 file changed, 140 insertions(+), 61 deletions(-) diff --git a/ego/scenario_setting.json b/ego/scenario_setting.json index 8008930..19f5eca 100644 --- a/ego/scenario_setting.json +++ b/ego/scenario_setting.json @@ -1,67 +1,146 @@ { - "eGo": { - "eTraGo": true, - "eDisGo": true, - "csv_import_eTraGo": false, - "csv_import_eDisGo": false, + "eGo": { + "eTraGo": true, + "eDisGo": true, + "csv_import_eTraGo": false, + "csv_import_eDisGo": false + }, + "eTraGo": { + "db": "egon-data", + "gridversion": null, + "method": { + "type": "lopf", + "n_iter": 4, + "pyomo": true }, - "eTraGo": { - "db": "oedb", - "gridversion": "v0.4.5", - "method": "lopf", - "pf_post_lopf": true, - "start_snapshot": 1000, - "end_snapshot": 1005, - "solver": "gurobi", - "solver_options": {}, - "scn_name": "eGo 100", - "scn_extension": null, - "scn_decommissioning": null, - "lpfile": false, - "csv_export": "results/your_results", - "db_export": false, - "extendable": ["storage", "network"], - "generator_noise": 789456, - "minimize_loading": false, - "ramp_limits": false, - "extra_functionality": null, - "network_clustering_kmeans": 10, - "load_cluster": false, - "network_clustering_ehv": false, - "disaggregation": "uniform", - "snapshot_clustering": false, - "parallelisation": false, - "skip_snapshots": false, - "line_grouping": false, - "branch_capacity_factor": {"HV": 0.5, "eHV": 0.7}, - "load_shedding": false, - "foreign_lines": {"carrier": "AC", "capacity": "osmTGmod"}, - "comments": "", + "pf_post_lopf": { + "active": true, + "add_foreign_lopf": true, + "q_allocation": "p_nom" }, - "eDisGo": { - "db": "oedb", - "gridversion": "v0.4.5", - "ding0_files": "/path/to_your/.dingo/grids", - "choice_mode": "cluster", - "cluster_attributes": [ - "farthest_node", - "wind_cap", - "solar_cap", - "extended_storage", + "start_snapshot": 1, + "end_snapshot": 2, + "solver": "gurobi", + "solver_options": { + "BarConvTol": 1e-05, + "FeasibilityTol": 1e-05, + "method": 2, + "crossover": 0, + "logFile": "solver_etragos.log", + "threads": 4 + }, + "model_formulation": "kirchhoff", + "scn_name": "eGon2035", + "scn_extension": null, + "scn_decommissioning": null, + "lpfile": false, + "csv_export": "test", + "extendable": { + "extendable_components": [ + "as_in_db" ], - "only_cluster": false, - "manual_grids": [], - "no_grids": 2, - "parallelization": true, - "max_calc_time": 0.5, - "max_workers": 2, - "initial_reinforcement": true, - "apply_curtailment": true, - "curtailment_voltage_threshold": 0, - "storage_distribution": true, - "max_cos_phi_renewable": 0.9, - "results": "results/another_result", - "solver": "gurobi", - "timesteps_pfa": "snapshot_analysis", + "upper_bounds_grid": { + "grid_max_D": null, + "grid_max_abs_D": { + "380": { + "i": 1020, + "wires": 4, + "circuits": 4 + }, + "220": { + "i": 1020, + "wires": 4, + "circuits": 4 + }, + "110": { + "i": 1020, + "wires": 4, + "circuits": 2 + }, + "dc": 0 + }, + "grid_max_foreign": 4, + "grid_max_abs_foreign": null + } + }, + "generator_noise": 789456, + "extra_functionality": {}, + "network_clustering": { + "random_state": 42, + "active": true, + "method": "kmedoids-dijkstra", + "n_clusters_AC": 30, + "cluster_foreign_AC": false, + "method_gas": "kmedoids-dijkstra", + "n_clusters_gas": 20, + "cluster_foreign_gas": false, + "k_busmap": false, + "kmeans_gas_busmap": false, + "line_length_factor": 1, + "remove_stubs": false, + "use_reduced_coordinates": false, + "bus_weight_tocsv": null, + "bus_weight_fromcsv": null, + "gas_weight_tocsv": null, + "gas_weight_fromcsv": null, + "n_init": 10, + "max_iter": 100, + "tol": 1e-06, + "CPU_cores": 4 + }, + "sector_coupled_clustering": { + "active": true, + "carrier_data": { + "central_heat": { + "base": [ + "CH4", + "AC" + ], + "strategy": "simultaneous" + } + } + }, + "network_clustering_ehv": false, + "disaggregation": "uniform", + "snapshot_clustering": { + "active": false, + "method": "segmentation", + "extreme_periods": null, + "how": "daily", + "storage_constraints": "soc_constraints", + "n_clusters": 5, + "n_segments": 5 + }, + "skip_snapshots": false, + "dispatch_disaggregation": false, + "branch_capacity_factor": { + "HV": 0.5, + "eHV": 0.7 + }, + "load_shedding": false, + "foreign_lines": { + "carrier": "AC", + "capacity": "osmTGmod" }, + "comments": null +}, + "eDisGo": { + "db": "oedb", + "gridversion": "v0.4.5", + "ding0_path": "/path/to_your/.dingo/grids", + "choice_mode": "cluster", + "cluster_attributes":["farthest_node", "wind_cap", "solar_cap", "extended_storage"], + "only_cluster": false, + "manual_grids": [], + "no_grids": 2, + "parallelization":true, + "max_calc_time": 0.5, + "max_workers":2, + "initial_reinforcement":true, + "max_cos_phi_renewable": 0.9, + "results": "results/another_result", + "solver": "gurobi", + "timesteps_pfa": "snapshot_analysis" + } + }