From 7b4eaf424eec0970693e16acd3bd1535baaa737c Mon Sep 17 00:00:00 2001 From: maartenbrinkerink <65602545+maartenbrinkerink@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:40:07 -0500 Subject: [PATCH] Added final year entry to user_defined_capacity_transmission This allows for setting expansion candidates for different year periods (or single years) at different build rates. --- config/config.yaml | 18 +++-- .../transmission/user_defined_capacity.py | 74 +++++++++---------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 90fdd4b..28ddff4 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -67,18 +67,22 @@ user_defined_capacity_transmission: # capacity, # build_year, # first_year_of_expansion, + # final_year_of_expansion, # build_rate_per_year, # capex_cost, # annual_fixed_O&M_cost, # variable_O&M_cost, # efficiency] - trn1: [TRNINDEAINDNE, 5, 1975, 2030, 10, 350, 13, 4, 95] - trn2: [TRNINDEAINDNE, 1, 1990, 2030, 10, 350, 13, 4, 95] - trn3: [TRNINDEAINDNE, 2, 2035, 2030, 10, 350, 13, 4, 95] - trn4: [TRNINDNOINDSO, 0, 2020, 2025, 0.5, 620, 24, 4, 92] - # Per technology, only the capacity and build_year - # parameters can deviate from each other. For all other - # parameters only the last entry will be used. + trn1: [TRNINDEAINDNE, 5, 1975, 2025, 2025, 0, 350, 13, 4, 95] + trn2: [TRNINDEAINDNE, 1, 1990, 2025, 2025, 0, 350, 13, 4, 95] + trn3: [TRNINDEAINDNE, 2, 2035, 2025, 2025, 0, 350, 13, 4, 95] + trn4: [TRNINDEAINDNE, 0, 2020, 2025, 2025, 1, 350, 13, 4, 95] + trn5: [TRNINDEAINDNE, 0, 2020, 2030, 2040, 2, 350, 13, 4, 95] + trn6: [TRNINDEAINDNE, 0, 2020, 2040, 2050, 3, 350, 13, 4, 95] + trn7: [TRNINDNOINDSO, 0, 2020, 2025, 2025, 0.5, 620, 24, 4, 92] + # Per technology, only the capacity, build_year, first_year_of_expansion, + # final_year_of_expansion and build_rate_per_year parameters can deviate + # from each other. For all other parameters only the last entry will be used. user_defined_capacity_storage: # entry: [technology, diff --git a/workflow/scripts/osemosys_global/transmission/user_defined_capacity.py b/workflow/scripts/osemosys_global/transmission/user_defined_capacity.py index 3934ea0..80515cb 100644 --- a/workflow/scripts/osemosys_global/transmission/user_defined_capacity.py +++ b/workflow/scripts/osemosys_global/transmission/user_defined_capacity.py @@ -1,6 +1,7 @@ """Function to integrate user defined capacities for transmission.""" import pandas as pd +import numpy as np import itertools from data import get_years @@ -12,23 +13,25 @@ def set_user_defined_capacity_trn(tech_capacity_trn, op_life_dict, start_year, end_year, region_name): techCapacity_trn = [] + build_year_dict = {} first_year_expansion_dict = {} + final_year_expansion_dict = {} build_rate_dict = {} capex_dict = {} var_dict = {} fix_dict = {} - build_year_dict = {} efficiency_dict = {} for idx, tech_params in tech_capacity_trn.items(): techCapacity_trn.append([idx, tech_params[0], tech_params[1], tech_params[2]]) build_year_dict[idx] = tech_params[2] first_year_expansion_dict[idx] = tech_params[3] - build_rate_dict[idx] = tech_params[4] - capex_dict[idx] = tech_params[5] - fix_dict[idx] = tech_params[6] - var_dict[idx] = tech_params[7] - efficiency_dict[idx] = tech_params[8] + final_year_expansion_dict[idx] = tech_params[4] + build_rate_dict[idx] = tech_params[5] + capex_dict[idx] = tech_params[6] + fix_dict[idx] = tech_params[7] + var_dict[idx] = tech_params[8] + efficiency_dict[idx] = tech_params[9] tech_capacity_trn_df = pd.DataFrame(techCapacity_trn, columns=['idx', 'TECHNOLOGY', 'VALUE', 'YEAR']) @@ -38,47 +41,36 @@ def set_user_defined_capacity_trn(tech_capacity_trn, op_life_dict, df_min_cap_inv = pd.concat([df_min_cap_invest, tech_capacity_trn_df]) df_min_cap_inv.drop_duplicates(inplace=True) - max_cap_techs_df = pd.DataFrame(list(itertools.product(list(tech_capacity_trn_df['idx']), - get_years(start_year, end_year)) - ), - columns = ['idx', - 'YEAR'] - ) - - max_cap_techs_df['REGION'], max_cap_techs_df['VALUE'] = region_name, '' - - max_cap_techs_df = pd.merge(max_cap_techs_df, df_min_cap_inv[['TECHNOLOGY', 'idx']], - how='left', - on=['idx']) - - max_cap_techs_df = max_cap_techs_df[['idx', 'REGION', 'TECHNOLOGY', 'YEAR', 'VALUE']] + max_cap_techs_df = pd.DataFrame(columns = ['idx', 'REGION', 'TECHNOLOGY', 'YEAR', 'VALUE']) for idx, tech_params in tech_capacity_trn.items(): - max_cap_techs_df.loc[max_cap_techs_df['idx'] == idx, 'BUILD_YEAR'] = build_year_dict.get(idx) - max_cap_techs_df.loc[max_cap_techs_df['idx'] == idx, 'FIRST_YEAR'] = first_year_expansion_dict.get(idx) - max_cap_techs_df.loc[max_cap_techs_df['idx'] == idx, 'MAX_BUILD'] = build_rate_dict.get(idx) - - max_cap_techs_df.loc[(max_cap_techs_df['YEAR']>=max_cap_techs_df['FIRST_YEAR']), - 'VALUE'] = max_cap_techs_df['MAX_BUILD'] + data = pd.DataFrame(list(itertools.product([tech_capacity_trn_df['idx']], + [region_name], + [tech_params[0]], + get_years(first_year_expansion_dict.get(idx), + final_year_expansion_dict.get(idx)), + [build_rate_dict.get(idx)] + )), + columns = ['idx', 'REGION', 'TECHNOLOGY', 'YEAR', 'VALUE']) - with pd.option_context("future.no_silent_downcasting", True): - max_cap_techs_df['VALUE'] = max_cap_techs_df[ - 'VALUE'].replace(r'^\s*$', 0, regex = True).infer_objects(copy=False) + if max_cap_techs_df.empty: + max_cap_techs_df = data + else: + max_cap_techs_df = pd.concat([max_cap_techs_df, data]).reset_index(drop = True) - max_cap_techs_df = max_cap_techs_df[['REGION', - 'TECHNOLOGY', - 'YEAR', - 'VALUE']] + max_cap_techs_df = max_cap_techs_df[['REGION','TECHNOLOGY','YEAR','VALUE']] + + for tech in max_cap_techs_df['TECHNOLOGY'].unique(): + for year in get_years(start_year, end_year): + if not year in max_cap_techs_df.loc[max_cap_techs_df['TECHNOLOGY'] == + tech]['YEAR'].values: + + max_cap_techs_df.loc[max_cap_techs_df.shape[0]] = region_name, tech, year, 0 # Append existing TotalAnnualMaxCapacityInvestment data with MAX_BUILD - df_max_cap_inv = pd.concat([df_max_cap_invest, max_cap_techs_df]).drop_duplicates() + df_max_cap_inv = pd.concat([df_max_cap_invest, max_cap_techs_df]) - # Print TotalAnnualMaxCapacityInvestment.csv with MAX_BUILD - df_max_cap_inv.drop_duplicates(subset=['REGION', - 'TECHNOLOGY', - 'YEAR'], - keep='last', - inplace=True) + df_max_cap_inv.drop_duplicates(subset=['REGION', 'TECHNOLOGY','YEAR'], keep='last', inplace=True) # For technologies with start year before model start year, add to ResidualCapacity df_res_cap_ud = df_min_cap_inv.copy().loc[df_min_cap_inv.copy()['YEAR'] < min(get_years(start_year, end_year))] @@ -135,6 +127,8 @@ def set_user_defined_capacity_trn(tech_capacity_trn, op_life_dict, (df_max_cap_inv['YEAR'] == row['YEAR']), 'VALUE'] = df_max_cap_inv.loc[( df_max_cap_inv['TECHNOLOGY'] == row['TECHNOLOGY']) & (df_max_cap_inv['YEAR'] == row['YEAR']), 'VALUE'] + row['VALUE'] + + df_max_cap_inv.to_csv('temp5.csv') # Add IAR and OAR for custom technologies tech_list = list(tech_capacity_trn_df['TECHNOLOGY'].unique())