Skip to content

Commit

Permalink
backstop templated
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed Dec 4, 2024
1 parent e136e1a commit 76ca448
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 5 deletions.
59 changes: 59 additions & 0 deletions workflow/scripts/osemosys_global/powerplant/backstop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Sets backstop parameters"""

import pandas as pd


def get_backstop_data(
tech_set: pd.DataFrame, year_set: pd.DataFrame, region: str
) -> tuple[pd.DataFrame]:
"""Gets the following backstop data
- Technologies
- OAR
- Capital Cost
- Fixed Cost
"""

df = tech_set.copy()

# technologies
techs = df[df.VALUE.str.startswith("PWR")].copy() # pwrtrn not added yet
techs["VALUE"] = "BCK" + df.VALUE.str[-7:-2]
techs = techs.drop_duplicates()
bck_techs = techs.VALUE.to_list()

# activity ratios
years = year_set.VALUE.to_list()
oar = pd.DataFrame(
index=pd.MultiIndex.from_product(
[bck_techs, years], names=["TECHNOLOGY", "YEAR"]
)
).reset_index()
oar["REGION"] = region
oar["FUEL"] = oar.TECHNOLOGY.str.replace("BCK", "ELEC")
oar["FUEL"] = oar.FUEL + "02"
oar["MODE_OF_OPERATION"] = 1
oar["VALUE"] = 1
oar = oar[["REGION", "TECHNOLOGY", "FUEL", "MODE_OF_OPERATION", "YEAR", "VALUE"]]

# capital cost
capex = pd.DataFrame(
index=pd.MultiIndex.from_product(
[bck_techs, years], names=["TECHNOLOGY", "YEAR"]
)
).reset_index()
capex["REGION"] = region
capex["VALUE"] = 999999
capex = capex[["REGION", "TECHNOLOGY", "YEAR", "VALUE"]]

# fixed costs
opex = pd.DataFrame(
index=pd.MultiIndex.from_product(
[bck_techs, years], names=["TECHNOLOGY", "YEAR"]
)
).reset_index()
opex["REGION"] = region
opex["VALUE"] = 999999
opex = opex[["REGION", "TECHNOLOGY", "YEAR", "VALUE"]]

return techs, oar, capex, opex
11 changes: 10 additions & 1 deletion workflow/scripts/osemosys_global/powerplant/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@

from calibration import apply_calibration

from backstop import get_backstop_data

def main(
plexos_prop: pd.DataFrame,
plexos_memb: pd.DataFrame,
Expand Down Expand Up @@ -238,6 +240,13 @@ def main(
df_res_cap,
region_name)

# add backstop technologies
bck_techs, bck_oar, bck_capex, bck_opex = get_backstop_data(tech_set, years_set, region_name)
tech_set = pd.concat([tech_set, bck_techs])
df_oar_final = pd.concat([df_oar_final, bck_oar])
df_cap_cost_final = pd.concat([df_cap_cost_final, bck_capex])
df_fix_cost_final = pd.concat([df_fix_cost_final, bck_opex])

# OUTPUT CSV's USED AS INPUT FOR TRANSMISSION RULE

df_res_cap.to_csv(os.path.join(powerplant_data_dir, "ResidualCapacity.csv"), index=None)
Expand Down Expand Up @@ -352,7 +361,7 @@ def main(
fossil_capacity_targets = [["BTNXX", 'COA', 2030, 2050, 'ABS', 1],
["INDNE", 'CCG', 2040, 2050, 'MIN', 10],
["INDSO", 'OCG', 2025, 2050, 'MAX', 25]]
min_generation_factors = {'OCG1': [50, "IND", 2021]}
calibration = {'OCG1': [50, "IND", 2021]}
output_data_dir = 'results/data'
input_data_dir = 'resources/data'
powerplant_data_dir = 'results/data/powerplant'
Expand Down
33 changes: 29 additions & 4 deletions workflow/scripts/osemosys_global/powerplant/variable_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,26 @@ def _get_country_nodes_mapper(nodes: list[str]) -> dict[str, list[str]]:
return df.set_index(["REGION", "TECHNOLOGY", "MODE_OF_OPERATION", "YEAR"])


def get_backstop_var_costs(
techs: pd.Series, years: pd.Series, regions: pd.Series
) -> pd.Series:
"""Gets backstop variable costs"""

t = techs[techs.str.startswith("BCK")].unique().tolist()
y = years.unique().tolist()
r = regions.unique().tolist()[0] # only one region

df = pd.DataFrame(
index=pd.MultiIndex.from_product(
[[r], t, y], names=["REGION", "TECHNOLOGY", "YEAR"]
)
).reset_index()
df["MODE_OF_OPERATION"] = 1
df["VALUE"] = 999999

return df.set_index(["REGION", "TECHNOLOGY", "MODE_OF_OPERATION", "YEAR"])


def main(
cmo_forecasts: pd.DataFrame,
cmo_data_year: int,
Expand Down Expand Up @@ -403,6 +423,11 @@ def main(
var_costs = pd.concat([mining_data, renewable_data])
var_costs = var_costs[var_costs.index.get_level_values("YEAR").isin(y)]
var_costs = filter_var_cost_technologies(var_costs, technologies)

bck_var_costs = get_backstop_var_costs(technologies, years, regions)

var_costs = pd.concat([var_costs, bck_var_costs])

return var_costs.round(3)


Expand All @@ -418,10 +443,10 @@ def main(
else:
file_cmo_forecasts = "resources/data/CMO-October-2024-Forecasts.xlsx"
file_fuel_prices = "resources/data/fuel_prices.csv"
file_regions = "results/India/data/REGION.csv"
file_years = "results/India/data/YEAR.csv"
file_technologies = "results/India/data/TECHNOLOGY.csv"
file_var_costs = "results/India/data/VariableCosts.csv"
file_regions = "results/data/REGION.csv"
file_years = "results/data/YEAR.csv"
file_technologies = "results/data/powerplant/TECHNOLOGY.csv"
file_var_costs = "results/data/powerplant/VariableCosts.csv"

cmo_forecasts = import_cmo_forecasts(file_cmo_forecasts)
user_fuel_prices = import_fuel_prices(file_fuel_prices)
Expand Down

0 comments on commit 76ca448

Please sign in to comment.