Skip to content

Commit

Permalink
Merge pull request #369 from agoenergy/fix-cost-categories
Browse files Browse the repository at this point in the history
remove deprecated storage cost factor
  • Loading branch information
wingechr authored May 14, 2024
2 parents 740135c + 10be233 commit d810485
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 334 deletions.
77 changes: 0 additions & 77 deletions ptxboa/api_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def calculate(data: CalculateDataType) -> pd.DataFrame:
# get general parameters
parameters = data["parameter"]
wacc = parameters["WACC"]
storage_factor = parameters["STR-CF"]

# start main chain calculation
main_output_value = 1 # start with normalized value of 1
Expand All @@ -33,20 +32,6 @@ def calculate(data: CalculateDataType) -> pd.DataFrame:
for step_data in data["main_process_chain"] + data["transport_process_chain"]:
process_step = step_data["step"]
process_code = step_data["process_code"]
is_shipping_or_pre_post = process_step in {
"PRE_SHP",
"SHP",
"SHP-OWN",
"POST_SHP",
}
is_pipeline_or_pre_post = process_step in {
"PRE_PPL",
"PPLS",
"PPL",
"PPLX",
"PPLR",
"POST_PPL",
}
is_transport = process_step in {
"SHP",
"SHP-OWN",
Expand Down Expand Up @@ -76,40 +61,13 @@ def calculate(data: CalculateDataType) -> pd.DataFrame:
results.append((result_process_type, process_code, "CAPEX", capex_ann))
results.append((result_process_type, process_code, "OPEX", opex))

if not (is_shipping_or_pre_post or is_pipeline_or_pre_post):
# no storage factor in transport pre/post
results.append(
(
"Electricity and H2 storage",
process_code,
"OPEX", # NOTE: in old app,storage is always OPEX
capex_ann * storage_factor,
)
)
results.append(
(
"Electricity and H2 storage",
process_code,
"OPEX",
opex * storage_factor,
)
)
else:
opex_t = step_data["OPEX-T"]
dist_transport = step_data["DIST"]
opex_ot = opex_t * dist_transport
opex = (opex_o + opex_ot) * main_output_value
results.append((result_process_type, process_code, "OPEX", opex))

if not (is_shipping_or_pre_post or is_pipeline_or_pre_post):
results.append(
(
"Electricity and H2 storage",
process_code,
"OPEX",
opex * storage_factor,
)
)
# create flows for process step
for flow_code, conv in step_data["CONV"].items():
flow_value = main_output_value * conv
Expand Down Expand Up @@ -140,23 +98,6 @@ def calculate(data: CalculateDataType) -> pd.DataFrame:
results.append(
(sec_result_process_type, sec_process_code, "OPEX", opex)
)
if not (is_shipping_or_pre_post or is_pipeline_or_pre_post):
results.append(
(
"Electricity and H2 storage",
sec_process_code,
"OPEX", # NOTE: in old app, storage is always OPEX
capex_ann * storage_factor,
)
)
results.append(
(
"Electricity and H2 storage",
sec_process_code,
"OPEX",
opex * storage_factor,
)
)

for sec_flow_code, sec_conv in sec_process_data["CONV"].items():
sec_flow_value = flow_value * sec_conv
Expand All @@ -180,15 +121,6 @@ def calculate(data: CalculateDataType) -> pd.DataFrame:
sec_flow_cost,
)
)
if not (is_shipping_or_pre_post or is_pipeline_or_pre_post):
results.append(
(
"Electricity and H2 storage",
sec_process_code,
"OPEX", # NOTE: in old app, storage is always OPEX
sec_flow_cost * storage_factor,
)
)

else:
# use market
Expand All @@ -210,15 +142,6 @@ def calculate(data: CalculateDataType) -> pd.DataFrame:
results.append(
(flow_result_process_type, process_code, "FLOW", flow_cost)
)
if not (is_shipping_or_pre_post or is_pipeline_or_pre_post):
results.append(
(
"Electricity and H2 storage",
process_code,
"OPEX", # NOTE: in old app, storage is always OPEX
flow_cost * storage_factor,
)
)

# convert to DataFrame
dim_columns = ["process_type", "process_subtype", "cost_type"]
Expand Down
16 changes: 0 additions & 16 deletions ptxboa/api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@ def __init__(
"process_flh",
),
)
self.storage_cost_factor = _load_data(
self.data_dir,
name="storage_cost_factor",
key_columns=("process_res", "process_ely", "process_deriv"),
)

scenario_filename = (
f"{scenario.replace(' ', '_').replace(')', '').replace('(', '')}"
Expand Down Expand Up @@ -475,16 +470,6 @@ def _get_parameter_value(
]
required_keys = set(keys)

elif parameter_code == "STR-CF":
# Storage cost factor not changed by user (and currently in separate file)
df = self.storage_cost_factor
keys = [
"process_code_res",
"process_code_ely",
"process_code_deriv",
]
required_keys = set(keys)

else:
df = self.scenario_data
keys = [
Expand Down Expand Up @@ -675,7 +660,6 @@ def get_flow_params():
}

result["parameter"]["WACC"] = get_parameter_value_w_default("WACC")
result["parameter"]["STR-CF"] = get_parameter_value_w_default("STR-CF")
result["parameter"]["CALOR"] = get_parameter_value_w_default(
parameter_code="CALOR", flow_code=chain["FLOW_OUT"]
)
Expand Down
33 changes: 15 additions & 18 deletions ptxboa/data/_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
import sqlalchemy as sa


def update_csv(query: str, filename: str, data_dir: str = None) -> None:
def update_csv(
query: str, filename: str, data_dir: str = None, check_uniue_cols: list = None
) -> None:
data_dir = data_dir or os.path.dirname(__file__)
CS = (
"mssql+pyodbc://?odbc_connect=driver=sql server;server=sqldaek2;database=ptxboa"
)
engine = sa.create_engine(CS)
pd.read_sql(
df = pd.read_sql(
query,
engine,
).to_csv(data_dir + "/" + filename, index=False, lineterminator="\n")
)
if check_uniue_cols:
assert df.set_index(check_uniue_cols).index.is_unique
df.to_csv(data_dir + "/" + filename, index=False, lineterminator="\n")


def main():
Expand All @@ -39,21 +44,6 @@ def main():
""",
"flh.csv",
)
update_csv(
"""
select
"key",
"process_res",
"process_ely",
"process_deriv",
"value",
"source"
FROM "ptxboa_data_storage_factor"
WHERE value is not null
ORDER BY "key"
""",
"storage_cost_factor.csv",
)

for year in [2030, 2040]:
for rng in ["high", "medium", "low"]:
Expand All @@ -77,6 +67,13 @@ def main():
order by "key"
""",
f"{year}_{rng}.csv",
check_uniue_cols=[
"parameter_code",
"process_code",
"flow_code",
"source_region_code",
"target_country_code",
],
)


Expand Down
106 changes: 0 additions & 106 deletions ptxboa/data/storage_cost_factor.csv

This file was deleted.

4 changes: 0 additions & 4 deletions ptxboa/static/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@
"RE-POT",
"SEASHARE",
"SPECCOST",
"STR-CF",
"WACC",
]
ParameterCodeValues = [
Expand All @@ -564,7 +563,6 @@
"RE-POT",
"SEASHARE",
"SPECCOST",
"STR-CF",
"WACC",
]

Expand All @@ -586,7 +584,6 @@
"sea share of pipeline distance",
"shipping distance",
"specific costs",
"Storage cost factor",
"transport capacity",
]
ParameterNameValues = [
Expand All @@ -606,7 +603,6 @@
"sea share of pipeline distance",
"shipping distance",
"specific costs",
"Storage cost factor",
"transport capacity",
]

Expand Down
1 change: 0 additions & 1 deletion ptxboa/static/dim_parameter.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ OPEX-T,levelized costs,USD2021/(kWh*km),False,False,True,False,True,False,False,
RE-POT,RE potential,MWel,False,False,False,True,True,True,False,False,no,no,,process_code/source_region_code
SEASHARE,sea share of pipeline distance,fraction,False,False,False,False,False,True,True,False,no,no,,source_region_code/target_country_code
SPECCOST,specific costs,various (USD2021 per flow),True,False,False,False,False,True,False,True,basic,extended,"Costs are associated with every *secondary* input. It could also be associated with secondary output (<0 for gains, >0 for costs)",flow_code/source_region_code
STR-CF,Storage cost factor,1,False,True,False,True,False,False,False,False,0,0,,
WACC,interest rate,fraction,False,True,False,True,False,True,False,True,,,,source_region_code
Loading

0 comments on commit d810485

Please sign in to comment.