@@ -156,10 +156,13 @@ def add_power_capacities_installed_before_baseyear(
156156 grouping_years : list [int ],
157157 baseyear : int ,
158158 powerplants_file : str ,
159+ custom_powerplants_file : str ,
159160 countries : list [str ],
160161 capacity_threshold : float ,
161162 lifetime_values : dict [str , float ],
163+ lifetime_gas_chp : int ,
162164 renewable_carriers : list [str ],
165+ options : dict ,
163166) -> None :
164167 """
165168 Add power generation capacities installed before base year.
@@ -176,23 +179,25 @@ def add_power_capacities_installed_before_baseyear(
176179 Base year for analysis
177180 powerplants_file : str
178181 Path to powerplants CSV file
182+ custom_powerplants_file : str
183+ Path to custom powerplants CSV file
179184 countries : list
180185 List of countries to consider
181186 capacity_threshold : float
182187 Minimum capacity threshold
183188 lifetime_values : dict
184189 Default values for missing data
185- renewable_carriers: list
190+ lifetime_gas_chp: int,
191+ Lifetime for gas CHPs if missing
192+ renewable_carriers: list[str]
186193 List of renewable carriers in the network
194+ options: dict,
187195 """
188196 logger .debug (f"Adding power capacities installed before { baseyear } " )
189197
190198 df_agg = pd .read_csv (powerplants_file , index_col = 0 )
191-
192- if snakemake .input .get ("custom_powerplants" ):
193- df_agg = add_custom_powerplants (
194- df_agg , snakemake .input .custom_powerplants , True
195- )
199+ if custom_powerplants_file :
200+ df_agg = add_custom_powerplants (df_agg , custom_powerplants_file , True )
196201
197202 rename_fuel = {
198203 "Hard Coal" : "coal" ,
@@ -258,7 +263,18 @@ def add_power_capacities_installed_before_baseyear(
258263 )
259264
260265 # add chp plants
261- add_chp_plants (n , grouping_years , costs , baseyear )
266+ add_chp_plants (
267+ n ,
268+ grouping_years ,
269+ costs ,
270+ baseyear ,
271+ powerplants_file ,
272+ custom_powerplants_file ,
273+ lifetime_values ,
274+ lifetime_gas_chp ,
275+ capacity_threshold ,
276+ options ,
277+ )
262278
263279 # drop assets which are already phased out / decommissioned
264280 phased_out = df_agg [df_agg ["DateOut" ] < baseyear ].index
@@ -484,7 +500,18 @@ def add_power_capacities_installed_before_baseyear(
484500 ]
485501
486502
487- def add_chp_plants (n , grouping_years , costs , baseyear ):
503+ def add_chp_plants (
504+ n ,
505+ grouping_years ,
506+ costs ,
507+ baseyear ,
508+ powerplants_file ,
509+ custom_powerplants_file ,
510+ lifetime_values ,
511+ lifetime_gas_chp ,
512+ capacity_threshold ,
513+ options ,
514+ ):
488515 # rename fuel of CHPs - lignite not in DEA database
489516 rename_fuel = {
490517 "Hard Coal" : "coal" ,
@@ -495,13 +522,13 @@ def add_chp_plants(n, grouping_years, costs, baseyear):
495522 "Oil" : "oil" ,
496523 }
497524
498- ppl = pd .read_csv (snakemake . input . powerplants , index_col = 0 )
525+ ppl = pd .read_csv (powerplants_file , index_col = 0 )
499526
500- if snakemake . input . get ( "custom_powerplants" ) :
501- if snakemake . input . custom_powerplants .endswith ("german_chp_{clusters}.csv" ):
527+ if custom_powerplants_file :
528+ if custom_powerplants_file .endswith ("german_chp_{clusters}.csv" ):
502529 logger .info ("Supersedeing default German CHPs with custom_powerplants." )
503530 ppl = ppl .query ("~(Set == 'CHP' and Country == 'DE')" )
504- ppl = add_custom_powerplants (ppl , snakemake . input . custom_powerplants , True )
531+ ppl = add_custom_powerplants (ppl , custom_powerplants_file , True )
505532
506533 # drop assets which are already phased out / decommissioned
507534 # drop hydro, waste and oil fueltypes for CHP
@@ -519,11 +546,11 @@ def add_chp_plants(n, grouping_years, costs, baseyear):
519546 grouping_years , np .digitize (chp .DateIn , grouping_years , right = True )
520547 )
521548 chp ["lifetime" ] = (chp .DateOut - chp ["grouping_year" ] + 1 ).fillna (
522- snakemake . params . costs [ "fill_values" ] ["lifetime" ]
549+ lifetime_values ["lifetime" ]
523550 )
524551 chp .loc [chp .Fueltype == "gas" , "lifetime" ] = (
525552 chp .DateOut - chp ["grouping_year" ] + 1
526- ).fillna (snakemake . params . existing_capacities [ "fill_value_gas_chp_lifetime" ] )
553+ ).fillna (lifetime_gas_chp )
527554
528555 chp = chp .loc [
529556 chp .grouping_year + chp .lifetime > baseyear
@@ -611,7 +638,7 @@ def add_chp_plants(n, grouping_years, costs, baseyear):
611638 for grouping_year , generator in mastr_chp_p_nom .index :
612639 # capacity is the capacity in MW at each node for this
613640 p_nom = mastr_chp_p_nom .loc [grouping_year , generator ]
614- threshold = snakemake . params . existing_capacities [ "threshold_capacity" ]
641+ threshold = capacity_threshold
615642 p_nom = p_nom [p_nom > threshold ]
616643
617644 efficiency_power = mastr_chp_efficiency_power .loc [grouping_year , generator ]
@@ -701,7 +728,7 @@ def add_chp_plants(n, grouping_years, costs, baseyear):
701728 )
702729 for grouping_year , generator in chp_nodal_p_nom .index :
703730 p_nom = chp_nodal_p_nom .loc [grouping_year , generator ]
704- threshold = snakemake . params . existing_capacities [ "threshold_capacity" ]
731+ threshold = capacity_threshold
705732 p_nom = p_nom [p_nom > threshold ]
706733 lifetime = chp_nodal_lifetime .loc [grouping_year , generator ]
707734
@@ -1156,10 +1183,15 @@ def add_heating_capacities_installed_before_baseyear(
11561183 grouping_years = grouping_years_power ,
11571184 baseyear = baseyear ,
11581185 powerplants_file = snakemake .input .powerplants ,
1186+ custom_powerplants_file = snakemake .input .get ("custom_powerplants" , "" ),
11591187 countries = snakemake .config ["countries" ],
11601188 capacity_threshold = snakemake .params .existing_capacities ["threshold_capacity" ],
11611189 lifetime_values = snakemake .params .costs ["fill_values" ],
1190+ lifetime_gas_chp = snakemake .params .existing_capacities [
1191+ "fill_value_gas_chp_lifetime"
1192+ ],
11621193 renewable_carriers = renewable_carriers ,
1194+ options = options ,
11631195 )
11641196
11651197 if options ["heating" ]:
0 commit comments