Skip to content

Commit

Permalink
Updates to avoid future depreciation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbrinkerink committed Sep 24, 2024
1 parent 6268d45 commit ce91ebf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
4 changes: 3 additions & 1 deletion workflow/scripts/osemosys_global/powerplant/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def activity_output_pwr(df_ratios, thermal_fuel_list_oar):
df_oar = df_ratios.copy()
mask = df_oar['TECHNOLOGY'].apply(lambda x: x[3:6] in thermal_fuel_list_oar)
df_oar['FUEL'] = 0
df_oar['FUEL'][mask] = 1
df_oar.loc[mask, "FUEL"] = 1

df_oar = df_oar.loc[~((df_oar['MODE_OF_OPERATION'] > 1) &
(df_oar['FUEL'] == 0))]
df_oar['FUEL'] = ('ELC' +
Expand Down Expand Up @@ -88,6 +89,7 @@ def activity_input_pwr(df_oar, thermal_fuel_list_iar, renewables_list,
df_iar = df_oar.copy()

df_iar['FUEL'] = 0
df_iar['FUEL'] = df_iar['FUEL'].astype(str)

# Deal with GAS techs first... OCG and CCG
# OCG Mode 1: Domestic GAS
Expand Down
19 changes: 12 additions & 7 deletions workflow/scripts/osemosys_global/powerplant/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def costs_end(df_weo_regions, df_costs, df_oar_final, df_trans_capex,

# Create formatted CSVs
for each_cost in ['Capital', 'O&M']:
df_costs_temp = df_costs.loc[df_costs['parameter'].str.contains(each_cost)]
df_costs_temp = df_costs.copy().loc[df_costs.copy()['parameter'].str.contains(each_cost)]

df_costs_temp.drop(['technology', 'parameter'],
axis = 1,
Expand All @@ -72,7 +72,8 @@ def costs_end(df_weo_regions, df_costs, df_oar_final, df_trans_capex,
'TECHNOLOGY',
'YEAR'
]]
df_costs_final['YEAR'] = df_costs_final['YEAR'].astype(int)
df_costs_final.loc[:,'YEAR'] = df_costs_final['YEAR'].astype(int)

df_costs_final = df_costs_final.drop_duplicates()
df_costs_final = (df_costs_final
.loc[(df_costs_final['TECHNOLOGY']
Expand All @@ -96,17 +97,21 @@ def costs_end(df_weo_regions, df_costs, df_oar_final, df_trans_capex,
df_costs_final.drop(['technology_code', 'weo_region'],
axis = 1,
inplace = True)
df_costs_final = df_costs_final.fillna(-9)
df_costs_final = df_costs_final.infer_objects().fillna(-9)
df_costs_final = pd.pivot_table(df_costs_final,
index = ['REGION', 'YEAR'],
columns = 'TECHNOLOGY',
values = 'value').reset_index()
df_costs_final = df_costs_final.replace([-9],[np.nan])

df_costs_final = df_costs_final.interpolate(method = 'linear',
limit_direction='forward').round(2)
df_costs_final = df_costs_final.interpolate(method = 'linear',
limit_direction='backward').round(2)
for col in df_costs_final.columns:
if df_costs_final[col].dtype != 'object':
df_costs_final[col] = df_costs_final[col].interpolate(method = 'linear',
limit_direction='forward').round(2)

df_costs_final[col] = df_costs_final[col].interpolate(method = 'linear',
limit_direction='backward').round(2)

df_costs_final = pd.melt(df_costs_final,
id_vars = ['REGION', 'YEAR'],
value_vars = [x for x in df_costs_final.columns
Expand Down
9 changes: 5 additions & 4 deletions workflow/scripts/osemosys_global/powerplant/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Functions to extract relevent data"""

import pandas as pd
import numpy as np
from datetime import datetime
import itertools
import logging
Expand Down Expand Up @@ -30,7 +29,7 @@ def set_generator_table(plexos_prop: pd.DataFrame, plexos_memb: pd.DataFrame,
index="powerplant",
columns="property",
values="value",
aggfunc=np.sum,
aggfunc='sum',
fill_value=0,
)
df_gen["total_capacity"] = (df_gen["Max Capacity"].astype(float)) * (
Expand Down Expand Up @@ -59,9 +58,10 @@ def set_generator_table(plexos_prop: pd.DataFrame, plexos_memb: pd.DataFrame,
)

## Extract start year from Commission Date
df_gen_base["Commission Date"] = (pd.TimedeltaIndex(df_gen_base["Commission Date"].astype(int),
df_gen_base["Commission Date"] = (pd.to_timedelta(df_gen_base["Commission Date"].astype(int),
unit='d') +
datetime(1900, 1, 1))

df_gen_base["start_year"] = df_gen_base["Commission Date"].dt.year
df_gen_base.drop("Commission Date", axis=1, inplace=True)

Expand Down Expand Up @@ -329,5 +329,6 @@ def newIar(df_in, tech, new_iar_ccg,
else:
logging.warning(f'Default IAR used for new {tech} power plants')
iar = new_iar_default
df_out['VALUE'] = round(1/iar, 3)
df_out.loc[:,'VALUE'] = round(1/iar, 3)

return df_out
10 changes: 5 additions & 5 deletions workflow/scripts/osemosys_global/powerplant/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def main(
# return generator_table
gen_table = set_generator_table(plexos_prop, plexos_memb,
op_life_dict, tech_code_dict)

# Calculate average technology efficiencies.
df_eff_node, df_eff_tech = average_efficiency(gen_table, avg_csp_eff,
avg_urn_eff)

# Calculate residual capacity.
df_res_cap, custom_techs = res_capacity(gen_table, tech_list, tech_code,
custom_res_cap, duplicate_techs)

df_ratios = activity_master_start(gen_table, nodes_extra_list,
duplicate_techs, mode_list)

Expand All @@ -123,7 +123,7 @@ def main(

df_oar_upstream, df_oar_int = activity_upstream(df_iar_base, renewables_list,
thermal_fuel_list_mining)

df_iar_trn, df_oar_trn, df_int_trn_oar, df_int_trn_iar = activity_transmission(df_oar_base,
plexos_prop,
interface_data)
Expand All @@ -142,7 +142,7 @@ def main(
df_capact_final = capact(df_oar_final)

df_crossborder_final = activity_transmission_limit(cross_border_trade, df_oar_final)

df_op_life_trn, df_op_life_out = set_op_life(tech_code_dict, df_iar_final,
df_oar_final, op_life_dict)

Expand Down Expand Up @@ -191,7 +191,7 @@ def main(
)

df_af_final = availability_factor(availability, tech_set)

# OUTPUT CSV's

df_res_cap.to_csv(os.path.join(output_data_dir, "ResidualCapacity.csv"), index=None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ def res_capacity(df_gen_base, tech_list, df_tech_code, df_custom_res_cap, duplic
]

df_res_cap = df_gen_base[res_cap_cols]

for each_year in range(start_year, end_year+1):
df_res_cap[str(each_year)] = 0

df_res_cap = df_res_cap.reindex(columns=[*df_res_cap.columns.tolist(), *list(range(start_year, end_year+1))], fill_value=0)

df_res_cap = pd.melt(
df_res_cap,
Expand All @@ -38,7 +37,10 @@ def res_capacity(df_gen_base, tech_list, df_tech_code, df_custom_res_cap, duplic
var_name="model_year",
value_name="value",
)

df_res_cap["model_year"] = df_res_cap["model_year"].astype(int)
df_res_cap["value"] = df_res_cap["value"].astype(float)

df_res_cap.loc[
(df_res_cap["model_year"] >= df_res_cap["start_year"])
& (df_res_cap["model_year"] <= df_res_cap["retirement_year_model"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def set_user_defined_capacity(tech_capacity, op_life_dict, df_tech_set,
df.loc[(df['YEAR']>=df['FIRST_YEAR']) &
(df['YEAR']>df['BUILD_YEAR']),
'VALUE'] = df['MAX_BUILD']
df.fillna(0,
df.infer_objects().fillna(0,
inplace=True)
max_cap_techs_df = df[['REGION',
'TECHNOLOGY',
Expand All @@ -93,7 +93,7 @@ def set_user_defined_capacity(tech_capacity, op_life_dict, df_tech_set,
inplace=True)

# For technologies with start year before model start year, add to ResidualCapacity
df_res_cap_ud = df_min_cap_inv.loc[df_min_cap_inv['YEAR'] < min(years)]
df_res_cap_ud = df_min_cap_inv.copy().loc[df_min_cap_inv.copy()['YEAR'] < min(years)]
df_res_cap_ud.rename(columns={'YEAR':'START_YEAR'},
inplace=True)
df_res_cap_ud_final = pd.DataFrame(list(itertools.product(df_res_cap_ud['TECHNOLOGY'].unique(),
Expand Down Expand Up @@ -122,7 +122,9 @@ def set_user_defined_capacity(tech_capacity, op_life_dict, df_tech_set,
'YEAR',
'VALUE']]

df_res_cap = pd.concat([df_res_cap, df_res_cap_ud_final])

df_res_cap = pd.concat([df_res_cap, df_res_cap_ud_final
if not df_res_cap_ud_final.empty else None])

# For technologies with start year at or after model start year, add to
# TotalAnnualMinCapacityInvestment
Expand Down

0 comments on commit ce91ebf

Please sign in to comment.