Skip to content

Commit

Permalink
Merge pull request #481 from agoenergy/develop
Browse files Browse the repository at this point in the history
v0.9
  • Loading branch information
wingechr authored Jun 19, 2024
2 parents 6c1be18 + 8fd182d commit 5f33b37
Show file tree
Hide file tree
Showing 22 changed files with 4,432 additions and 4,379 deletions.
4 changes: 3 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.8.2
current_version = 0.9.0
commit = True
tag = True

Expand All @@ -10,3 +10,5 @@ tag = True
[bumpversion:file:.github/workflows/publish.yaml]

[bumpversion:file:README.md]

[bumpversion:file:app/tab_info.py]
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
uses: docker/build-push-action@v5
with:
push: true
tags: wingechr/ptx-boa:0.8.2
tags: wingechr/ptx-boa:0.9.0
2 changes: 1 addition & 1 deletion .streamlit/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
toolbarMode = "minimal"

[logger]
level="DEBUG"
level="INFO"

[browser]
gatherUsageStats = false
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3.10-slim
LABEL version="0.8.2"
LABEL version="0.9.0"

RUN apt-get update
RUN apt-get install -y git
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ scp -r ptxboa2:ptx-boa_offline_optimization/optimization_cache/* .
# connect to server
ssh ptxboa
# pull latest image from dockerhub
VERSION=0.8.2
VERSION=0.9.0
docker pull wingechr/ptx-boa:$VERSION
# stop and delete the currently running container "app"
docker stop app
Expand Down
14 changes: 8 additions & 6 deletions app/layout_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,10 @@ def display_footer():
st.markdown(
"""
##### On behalf of
Agora Energiewende<br/>
Agora Industry<br/>
Anna-Louisa-Karsch-Str. 2<br/>
D-10178 Berlin<br/>
www.agora-industry.org<br/>
www.agora-energiewende.org
www.agora-industry.org
""",
unsafe_allow_html=True,
)
Expand All @@ -192,13 +191,16 @@ def display_footer():
)

# TODO: fix uneven height and vertical alignment of logos
c1, c2, c3, c4 = st.columns(4, gap="medium")
c0, c1, c2, c3, c4, c5 = st.columns(
[1, 2, 2, 2, 2, 1],
gap="large",
)
with c1:
st.image("img/oeko_logo_612x306.png")
st.image("img/Agora_Industry_logo_612x306.png")
with c2:
st.image("img/agora-energiewende_logo_612x306.png")
with c3:
st.image("img/Agora_Industry_logo_612x306.png")
st.image("img/oeko_logo_612x306.png")
with c4:
st.image("img/PtX-Hub_Logo_international_612x306.png")

Expand Down
25 changes: 19 additions & 6 deletions app/plot_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ def add_trace_to_figure(
df_plot = df[(df["Component"] == component)]
df_plot = df_plot[(df_plot["Parameter"] == parameter)]
if fill:
if df_plot["MW (MWh for SOC)"].sum() > 0:
if df_plot["MW"].sum() > 0:
fig.add_trace(
go.Scatter(
x=df_plot["time"],
y=df_plot["MW (MWh for SOC)"],
y=df_plot["MW"],
mode="lines",
name=component,
line_color=color,
Expand All @@ -597,7 +597,7 @@ def add_trace_to_figure(
fig.add_trace(
go.Scatter(
x=df_plot["time"],
y=df_plot["MW (MWh for SOC)"],
y=df_plot["MW"],
mode="lines",
name=component,
line_color=color,
Expand All @@ -612,7 +612,7 @@ def transform_time_series(
res = df.reset_index().melt(
id_vars=["timestep", "period"],
var_name="Component",
value_name="MW (MWh for SOC)",
value_name="MW",
)
res["Parameter"] = parameter
return res
Expand All @@ -623,9 +623,9 @@ def transform_time_series(
df_gen = transform_time_series(df_gen)
df_links = -n.links_t["p1"]
df_links = transform_time_series(df_links)
df_store = n.stores_t["e"]
df_store = n.stores_t["p"]
df_store = transform_time_series(df_store)
df_storageunit = n.storage_units_t["state_of_charge"]
df_storageunit = n.storage_units_t["p"]
df_storageunit = transform_time_series(df_storageunit)

df = pd.concat([df_p_max_pu, df_gen, df_links, df_store, df_storageunit])
Expand Down Expand Up @@ -711,12 +711,24 @@ def create_profile_figure_generation(df_sel: pd.DataFrame) -> go.Figure:
parameter="Power",
color="#408B2E",
)
add_trace_to_figure(
df_sel,
fig,
component="Electricity storage",
parameter="Power",
color="#D05094",
)

add_trace_to_figure(
df_sel, fig, component="H2 storage", parameter="Power", color="#733E88"
)

add_vertical_lines(fig)

fig.update_layout(
xaxis={"title": "time (h)"},
yaxis={"title": "output (MW)"},
legend={"traceorder": "normal"},
)

return fig
Expand Down Expand Up @@ -757,6 +769,7 @@ def create_profile_figure_soc(df_sel: pd.DataFrame) -> go.Figure:
fig.update_layout(
xaxis={"title": "time (h)"},
yaxis={"title": "state of charge (MWh)"},
legend={"traceorder": "normal"},
)

return fig
Expand Down
4 changes: 2 additions & 2 deletions app/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

@st.cache_resource()
def sidebar_logo():
st.image("img/agora-energiewende_logo_612x306.png")
st.image("img/Agora_Industry_logo_612x306.png")


def make_sidebar(api: PtxboaAPI):
st.logo(
image="img/transparent_10x10.png", # placeholder when sidebar is expanded
icon_image="img/agora-energiewende_logo_612x306.png",
icon_image="img/Agora_Industry_logo_612x306.png",
)

with st.sidebar:
Expand Down
15 changes: 15 additions & 0 deletions app/tab_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from app.ptxboa_functions import read_markdown_file

__version__ = "0.8.3"


def content_info():
with st.container(border=True):
Expand Down Expand Up @@ -42,3 +44,16 @@ def content_info():

with st.container(border=True):
st.markdown(read_markdown_file("md/info_disclaimer.md"))
st.markdown(
(
"#### Licensing and quotation\n"
"This tool is licensed under the Creative Commons CC-BY 4.0 license"
" (<https://creativecommons.org/licenses/by/4.0/>).\n\n"
"The use of the methods and results are only authorised"
" in case the tool and its authors are properly cited.\n\n"
"Please cite it as:"
" Oeko-Institut, Agora Industry & Agora Energiewende (2024):"
f" PTX Business Opportunity Analyser {__version__}"
" <https://ptxboa.agora-thinktanks.org/>)"
)
)
Binary file modified img/costs_of_hydrogen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 6 additions & 19 deletions md/info_disclaimer.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
#### Disclaimer

The PTX BOA uses technical reports published by third parties.
The authors of the tool and Agora Energiewende trust but do not guarantee
the accuracy and completeness of the information provided by them.

All rights reserved to Öko-Institut and Agora Energiewende.
The use of the methods and results are only authorised
in case Öko-institut and Agora Energiewende is properly cited.

#### Licensing and quotation

This tool is licensed under the Creative Commons CC-BY-SA license
(<https://creativecommons.org/licenses/by-sa/4.0/>).

Please cite it as: Oeko-Institut, Agora Energiewende & Agora Industry (2023):
PTX Business Opportunity Analyser
<https://ptx-boa.streamlit.app/>

#### Source code and contribution

We strongly welcome anyone interested in contributing to this project.
Expand All @@ -28,3 +9,9 @@ or make a contribution, please check out our Github repository:

Visit our website for data documentation, additional resources and updates:
<https://www.agora-energiewende.de/en/publications/business-opportunity-analyser-boa>

#### Disclaimer

The PTX BOA uses technical reports published by third parties.
The authors of the tool and Agora Energiewende trust but do not guarantee
the accuracy and completeness of the information provided by them.
54 changes: 36 additions & 18 deletions offline_optimization_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ def generate_param_sets(api: PtxboaAPI):

# specify parameter dimensions not relevant for optimization
# we choose arbritray values for those
static_params = {
"transport": "Ship",
"ship_own_fuel": False,
"country": "Germany",
"secproc_water": "Specific costs",
"secproc_co2": "Specific costs",
}
static_params = {"transport": "Ship", "ship_own_fuel": False, "country": "Germany"}

# these are the parameter dimensions that are relevant for the optimization
scenarios = api.get_dimension("scenario").index.tolist()
Expand All @@ -81,14 +75,22 @@ def generate_param_sets(api: PtxboaAPI):
for c in api.get_dimension("chain").index.tolist()
if not c.endswith("+ reconv. to H2")
]
secprocs_water = ["Specific costs", "Sea Water desalination"]
secprocs_co2 = ["Specific costs", "Direct Air Capture"]

param_sets = []
for region in regions:
# only get availabe technologies for this region
res_gens = api.get_res_technologies(region)
param_sets += [
p | static_params | {"region": region}
for p in product_dict(scenario=scenarios, chain=chains, res_gen=res_gens)
for p in product_dict(
scenario=scenarios,
chain=chains,
res_gen=res_gens,
secproc_water=secprocs_water,
secproc_co2=secprocs_co2,
)
]

return param_sets
Expand All @@ -100,13 +102,27 @@ def main(
loglevel: Literal["debug", "info", "warning", "error"] = "info",
index_from: int = None,
index_to: int = None,
count_only: bool = False,
):
cache_dir = Path(cache_dir)
cache_dir.mkdir(exist_ok=True)

out_dir = Path(out_dir) if out_dir else cache_dir
out_dir.mkdir(exist_ok=True)

api = PtxboaAPI(data_dir=DEFAULT_DATA_DIR, cache_dir=cache_dir)

param_sets = generate_param_sets(api)

if count_only:
print(f"Number of parameter variations: {len(param_sets)}")
return

# filter for batch
index_from = index_from or 0
index_to = index_to or len(param_sets)
param_sets = param_sets[index_from:index_to]

# set up logging
fmt = "[%(asctime)s %(levelname)7s] %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
Expand All @@ -115,18 +131,12 @@ def main(
format=fmt,
datefmt=datefmt,
handlers=[
logging.FileHandler(cache_dir / "offline_optimization_script.log"),
logging.FileHandler(
cache_dir / f"offline_optimization_script.{index_from}-{index_to}.log"
),
],
)
logging.info(f"starting offline optimization script with cache_dir: {cache_dir}")
api = PtxboaAPI(data_dir=DEFAULT_DATA_DIR, cache_dir=cache_dir)

param_sets = generate_param_sets(api)

# filter for batch
index_from = index_from or 0
index_to = index_to or len(param_sets)
param_sets = param_sets[index_from:index_to]

results = [] # save results
for params in progress.bar.Bar(
Expand Down Expand Up @@ -154,7 +164,9 @@ def main(

# save result
with open(
out_dir / "offline_optimization.results.json", "w", encoding="utf-8"
out_dir / f"offline_optimization.results.{index_from}-{index_to}.json",
"w",
encoding="utf-8",
) as file:
json.dump(
results,
Expand Down Expand Up @@ -205,6 +217,12 @@ def main(
type=int,
help="final index (exlusive) for prallel runs",
)
parser.add_argument(
"-n",
"--count_only",
action="store_true",
help="only print number of parameter variations and quit.",
)

args = parser.parse_args()
main(**vars(args))
4 changes: 4 additions & 0 deletions ptxboa/api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,16 +809,20 @@ def _get_calculation_data(
chain, transport_distances
)

used_flows = set()
for process_step in chain_steps_main:
process_code = chain[process_step]
res = pg.get_process_params(process_code)
res["step"] = process_step
res["process_code"] = process_code
result["main_process_chain"].append(res)
used_flows = used_flows | set(res["CONV"])

for flow_code, process_code in secondary_processes.items():
if not process_code:
continue
if flow_code not in used_flows:
continue
res = pg.get_process_params(process_code)
res["process_code"] = process_code
result["secondary_process"][flow_code] = res
Expand Down
Loading

0 comments on commit 5f33b37

Please sign in to comment.