From 4a6dd2fe33125086926f6653b55c308b8efb8f0c Mon Sep 17 00:00:00 2001 From: AmosSchledorn Date: Fri, 2 Aug 2024 15:56:37 +0200 Subject: [PATCH] fix naming bugs --- config/config.default.yaml | 15 +++-------- scripts/build_cop_profiles/run.py | 12 ++++----- scripts/prepare_sector_network.py | 43 +++++++++++++++---------------- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index bfa99d90..ebb8eb4f 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -417,20 +417,13 @@ sector: isentropic_compressor_efficiency: 0.8 heat_loss: 0.0 heat_pump_sources: - central: + urban central: - air - decentral: + urban decentral: + - air + rural: - air - ground - heat_systems: - rural: - - residential rural - - services rural - urban decentral: - - residential urban decentral - - services urban decentral - urban central: - - urban central cluster_heat_buses: true heat_demand_cutout: default bev_dsm_restriction_value: 0.75 diff --git a/scripts/build_cop_profiles/run.py b/scripts/build_cop_profiles/run.py index 5178483a..583d097a 100644 --- a/scripts/build_cop_profiles/run.py +++ b/scripts/build_cop_profiles/run.py @@ -12,18 +12,18 @@ from DecentralHeatingCopApproximator import DecentralHeatingCopApproximator def get_cop( - heat_system_type: str, + heat_system_category: str, heat_source: str, source_inlet_temperature_celsius: xr.DataArray, ) -> xr.DataArray: - if heat_system_type == "decentral": + if heat_system_category in ["urban decentral", "rural"]: return DecentralHeatingCopApproximator( forward_temperature_celsius=snakemake.params.heat_pump_sink_T_decentral_heating, source_inlet_temperature_celsius=source_inlet_temperature_celsius, source_type=heat_source, ).approximate_cop() - elif heat_system_type == "central": + elif heat_system_category == "urban central": return CentralHeatingCopApproximator( forward_temperature_celsius=snakemake.params.forward_temperature_central_heating, return_temperature_celsius=snakemake.params.return_temperature_central_heating, @@ -33,7 +33,7 @@ def get_cop( ).approximate_cop() else: raise ValueError( - f"Invalid heat system type '{heat_system_type}'. Must be one of ['decentral', 'central']" + f"Invalid heat system type '{heat_system_category}'. Must be one of ['urban decentral', 'urban central', 'rural]" ) @@ -50,14 +50,14 @@ if __name__ == "__main__": set_scenario_config(snakemake) cop_all_system_types = [] - for heat_system_type, heat_sources in snakemake.params.heat_pump_sources.items(): + for heat_system_category, heat_sources in snakemake.params.heat_pump_sources.items(): cop_this_system_type = [] for heat_source in heat_sources: source_inlet_temperature_celsius = xr.open_dataarray( snakemake.input[f"temp_{heat_source.replace('ground', 'soil')}_total"] ) cop_da = get_cop( - heat_system_type=heat_system_type, + heat_system_category=heat_system_category, heat_source=heat_source, source_inlet_temperature_celsius=source_inlet_temperature_celsius, ) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 52989c2d..989f4dc2 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -1840,9 +1840,9 @@ def add_heat(n, costs): n.madd( "Bus", - nodes + f" {heat_system} heat", + nodes + f" {heat_system.value} heat", location=nodes, - carrier=f"{heat_system} heat", + carrier=f"{heat_system.value} heat", unit="MWh_th", ) @@ -1891,10 +1891,10 @@ def add_heat(n, costs): ) ## Add heat pumps - for heat_source in snakemake.params.heat_pump_sources[heat_system.system_type]: + for heat_source in snakemake.params.heat_pump_sources[heat_system.system_category]: costs_name = heat_system.heat_pump_costs_name(heat_source) efficiency = ( - cop.sel(heat_system=heat_system.system_type, heat_source=heat_source, name=nodes) + cop.sel(heat_system=heat_system.system_category, heat_source=heat_source, name=nodes) .to_pandas() .reindex(index=n.snapshots) if options["time_dep_hp_cop"] @@ -2013,7 +2013,7 @@ def add_heat(n, costs): lifetime=costs.at[heat_system.system_type + " solar thermal", "lifetime"], ) - if options["chp"] and heat_system == "urban central": + if options["chp"] and heat_system == HeatSystem.URBAN_CENTRAL: # add gas CHP; biomass CHP is added in biomass section n.madd( "Link", @@ -2070,7 +2070,7 @@ def add_heat(n, costs): lifetime=costs.at["central gas CHP", "lifetime"], ) - if options["chp"] and options["micro_chp"] and heat_system != "urban central": + if options["chp"] and options["micro_chp"] and heat_system.value != "urban central": n.madd( "Link", nodes + f" {heat_system} micro gas CHP", @@ -2079,7 +2079,7 @@ def add_heat(n, costs): bus1=nodes, bus2=nodes + f" {heat_system} heat", bus3="co2 atmosphere", - carrier=heat_system + " micro gas CHP", + carrier=heat_system.value + " micro gas CHP", efficiency=costs.at["micro CHP", "efficiency"], efficiency2=costs.at["micro CHP", "efficiency-heat"], efficiency3=costs.at["gas", "CO2 intensity"], @@ -2106,36 +2106,35 @@ def add_heat(n, costs): # share of space heat demand 'w_space' of total heat demand w_space = {} - for sector in HeatSector: - w_space[sector.value] = heat_demand[sector.value + " space"] / ( - heat_demand[sector.value + " space"] + heat_demand[sector.value + " water"] + for sector in sectors: + w_space[sector] = heat_demand[sector + " space"] / ( + heat_demand[sector + " space"] + heat_demand[sector + " water"] ) w_space["tot"] = ( heat_demand["services space"] + heat_demand["residential space"] ) / heat_demand.T.groupby(level=[1]).sum().T - for heat_system in n.loads[ - n.loads.carrier.isin([x.value + " heat" for x in HeatSystem]) + for name in n.loads[ + n.loads.carrier.isin([x + " heat" for x in heat_systems]) ].index: - node = n.buses.loc[heat_system, "location"] + node = n.buses.loc[name, "location"] ct = pop_layout.loc[node, "ct"] # weighting 'f' depending on the size of the population at the node - if "urban central" in heat_system: + if "urban central" in name: f = dist_fraction[node] - elif "urban decentral" in heat_system: + elif "urban decentral" in name: f = urban_fraction[node] - dist_fraction[node] else: f = 1 - urban_fraction[node] if f == 0: continue - # get sector name ("residential"/"services"/or both "tot" for urban central) - if "urban central" in heat_system: + if "urban central" in name: sec = "tot" - if "residential" in heat_system: + if "residential" in name: sec = "residential" - if "services" in heat_system: + if "services" in name: sec = "services" # get floor aread at node and region (urban/rural) in m^2 @@ -2143,7 +2142,7 @@ def add_heat(n, costs): pop_layout.loc[node].fraction * floor_area.loc[ct, "value"] * 10**6 ).loc[sec] * f # total heat demand at node [MWh] - demand = n.loads_t.p_set[heat_system] + demand = n.loads_t.p_set[name] # space heat demand at node [MWh] space_heat_demand = demand * w_space[sec][node] @@ -2184,12 +2183,12 @@ def add_heat(n, costs): # add for each retrofitting strength a generator with heat generation profile following the profile of the heat demand for strength in strengths: - node_name = " ".join(heat_system.split(" ")[2::]) + node_name = " ".join(name.split(" ")[2::]) n.madd( "Generator", [node], suffix=" retrofitting " + strength + " " + node_name, - bus=heat_system, + bus=name, carrier="retrofitting", p_nom_extendable=True, p_nom_max=dE_diff[strength]