Skip to content

Commit

Permalink
Merge pull request #359 from agoenergy/dynamic-res-dropdown-options
Browse files Browse the repository at this point in the history
Dynamic res dropdown options
  • Loading branch information
wingechr authored May 14, 2024
2 parents 4551def + b6cd60a commit b733368
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ def make_sidebar(api: PtxboaAPI):
if use_reconversion:
st.session_state["chain"] = f"{st.session_state['chain']} + reconv. to H2"

available_res_gen = api.get_res_technologies(st.session_state["region"])
st.session_state["res_gen"] = st.sidebar.selectbox(
"Renewable electricity source (for selected supply region):",
api.get_dimension("res_gen").index,
available_res_gen,
index=available_res_gen.index("PV tilted"),
help=read_markdown_file("md/helptext_sidebar_re_source.md"),
)

Expand Down
37 changes: 36 additions & 1 deletion ptxboa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@


from pathlib import Path
from typing import Tuple
from typing import List, Tuple

import pandas as pd
import pypsa

from ptxboa import logger

from . import PROFILES_DIR
from .api_calc import PtxCalc
from .api_data import DataHandler
from .api_optimize import PtxOpt
from .static import (
ChainNameType,
DimensionType,
Expand Down Expand Up @@ -291,3 +293,36 @@ def get_flh_opt_network(
filepath = data_handler.optimizer._get_cache_filepath(hashsum=hashsum)
network = data_handler.optimizer._load_network(filepath=filepath)
return network

def get_res_technologies(
self, region_name: SourceRegionNameType
) -> List[ResGenType]:
"""List all available RES technologies for a source region.
Parameters
----------
region_name: SourceRegionNameType
Returns
-------
: List[ResGenType]
"""
optimizer = PtxOpt(profiles_path=PROFILES_DIR, cache_dir=None)

# translate name -> code
region_code = DataHandler.get_dimensions_parameter_code("region", region_name)

# get all keys from profiles
reg_res = set(optimizer.profiles_hashes.data.keys())
# filter keys for selected source_region
res_techs = pd.Series([res for reg, res in reg_res if reg == region_code])

# translate code -> name
res_gen = self.get_dimension("res_gen")
res_gen_code_to_name = pd.Series(
res_gen["process_name"].to_list(),
index=res_gen["process_code"],
)
res_techs = res_techs.map(res_gen_code_to_name).to_list()
return res_techs

0 comments on commit b733368

Please sign in to comment.