Skip to content

Commit

Permalink
added global level costs
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbrinkerink committed Dec 11, 2024
1 parent 1970942 commit e9fe0d6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
4 changes: 4 additions & 0 deletions workflow/rules/postprocess.smk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ RESULT_SUMMARIES = [
"TotalCostNode",
"PowerCostCountry",
"TotalCostCountry",
"PowerCostGlobal",
"TotalCostGlobal",
"Metrics"
]

Expand Down Expand Up @@ -128,8 +130,10 @@ rule calculate_costs:
output:
node_pwr_cost = "results/{scenario}/result_summaries/PowerCostNode.csv",
country_pwr_cost = "results/{scenario}/result_summaries/PowerCostCountry.csv",
global_pwr_cost = "results/{scenario}/result_summaries/PowerCostGlobal.csv",
node_cost = "results/{scenario}/result_summaries/TotalCostNode.csv",
country_cost = "results/{scenario}/result_summaries/TotalCostCountry.csv",
global_cost = "results/{scenario}/result_summaries/TotalCostGlobal.csv",
log:
log = 'results/{scenario}/logs/node_cost.log'
script:
Expand Down
41 changes: 30 additions & 11 deletions workflow/scripts/osemosys_global/summary/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,22 @@ def get_pwr_cost(demand: pd.DataFrame, cost: pd.DataFrame) -> pd.DataFrame:
demand_csv = snakemake.input.demand
power_cost_node_csv = snakemake.output.node_pwr_cost
power_cost_country_csv = snakemake.output.country_pwr_cost
power_cost_global_csv = snakemake.output.global_pwr_cost
total_cost_node_csv = snakemake.output.node_cost
total_cost_country_csv = snakemake.output.country_cost
total_cost_global_csv = snakemake.output.global_cost

else:
discounted_cost_by_technology_csv = (
"results/India/results/DiscountedCostByTechnology.csv"
)
demand_csv = "results/India/results/Demand.csv"
power_cost_node_csv = "results/India/result_summaries/NodePowerCost.csv"
power_cost_country_csv = "results/India/result_summaries/CountryPowerCost.csv"
total_cost_node_csv = "results/India/result_summaries/NodeCost.csv"
total_cost_country_csv = "results/India/result_summaries/CountryCost.csv"
power_cost_node_csv = "results/India/result_summaries/PowerCostNode.csv"
power_cost_country_csv = "results/India/result_summaries/PowerCostCountry.csv"
power_cost_global_csv = "results/India/result_summaries/PowerCostGlobal.csv"
total_cost_node_csv = "results/India/result_summaries/TotalCostNode.csv"
total_cost_country_csv = "results/India/result_summaries/TotalCostCountry.csv"
total_cost_global_csv = "results/India/result_summaries/TotalCostGlobal.csv"

discounted_cost_by_technology = pd.read_csv(
discounted_cost_by_technology_csv, index_col=[0, 1, 2]
Expand Down Expand Up @@ -128,11 +133,25 @@ def get_pwr_cost(demand: pd.DataFrame, cost: pd.DataFrame) -> pd.DataFrame:

# country level metrics

tech_cost = get_tech_cost(discounted_cost_by_technology, country=True)
storage_cost = get_storage_cost(discounted_cost_by_storage, country=True)
cost = tech_cost.add(storage_cost, fill_value=0)
demand = get_demand(demand_raw, country=True)
pwr_cost = get_pwr_cost(demand, cost)
tech_cost_country = get_tech_cost(discounted_cost_by_technology, country=True)
storage_cost_country = get_storage_cost(discounted_cost_by_storage, country=True)
cost_country = tech_cost_country.add(storage_cost_country, fill_value=0)
demand_country = get_demand(demand_raw, country=True)
pwr_cost_country = get_pwr_cost(demand_country, cost_country)

pwr_cost_country.to_csv(power_cost_country_csv, index=True)
cost_country.to_csv(total_cost_country_csv, index=True)

# global level metrics

cost_global = tech_cost_country.add(storage_cost_country,
fill_value=0).groupby(["YEAR"]).sum()

demand_global = get_demand(demand_raw, country=True)
demand_global = demand_global.groupby([
demand_global.index.get_level_values("YEAR")]).sum()

pwr_cost_global = get_pwr_cost(demand_global, cost_global)

pwr_cost.to_csv(power_cost_country_csv, index=True)
cost.to_csv(total_cost_country_csv, index=True)
pwr_cost_global.to_csv(power_cost_global_csv, index=True)
cost_global.to_csv(total_cost_global_csv, index=True)

0 comments on commit e9fe0d6

Please sign in to comment.