Skip to content
Open
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
4 changes: 2 additions & 2 deletions docs/user_guide/how_to_interface_with_user_defined_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ You can combine an existing H2Integrate model and a custom model for the same te

To demonstrate this capability, we include a minimal example of a custom technology model: a **paper mill**. This example includes:

- A `PaperMillPerformance` model that converts electricity input to paper output.
- A `PaperMillCost` model that estimates capital and operational expenditures.
- A `CustomPaperMillPerformance` model that converts electricity input to paper output.
- A `CustomPaperMillCost` model that estimates capital and operational expenditures.
- A `PaperMillFinance` technology finance model that computes the levelized cost of paper production (LCOP).

Refer to the [Paper Mill Model Example](https://github.com/NatLabRockies/H2Integrate/tree/develop/examples/06_custom_tech/) for a complete walkthrough.
Expand Down
4 changes: 2 additions & 2 deletions examples/06_custom_tech/tech_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ technologies:
cost_year: 2019
paper_mill:
performance_model:
model: PaperMillPerformance
model: CustomPaperMillPerformance
model_location: user_defined_model/paper_mill.py
cost_model:
model: PaperMillCost
model: CustomPaperMillCost
model_location: user_defined_model/paper_mill.py
finance_model:
model: PaperMillFinance
Expand Down
4 changes: 2 additions & 2 deletions examples/06_custom_tech/user_defined_model/paper_mill.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PaperMillConfig(BaseConfig):
electricity_usage_rate: float = field()


class PaperMillPerformance(om.ExplicitComponent):
class CustomPaperMillPerformance(om.ExplicitComponent):
_time_step_bounds = (
3600,
3600,
Expand Down Expand Up @@ -57,7 +57,7 @@ class PaperMillCostConfig(CostModelBaseConfig):
plant_capacity: float = field()


class PaperMillCost(CostModelBaseClass):
class CustomPaperMillCost(CostModelBaseClass):
_time_step_bounds = (
3600,
3600,
Expand Down
6 changes: 6 additions & 0 deletions examples/36_paper_mill/36_paper_mill_mn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: H2Integrate_config
system_summary: This reference paper mill plant is located in Minnesota and for its first pass, it contains paper mill plant
powered by grid. The system is designed to produce paper at a constant rate throughout the year.
driver_config: driver_config.yaml
technology_config: tech_config.yaml
plant_config: plant_config.yaml
185 changes: 185 additions & 0 deletions examples/36_paper_mill/Breakdown_cost_plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# """
# Created on Fri May 15 07:38:06 2026

# @author: mkoleva
# """

# import pandas as pd
# import matplotlib.pyplot as plt

# # Load Excel file
# file_path = "Breakdown_costs_per_scenario.xlsx"
# df = pd.read_excel(file_path, sheet_name="Sheet1", header=None)

# # Scenario labels — edit however you prefer
# scenarios = [
# "Paper + Pulp",
# "SAF with H2",
# "SAF with low-carbon H2",
# "Paper + Pulp\nSAF with H2",
# "Paper + Pulp\nSAF with low-carbon H2"
# ]

# # Extract cost component names
# components = df.iloc[3:, 0].values

# # Build scenario value arrays (sum of appropriate columns)
# records = {}
# records["Paper + Pulp"] = df.iloc[3:, [1, 2, 3]].astype(float).sum(axis=1).values
# records["SAF with H2"] = df.iloc[3:, [3]].astype(float).sum(axis=1).values
# records["SAF with low-carbon H2"] = df.iloc[3:, [4]].astype(float).sum(axis=1).values
# records["Paper + Pulp\nSAF with H2"] = df.iloc[3:, [5, 6, 7]].astype(float).sum(axis=1).values
# results = df.iloc[3:, [8, 9, 10]]
# records["Paper + Pulp\nSAF with low-carbon H2"] = results.astype(float).sum(axis=1).values

# # Build DataFrame
# plot_df = pd.DataFrame(records, index=components)
# plot_df = plot_df[scenarios] # order consistently

# # Assign custom colors
# colors = []
# for comp in plot_df.index:
# if "CapEx" in comp:
# colors.append("navy")
# elif "OpEx" in comp:
# colors.append("orange")
# elif "Feedstock" in comp:
# colors.append("deepskyblue")
# elif "Taxes" in comp:
# colors.append("lightpink")
# elif "Finances" in comp:
# colors.append("yellowgreen")
# else:
# colors.append(None) # Let matplotlib choose default

# # Plotting
# plt.figure(figsize=(10, 6))
# bottom = [0] * len(scenarios)

# for idx, comp in enumerate(plot_df.index):
# plt.bar(
# scenarios,
# plot_df.loc[comp],
# bottom=bottom,
# color=colors[idx],
# label=comp
# )
# bottom = [bottom[i] + plot_df.loc[comp][i] for i in range(len(scenarios))]

# plt.xlabel("Scenario")
# plt.ylabel("Cost ($/kg)")
# plt.title("Cost Breakdown per Scenario")

# # FORCE horizontal x-axis labels
# plt.xticks(rotation=0, ha="center")

# plt.legend()
# plt.tight_layout()

# plt.savefig("stacked_cost_breakdown_final.png", dpi=300)
# plt.show()

import textwrap

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


# -------------------------------------------------------------
# LOAD EXCEL
# -------------------------------------------------------------
file_path = "Breakdown_costs_per_scenario.xlsx"
df = pd.read_excel(file_path, sheet_name="Sheet1", header=None)
Comment on lines +92 to +93

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file depends on an Excel sheet, but this isn't included as part of this PR. Do you mean to add the sheet, or have a different script that produces it? Or maybe just remove this file entirely?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removing it entirely would be fine. The excel was added to help me do the plots for the E2C NE MN project.


# -------------------------------------------------------------
# READ STRUCTURE
# -------------------------------------------------------------
scenario_row = df.iloc[0, 1:].tolist()
product_row = df.iloc[1, 1:].tolist()
components = df.iloc[2:, 0].astype(str).str.strip().tolist()
values = df.iloc[2:, 1:].astype(float)

# -------------------------------------------------------------
# CLEAN NANS
# -------------------------------------------------------------
valid = [i for i, s in enumerate(scenario_row) if str(s) != "nan"]
scenario_row = [scenario_row[i] for i in valid]
product_row = [product_row[i] for i in valid]
values = values.iloc[:, valid]

# -------------------------------------------------------------
# MULTILINE SCENARIO LABELS (automatic wrapping)
# -------------------------------------------------------------
scenario_row_wrapped = ["\n".join(textwrap.wrap(s, width=18)) for s in scenario_row]

# -------------------------------------------------------------
# BUILD MULTIINDEX
# -------------------------------------------------------------
tuples = list(zip(scenario_row_wrapped, product_row))
df_plot = pd.DataFrame(values.values, index=components, columns=pd.MultiIndex.from_tuples(tuples))

# -------------------------------------------------------------
# FLATTENED PRODUCT LABELS
# -------------------------------------------------------------
flat_products = product_row

# -------------------------------------------------------------
# GROUP POSITIONS FOR SCENARIO LABELS
# -------------------------------------------------------------
scenario_groups = {}
for idx, scen in enumerate(scenario_row_wrapped):
scenario_groups.setdefault(scen, []).append(idx)

x = np.arange(len(flat_products))

# -------------------------------------------------------------
# COLOR MAP
# -------------------------------------------------------------
color_map = {
"CapEx ($/kg)": "navy",
"OpEx ($/kg)": "orange",
"Feedstock ($/kg)": "deepskyblue",
"Taxes ($/kg)": "lightpink",
"Finances ($/kg)": "yellowgreen",
}

# -------------------------------------------------------------
# PLOT
# -------------------------------------------------------------
plt.figure(figsize=(18, 7))

bottom = np.zeros(len(x))

for comp in components:
y = df_plot.loc[comp].values
plt.bar(x, y, bottom=bottom, color=color_map[comp], label=comp)
bottom += y

# -------------------------------------------------------------
# X-AXIS LABELS (PRODUCT LEVEL)
# -------------------------------------------------------------
plt.xticks(x, flat_products, rotation=0, ha="center")

# -------------------------------------------------------------
# Y-AXIS LABEL
# -------------------------------------------------------------
plt.ylabel("Levelized cost ($/kg)")

plt.title("Cost Breakdown by Product and Scenario")

# -------------------------------------------------------------
# SCENARIO LABELS (CENTERED ABOVE GROUPS)
# -------------------------------------------------------------
ymin, ymax = plt.ylim()
for scen, idxs in scenario_groups.items():
center = np.mean(idxs)
plt.text(
center, ymax + ymax * 0.04, scen, ha="center", va="bottom", fontsize=11, fontweight="bold"
)

plt.ylim(ymin, ymax * 1.25)

plt.legend(title="Cost Component", bbox_to_anchor=(1.02, 1), loc="upper left")
plt.tight_layout()
plt.show()
10 changes: 10 additions & 0 deletions examples/36_paper_mill/driver_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: driver_config
description: This analysis runs a paper mill plant and matches other examples in H2Integrate
general:
folder_output: outputs
recorder:
file: cases.sql
overwrite_recorder: true
flag: true
includes: ['*']
excludes: ['*_resource*']
Loading
Loading