Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add data sources to input data #385

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/layout_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def display_and_edit_input_data(
-------
pd.DataFrame
"""
df = get_data_type_from_input_data(api, data_type=data_type, scope=scope)
df, sources = get_data_type_from_input_data(api, data_type=data_type, scope=scope)
df_orig = df.copy()

if data_type in [
Expand Down Expand Up @@ -357,7 +357,8 @@ def display_and_edit_input_data(
column_config = get_column_config()

df = change_index_names(df)

if len(sources) > 0:
st.markdown(f"Data sources: {', '.join(sources)}")
# if editing is enabled, store modifications in session_state:
if st.session_state["edit_input_data"]:
if data_type == "full load hours":
Expand Down
2 changes: 1 addition & 1 deletion app/plot_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def plot_input_data_on_map(
-------
go.Figure
"""
input_data = get_data_type_from_input_data(api, data_type=data_type, scope=None)
input_data, _ = get_data_type_from_input_data(api, data_type=data_type, scope=None)

units = {"CAPEX": "USD/kW", "full load hours": "h/a", "interest rate": "%"}

Expand Down
17 changes: 12 additions & 5 deletions app/ptxboa_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,15 @@ def subset_and_pivot_input_data(
if process_code is not None:
input_data = input_data.loc[input_data["process_code"].isin(process_code)]

if "source" in input_data.columns:
sources = {x for x in sorted(input_data["source"].dropna().unique()) if x}
else:
sources = {}

reshaped = input_data.pivot_table(
index=index, columns=columns, values=values, aggfunc="sum"
)
return reshaped
return reshaped, sources


def get_data_type_from_input_data(
Expand Down Expand Up @@ -269,7 +274,7 @@ def get_data_type_from_input_data(
"""
if data_type == "full load hours":
input_data = api.get_optimization_flh_input_data()
df = subset_and_pivot_input_data(
df, _ = subset_and_pivot_input_data(
input_data,
source_region_code=None,
parameter_code=None,
Expand All @@ -284,7 +289,9 @@ def get_data_type_from_input_data(
)
if scope in ["Argentina", "Morocco", "South Africa"]:
df = select_subregions(df, scope)
return df

sources = {"own calculations using atlite, tsam and ERA5"}
return df, sources

input_data = api.get_input_data(
st.session_state["scenario"],
Expand Down Expand Up @@ -395,7 +402,7 @@ def get_data_type_from_input_data(
"PV tilted",
]

df = subset_and_pivot_input_data(
df, sources = subset_and_pivot_input_data(
input_data,
source_region_code=source_region_code,
parameter_code=parameter_code,
Expand All @@ -417,7 +424,7 @@ def get_data_type_from_input_data(
if "efficiency" in df.columns:
df["efficiency"] = df["efficiency"] * 100

return df
return df, sources


def remove_subregions(api: PtxboaAPI, df: pd.DataFrame, country_name: str):
Expand Down
Loading