Skip to content

Commit

Permalink
Merge pull request #411 from agoenergy/subregion_result_in_cost_compa…
Browse files Browse the repository at this point in the history
…rison

include selected subregion in global cost comparison
  • Loading branch information
markushal authored Jun 3, 2024
2 parents 6057b6c + 11f5320 commit 1241a34
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/ptxboa_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ def get_data_type_from_input_data(
return df


def remove_subregions(api: PtxboaAPI, df: pd.DataFrame, country_name: str):
def remove_subregions(
api: PtxboaAPI, df: pd.DataFrame, country_name: str, keep: str | None = None
):
"""Remove subregions from a dataframe.
Parameters
Expand All @@ -453,6 +455,9 @@ def remove_subregions(api: PtxboaAPI, df: pd.DataFrame, country_name: str):
country_name : str
name of target country. Is removed from region list if it is also in there.
keep : str or None, by default None
can be used to keep data for a specific subregion
Returns
-------
pandas DataFrame with subregions removed from index.
Expand All @@ -473,6 +478,9 @@ def remove_subregions(api: PtxboaAPI, df: pd.DataFrame, country_name: str):
r for r in region_list_without_subregions if r in df.index
]

if keep is not None:
region_list_without_subregions.append(keep)

df = df.loc[region_list_without_subregions]

return df
Expand Down
2 changes: 2 additions & 0 deletions app/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def main_settings(api):
index=region_list.get_loc("Morocco"), # Morocco as default
)
st.session_state["region"] = region
st.session_state["subregion"] = None

# If a deep dive country has been selected, add option to select subregion:
if region in ["Argentina", "Morocco", "South Africa"]:
Expand All @@ -64,6 +65,7 @@ def main_settings(api):
)
if subregion is not None:
st.session_state["region"] = subregion
st.session_state["subregion"] = subregion

# select demand country:
countries = api.get_dimension("country").index
Expand Down
8 changes: 7 additions & 1 deletion app/tab_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ def content_costs(

with st.container(border=True):
display_costs(
remove_subregions(api, costs_per_region, st.session_state["country"]),
remove_subregions(
api,
costs_per_region,
st.session_state["country"],
keep=st.session_state["subregion"],
),
(
remove_subregions(
api,
costs_per_region_without_user_changes,
st.session_state["country"],
keep=st.session_state["subregion"],
)
if st.session_state["user_changes_df"] is not None
else None
Expand Down

0 comments on commit 1241a34

Please sign in to comment.