Skip to content

Commit

Permalink
Merge pull request #184 from agoenergy/175-improve-help-texts
Browse files Browse the repository at this point in the history
improve help texts and input data representation
  • Loading branch information
markushal authored Dec 13, 2023
2 parents 9b3ed09 + 4b64353 commit dd2b2ae
Show file tree
Hide file tree
Showing 35 changed files with 368 additions and 302 deletions.
100 changes: 64 additions & 36 deletions app/ptxboa_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def get_data_type_from_input_data(
"CAPEX",
"full load hours",
"interest rate",
"specific_costs",
],
scope: Literal[None, "world", "Argentina", "Morocco", "South Africa"],
) -> pd.DataFrame:
Expand All @@ -234,7 +235,8 @@ def get_data_type_from_input_data(
data_type : str
the data type which should be selected. Needs to be one of
"electricity_generation", "conversion_processes", "transportation_processes",
"reconversion_processes", "CAPEX", "full load hours", and "interest rate".
"reconversion_processes", "CAPEX", "full load hours", "interest rate",
and "specific costs".
scope : Literal[None, "world", "Argentina", "Morocco", "South Africa"]
The regional scope. Is automatically set to None for data of
data type "conversion_processes" and "transportation_processes" which is not
Expand All @@ -261,6 +263,15 @@ def get_data_type_from_input_data(
columns = "parameter_code"
processes = api.get_dimension("process")

if data_type == "specific_costs":
scope = None
source_region_code = [""]
index = "flow_code"
columns = "parameter_code"
processes = [""]
parameter_code = ["specific costs"]
process_code = [""]

if data_type == "electricity_generation":
parameter_code = [
"CAPEX",
Expand Down Expand Up @@ -419,6 +430,7 @@ def display_user_changes(api):
"source_region_code": "Source Region",
"process_code": "Process",
"parameter_code": "Parameter",
"flow_code": "Carrier/Material",
"value": "Value",
}
).style.format(precision=3),
Expand Down Expand Up @@ -456,7 +468,8 @@ def register_user_changes(
res = pd.DataFrame(data_list)

# add missing key (the info that is not contained in the 2D table):
res[missing_index_name] = missing_index_value
if missing_index_name is not None or missing_index_value is not None:
res[missing_index_name] = missing_index_value

# Replace the 'id' values with the corresponding index elements from df_tab
res[index] = res[index].map(lambda x: df_tab.index[x])
Expand All @@ -467,6 +480,7 @@ def register_user_changes(
"source_region_code",
"process_code",
"parameter_code",
"flow_code",
"value",
]
)
Expand All @@ -475,7 +489,13 @@ def register_user_changes(
st.session_state["user_changes_df"] = pd.concat(
[st.session_state["user_changes_df"], res]
).drop_duplicates(
subset=["source_region_code", "process_code", "parameter_code"], keep="last"
subset=[
"source_region_code",
"process_code",
"parameter_code",
"flow_code",
],
keep="last",
)


Expand All @@ -499,6 +519,7 @@ def display_and_edit_input_data(
"reconversion_processes" "CAPEX",
"full load hours",
"interest rate",
"specific_costs",
],
scope: Literal["world", "Argentina", "Morocco", "South Africa"],
key: str,
Expand All @@ -516,7 +537,8 @@ def display_and_edit_input_data(
data_type : str
the data type which should be selected. Needs to be one of
"electricity_generation", "conversion_processes", "transportation_processes",
"reconversion_processes", "CAPEX", "full load hours", and "interest rate".
"reconversion_processes", "CAPEX", "full load hours", "interest rate",
and "specific costs".
scope : Literal[None, "world", "Argentina", "Morocco", "South Africa"]
The regional scope. Is automatically set to None for data of
data type "conversion_processes" and "transportation_processes" which is not
Expand All @@ -540,38 +562,7 @@ def display_and_edit_input_data(
columns = "parameter_code"
missing_index_name = "source_region_code"
missing_index_value = None
column_config = None

if data_type in [
"electricity_generation",
"conversion_processes",
"reconversion_processes",
]:
column_config = {
"CAPEX": st.column_config.NumberColumn(format="%.0f USD/kW", min_value=0),
"OPEX (fix)": st.column_config.NumberColumn(
format="%.0f USD/kW", min_value=0
),
"efficiency": st.column_config.NumberColumn(
format="%.2f", min_value=0, max_value=1
),
"lifetime / amortization period": st.column_config.NumberColumn(
format="%.0f a", min_value=0
),
}

if data_type == "transportation_processes":
column_config = {
"levelized costs": st.column_config.NumberColumn(
format="%.2e USD/(kW km)", min_value=0
),
"lifetime / amortization period": st.column_config.NumberColumn(
format="%.0f a", min_value=0
),
"losses (own fuel, transport)": st.column_config.NumberColumn(
format="%.2e fraction per km", min_value=0
),
}
column_config = get_column_config()

if data_type == "interest rate":
index = "source_region_code"
Expand Down Expand Up @@ -605,6 +596,13 @@ def display_and_edit_input_data(
for c in df.columns
}

if data_type == "specific_costs":
index = "flow_code"
columns = "parameter_code"
missing_index_name = None
missing_index_value = None
column_config = get_column_config()

# if editing is enabled, store modifications in session_state:
if st.session_state["edit_input_data"]:
with st.form(key=f"{key}_form"):
Expand Down Expand Up @@ -681,3 +679,33 @@ def get_region_from_subregion(subregion: str) -> str:
"""
region = subregion.split(" (")[0]
return region


def get_column_config() -> dict:
"""Define column configuration for dataframe display."""
column_config = {
"CAPEX": st.column_config.NumberColumn(format="%.0f USD/kW", min_value=0),
"OPEX (fix)": st.column_config.NumberColumn(format="%.0f USD/kW", min_value=0),
"efficiency": st.column_config.NumberColumn(
format="%.2f", min_value=0, max_value=1
),
"lifetime / amortization period": st.column_config.NumberColumn(
format="%.0f a",
min_value=0,
help=read_markdown_file("md/helptext_columns_lifetime.md"),
),
"levelized costs": st.column_config.NumberColumn(
format="%.2e USD/(kW km)", min_value=0
),
"losses (own fuel, transport)": st.column_config.NumberColumn(
format="%.2e fraction per km",
min_value=0,
help=read_markdown_file("md/helptext_columns_losses.md"),
),
"specific costs": st.column_config.NumberColumn(
format="%.3f [various units]",
min_value=0,
help=read_markdown_file("md/helptext_columns_specific_costs.md"),
),
}
return column_config
57 changes: 16 additions & 41 deletions app/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Sidebar creation."""
import streamlit as st

from app.ptxboa_functions import reset_user_changes
from app.ptxboa_functions import read_markdown_file, reset_user_changes
from ptxboa.api import PtxboaAPI


Expand All @@ -22,32 +22,20 @@ def make_sidebar(api: PtxboaAPI):
st.session_state["region"] = st.sidebar.selectbox(
"Supply country / region:",
region_list,
help=(
"One supply country or region can be selected here, "
" and detailed settings can be selected for this region below "
"(RE source, mode of transportation). For other regions, "
"default settings will be used."
),
help=(read_markdown_file("md/helptext_sidebar_supply_region.md")),
index=region_list.get_loc("Morocco"), # Morocco as default
)
st.sidebar.toggle(
"Include subregions",
help=(
"For three deep-dive countries (Argentina, Morocco, and South Africa) "
"the app calculates costs for subregions as well. Activate this switch"
"if you want to chose one of these subregions as a supply region. "
),
help=(read_markdown_file("md/helptext_sidebar_include_subregions.md")),
key="include_subregions",
)

countries = api.get_dimension("country").index
st.session_state["country"] = st.sidebar.selectbox(
"Demand country:",
countries,
help=(
"The country you aim to export to. Some key info on the demand country you "
"choose here are displayed in the info box."
),
help=read_markdown_file("md/helptext_sidebar_demand_country.md"),
index=countries.get_loc("Germany"),
)
# get chain as combination of product, electrolyzer type and reconversion option:
Expand All @@ -64,7 +52,7 @@ def make_sidebar(api: PtxboaAPI):
"Methanol",
"Ft e-fuels",
],
help="The product you want to export.",
help=read_markdown_file("md/helptext_sidebar_product.md"),
index=4, # Methane as default
)
with c2:
Expand All @@ -75,15 +63,14 @@ def make_sidebar(api: PtxboaAPI):
"PEM",
"SEOC",
],
help="The electrolyzer type you wish to use.",
help=read_markdown_file("md/helptext_sidebar_electrolyzer_type.md"),
index=0, # AEL as default
)
if product in ["Ammonia", "Methane"]:
use_reconversion = st.sidebar.toggle(
"Include reconversion to H2",
help=(
"If activated, account for costs of "
"reconverting product to H2 in demand country."
read_markdown_file("md/helptext_sidebar_include_reconversion_to_h2.md")
),
)
else:
Expand All @@ -96,11 +83,7 @@ def make_sidebar(api: PtxboaAPI):
st.session_state["res_gen"] = st.sidebar.selectbox(
"Renewable electricity source (for selected supply region):",
api.get_dimension("res_gen").index,
help=(
"The source of electricity for the selected source country. For all "
"other countries Wind-PV hybrid systems will be used (an optimized mixture "
"of PV and wind onshore plants)"
),
help=read_markdown_file("md/helptext_sidebar_re_source.md"),
)

# get scenario as combination of year and cost assumption:
Expand All @@ -110,21 +93,15 @@ def make_sidebar(api: PtxboaAPI):
"Data year:",
[2030, 2040],
index=1,
help=(
"To cover parameter uncertainty and development over time, we provide "
"cost reduction pathways (high / medium / low) for 2030 and 2040."
),
help=read_markdown_file("md/helptext_sidebar_data-year.md"),
horizontal=True,
)
with c2:
cost_scenario = st.radio(
"Cost assumptions:",
["high", "medium", "low"],
index=1,
help=(
"To cover parameter uncertainty and development over time, we provide "
"cost reduction pathways (high / medium / low) for 2030 and 2040."
),
help=read_markdown_file("md/helptext_sidebar_cost_assumptions.md"),
horizontal=True,
)
st.session_state["scenario"] = f"{data_year} ({cost_scenario})"
Expand All @@ -134,25 +111,25 @@ def make_sidebar(api: PtxboaAPI):
"Carbon source:",
api.get_dimension("secproc_co2").index,
horizontal=True,
help="Help text",
help=read_markdown_file("md/helptext_sidebar_carbon_source.md"),
)
st.session_state["secproc_water"] = st.sidebar.radio(
"Water source:",
api.get_dimension("secproc_water").index,
horizontal=True,
help="Help text",
help=read_markdown_file("md/helptext_sidebar_water_source.md"),
)
st.session_state["transport"] = st.sidebar.radio(
"Mode of transportation (for selected supply country):",
["Ship", "Pipeline"],
horizontal=True,
help="Help text",
help=read_markdown_file("md/helptext_sidebar_transport.md"),
index=1, # 'Pipeline' as default
)
if st.session_state["transport"] == "Ship":
st.session_state["ship_own_fuel"] = st.sidebar.toggle(
"For shipping option: Use the product as own fuel?",
help="Help text",
help=read_markdown_file("md/helptext_sidebar_transport_use_own_fuel.md"),
)
else:
st.session_state["ship_own_fuel"] = False
Expand All @@ -161,15 +138,13 @@ def make_sidebar(api: PtxboaAPI):
"Unit for delivered costs:",
["USD/MWh", "USD/t"],
horizontal=True,
help="Help text",
help=read_markdown_file("md/helptext_sidebar_cost_unit.md"),
index=1, # 'USD/t' as default
)
st.sidebar.divider()
st.sidebar.toggle(
"Edit input data",
help="""Activate this to enable editing of input data.
Disable this setting to reset user data to default values.""",
help=read_markdown_file("md/helptext_sidebar_edit_input_data.md"),
value=False,
key="edit_input_data",
on_change=reset_user_changes,
Expand Down
21 changes: 13 additions & 8 deletions app/tab_input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,40 @@ def content_input_data(api: PtxboaAPI) -> None:

with st.container(border=True):
st.subheader("Global data")
st.markdown("**Electricity generation:**")
with st.expander("**Data**"):
with st.expander("**Electricity generation**"):
display_and_edit_input_data(
api,
data_type="electricity_generation",
scope=None,
key="input_data_editor_electricity_generation",
)
st.markdown("**Electrolysis and derivate production:**")
with st.expander("**Data**"):
with st.expander("**Electrolysis and derivate production**"):
display_and_edit_input_data(
api,
data_type="conversion_processes",
scope=None,
key="input_data_editor_conversion_processes",
)
st.markdown("**Transportation (ships and pipelines):**")
with st.expander("**Data**"):
with st.expander("**Transportation (ships and pipelines)**"):
display_and_edit_input_data(
api,
data_type="transportation_processes",
scope=None,
key="input_data_editor_transportation_processes",
)
st.markdown("**Transportation (compression, liquefication and reconversion):**")
with st.expander("**Data**"):
with st.expander(
"**Transportation (compression, liquefication and reconversion)**"
):
display_and_edit_input_data(
api,
data_type="reconversion_processes",
scope=None,
key="input_data_editor_reconversion_processes",
)
with st.expander("**Specific costs for materials and energy carriers**"):
display_and_edit_input_data(
api,
data_type="specific_costs",
scope=None,
key="input_data_editor_specific_costs",
)
Loading

0 comments on commit dd2b2ae

Please sign in to comment.