@@ -2331,11 +2331,49 @@ def get_final_energy(
23312331 # straightforward for the other categories
23322332 # !!! TODO this assert is temporarily disabled because of https://github.com/PyPSA/pypsa-eur/issues/985
23332333
2334+ central_heat_withdrawal = (
2335+ n .statistics .withdrawal (
2336+ bus_carrier = ["urban central heat" ],
2337+ ** kwargs ,
2338+ )
2339+ .filter (
2340+ like = region ,
2341+ )
2342+ .groupby ("carrier" )
2343+ .sum ()
2344+ .multiply (MWh2PJ )
2345+ )
2346+
2347+ var ["Final Energy|Carbon Dioxide Removal|Heat" ] = decentral_heat_withdrawal .get (
2348+ "DAC" , 0
2349+ ) + central_heat_withdrawal .get ("DAC" , 0 )
2350+
2351+ electricity = (
2352+ n .statistics .withdrawal (
2353+ bus_carrier = "AC" ,
2354+ ** kwargs ,
2355+ )
2356+ .filter (
2357+ like = region ,
2358+ )
2359+ .groupby ("carrier" )
2360+ .sum ()
2361+ .multiply (MWh2PJ )
2362+ )
2363+
2364+ var ["Final Energy|Carbon Dioxide Removal|Electricity" ] = electricity .get ("DAC" , 0 )
2365+
2366+ var ["Final Energy|Carbon Dioxide Removal" ] = (
2367+ var ["Final Energy|Carbon Dioxide Removal|Electricity" ]
2368+ + var ["Final Energy|Carbon Dioxide Removal|Heat" ]
2369+ )
2370+
23342371 var ["Final Energy|Electricity" ] = (
23352372 var ["Final Energy|Agriculture|Electricity" ]
23362373 + var ["Final Energy|Residential and Commercial|Electricity" ]
23372374 + var ["Final Energy|Transportation|Electricity" ]
23382375 + var ["Final Energy|Industry excl Non-Energy Use|Electricity" ]
2376+ + var ["Final Energy|Carbon Dioxide Removal|Electricity" ]
23392377 )
23402378
23412379 var ["Final Energy|Solids" ] = (
@@ -2385,6 +2423,7 @@ def get_final_energy(
23852423 var ["Final Energy|Agriculture|Heat" ]
23862424 + var ["Final Energy|Residential and Commercial|Heat" ]
23872425 + var ["Final Energy|Industry excl Non-Energy Use|Heat" ]
2426+ + var ["Final Energy|Carbon Dioxide Removal|Heat" ]
23882427 )
23892428 # var["Final Energy|Solar"] = \
23902429 var ["Final Energy|Hydrogen" ] = (
@@ -2410,30 +2449,6 @@ def get_final_energy(
24102449
24112450 var ["Final Energy|Waste" ] = waste_withdrawal .get ("HVC to air" , 0 )
24122451
2413- var ["Final Energy|Carbon Dioxide Removal|Heat" ] = decentral_heat_withdrawal .get (
2414- "DAC" , 0
2415- )
2416-
2417- electricity = (
2418- n .statistics .withdrawal (
2419- bus_carrier = "AC" ,
2420- ** kwargs ,
2421- )
2422- .filter (
2423- like = region ,
2424- )
2425- .groupby ("carrier" )
2426- .sum ()
2427- .multiply (MWh2PJ )
2428- )
2429-
2430- var ["Final Energy|Carbon Dioxide Removal|Electricity" ] = electricity .get ("DAC" , 0 )
2431-
2432- var ["Final Energy|Carbon Dioxide Removal" ] = (
2433- var ["Final Energy|Carbon Dioxide Removal|Electricity" ]
2434- + var ["Final Energy|Carbon Dioxide Removal|Heat" ]
2435- )
2436-
24372452 var ["Final Energy incl Non-Energy Use incl Bunkers" ] = (
24382453 var ["Final Energy|Industry" ]
24392454 + var ["Final Energy|Residential and Commercial" ]
@@ -2897,6 +2912,7 @@ def get_emissions(n, region, _energy_totals, industry_demand):
28972912 + var ["Emissions|Gross Fossil CO2|Energy|Supply|Hydrogen" ]
28982913 + var ["Emissions|Gross Fossil CO2|Energy|Supply|Liquids" ]
28992914 + var ["Emissions|Gross Fossil CO2|Energy|Supply|Solids" ]
2915+ + var ["Emissions|Gross Fossil CO2|Energy|Supply|Gases" ]
29002916 )
29012917
29022918 var ["Emissions|Gross Fossil CO2|Energy" ] = (
@@ -2927,12 +2943,6 @@ def get_emissions(n, region, _energy_totals, industry_demand):
29272943 var ["Emissions|CO2|Energy" ] + var ["Emissions|CO2|Industrial Processes" ]
29282944 )
29292945
2930- var ["Emissions|Gross Fossil CO2|Energy|Supply" ] = (
2931- var ["Emissions|Gross Fossil CO2|Energy|Supply|Electricity" ]
2932- + var ["Emissions|Gross Fossil CO2|Energy|Supply|Heat" ]
2933- + var ["Emissions|Gross Fossil CO2|Energy|Supply|Hydrogen" ]
2934- )
2935-
29362946 emission_difference = var ["Emissions|CO2" ] - (
29372947 var ["Emissions|CO2|Energy and Industrial Processes" ]
29382948 + var ["Emissions|CO2|Energy|Demand|Bunkers" ]
@@ -4174,72 +4184,92 @@ def get_trade(n, region):
41744184 var = pd .Series ()
41754185
41764186 def get_export_import_links (n , region , carriers ):
4177- exporting = n .links .index [
4187+ # note: links can also used bidirectional if efficiency=1 (e.g. "H2 pipeline retrofitted")
4188+ outgoing = n .links .index [
41784189 (n .links .carrier .isin (carriers ))
41794190 & (n .links .bus0 .str [:2 ] == region )
41804191 & (n .links .bus1 .str [:2 ] != region )
41814192 ]
41824193
4183- importing = n .links .index [
4194+ incoming = n .links .index [
41844195 (n .links .carrier .isin (carriers ))
41854196 & (n .links .bus0 .str [:2 ] != region )
41864197 & (n .links .bus1 .str [:2 ] == region )
41874198 ]
41884199
41894200 exporting_p = (
4190- n .links_t .p0 .loc [:, exporting ]
4201+ # if p0 > 0 (=clip(lower=0)) system is withdrawing from bus0 (DE) and feeding into bus1 (non-DE) -> export
4202+ n .links_t .p0 .loc [:, outgoing ]
41914203 .clip (lower = 0 )
41924204 .multiply (n .snapshot_weightings .generators , axis = 0 )
41934205 .values .sum ()
4194- - n .links_t .p0 .loc [:, importing ]
4195- .clip (upper = 0 )
4206+ +
4207+ # if p1 > 0 system is withdrawing from bus1 (DE) and feeding into bus0 (non-DE) -> export
4208+ n .links_t .p1 .loc [:, incoming ]
4209+ .clip (lower = 0 )
41964210 .multiply (n .snapshot_weightings .generators , axis = 0 )
41974211 .values .sum ()
41984212 )
4213+
41994214 importing_p = (
4200- n .links_t .p0 .loc [:, importing ]
4201- .clip (lower = 0 )
4215+ # if p1 < 0 (=clip(upper=0)) system is feeding into bus1 (DE) and withdrawing from bus0 (non-DE) -> import (with negative sign here)
4216+ n .links_t .p1 .loc [:, incoming ]
4217+ .clip (upper = 0 )
42024218 .multiply (n .snapshot_weightings .generators , axis = 0 )
42034219 .values .sum ()
4204- - n .links_t .p0 .loc [:, exporting ]
4220+ * - 1
4221+ +
4222+ # if p0 < 0 (=clip(upper=0)) system is feeding into bus0 (DE) and withdrawing from bus1 (non-DE) -> import (with negative sign here)
4223+ n .links_t .p0 .loc [:, outgoing ]
42054224 .clip (upper = 0 )
42064225 .multiply (n .snapshot_weightings .generators , axis = 0 )
42074226 .values .sum ()
4227+ * - 1
42084228 )
42094229
42104230 return exporting_p , importing_p
42114231
42124232 # Trade|Secondary Energy|Electricity|Volume
4213- exporting_ac = n .lines .index [
4233+ outgoing_ac = n .lines .index [
42144234 (n .lines .carrier == "AC" )
42154235 & (n .lines .bus0 .str [:2 ] == region )
42164236 & (n .lines .bus1 .str [:2 ] != region )
42174237 ]
42184238
4219- importing_ac = n .lines .index [
4239+ incoming_ac = n .lines .index [
42204240 (n .lines .carrier == "AC" )
42214241 & (n .lines .bus0 .str [:2 ] != region )
42224242 & (n .lines .bus1 .str [:2 ] == region )
42234243 ]
4244+
42244245 exporting_p_ac = (
4225- n .lines_t .p0 .loc [:, exporting_ac ]
4246+ # if p0 > 0 (=clip(lower=0)) system is withdrawing from bus0 (DE) and feeding into bus1 (non-DE) -> export
4247+ n .lines_t .p0 .loc [:, outgoing_ac ]
42264248 .clip (lower = 0 )
42274249 .multiply (n .snapshot_weightings .generators , axis = 0 )
42284250 .values .sum ()
4229- - n .lines_t .p0 .loc [:, importing_ac ]
4230- .clip (upper = 0 )
4251+ +
4252+ # if p1 > 0 system is withdrawing from bus1 (DE) and feeding into bus0 (non-DE) -> export
4253+ n .lines_t .p1 .loc [:, incoming_ac ]
4254+ .clip (lower = 0 )
42314255 .multiply (n .snapshot_weightings .generators , axis = 0 )
42324256 .values .sum ()
42334257 )
4258+
42344259 importing_p_ac = (
4235- n .lines_t .p0 .loc [:, importing_ac ]
4236- .clip (lower = 0 )
4260+ # if p1 < 0 (=clip(upper=0)) system is feeding into bus1 (DE) and withdrawing from bus0 (non-DE) -> import (with negative sign here)
4261+ n .lines_t .p1 .loc [:, incoming_ac ]
4262+ .clip (upper = 0 )
42374263 .multiply (n .snapshot_weightings .generators , axis = 0 )
42384264 .values .sum ()
4239- - n .lines_t .p0 .loc [:, exporting_ac ]
4265+ * - 1
4266+ +
4267+ # if p0 < 0 (=clip(upper=0)) system is feeding into bus0 (DE) and withdrawing from bus1 (non-DE) -> import (with negative sign here)
4268+ n .lines_t .p0 .loc [:, outgoing_ac ]
42404269 .clip (upper = 0 )
42414270 .multiply (n .snapshot_weightings .generators , axis = 0 )
42424271 .values .sum ()
4272+ * - 1
42434273 )
42444274
42454275 exports_dc , imports_dc = get_export_import_links (n , region , ["DC" ])
@@ -5141,6 +5171,23 @@ def get_data(
51415171 var ["Investment|Energy Supply|Hydrogen|Fossil" ] = var [
51425172 "Investment|Energy Supply|Hydrogen|Gas"
51435173 ]
5174+ # For internal use only and translated directly to TWh
5175+ var ["Demand|Electricity" ] = (
5176+ var .reindex (
5177+ [
5178+ "Secondary Energy|Electricity|Storage Losses" ,
5179+ "Secondary Energy Input|Electricity|Heat" ,
5180+ "Secondary Energy Input|Electricity|Hydrogen" ,
5181+ "Secondary Energy Input|Electricity|Liquids" ,
5182+ "Final Energy|Industry|Electricity" ,
5183+ "Final Energy|Agriculture|Electricity" ,
5184+ "Final Energy|Residential and Commercial|Electricity" ,
5185+ "Final Energy|Transportation|Electricity" ,
5186+ "Final Energy|Carbon Dioxide Removal|Electricity" ,
5187+ ]
5188+ ).sum ()
5189+ / 3.6
5190+ )
51445191
51455192 data = []
51465193 for v in var .index :
0 commit comments