OpenPyTEA 3.2.2__tar.gz → 3.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {openpytea-3.2.2/src/OpenPyTEA.egg-info → openpytea-3.2.3}/PKG-INFO +17 -30
  2. {openpytea-3.2.2 → openpytea-3.2.3}/README.md +15 -29
  3. {openpytea-3.2.2 → openpytea-3.2.3}/pyproject.toml +14 -1
  4. {openpytea-3.2.2 → openpytea-3.2.3/src/OpenPyTEA.egg-info}/PKG-INFO +17 -30
  5. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/__init__.py +17 -2
  6. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/analysis.py +108 -27
  7. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/cli.py +11 -1
  8. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/data/cost_correlations.csv +431 -425
  9. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/equipment.py +722 -34
  10. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/io.py +257 -5
  11. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/plant.py +378 -74
  12. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/plotting.py +357 -65
  13. {openpytea-3.2.2 → openpytea-3.2.3}/tests/test_analysis.py +44 -0
  14. openpytea-3.2.3/tests/test_equipment.py +286 -0
  15. {openpytea-3.2.2 → openpytea-3.2.3}/tests/test_plant.py +159 -2
  16. {openpytea-3.2.2 → openpytea-3.2.3}/tests/test_plotting.py +113 -5
  17. {openpytea-3.2.2 → openpytea-3.2.3}/tests/test_run_tea.py +123 -0
  18. openpytea-3.2.2/tests/test_equipment.py +0 -111
  19. {openpytea-3.2.2 → openpytea-3.2.3}/LICENSE +0 -0
  20. {openpytea-3.2.2 → openpytea-3.2.3}/setup.cfg +0 -0
  21. {openpytea-3.2.2 → openpytea-3.2.3}/src/OpenPyTEA.egg-info/SOURCES.txt +0 -0
  22. {openpytea-3.2.2 → openpytea-3.2.3}/src/OpenPyTEA.egg-info/dependency_links.txt +0 -0
  23. {openpytea-3.2.2 → openpytea-3.2.3}/src/OpenPyTEA.egg-info/entry_points.txt +0 -0
  24. {openpytea-3.2.2 → openpytea-3.2.3}/src/OpenPyTEA.egg-info/requires.txt +0 -0
  25. {openpytea-3.2.2 → openpytea-3.2.3}/src/OpenPyTEA.egg-info/top_level.txt +0 -0
  26. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/data/cepci_values.csv +0 -0
  27. {openpytea-3.2.2 → openpytea-3.2.3}/src/openpytea/helpers.py +0 -0
  28. {openpytea-3.2.2 → openpytea-3.2.3}/tests/test_cli.py +0 -0
  29. {openpytea-3.2.2 → openpytea-3.2.3}/tests/test_composite_equipment.py +0 -0
  30. {openpytea-3.2.2 → openpytea-3.2.3}/tests/test_smoke.py +0 -0
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: OpenPyTEA
3
- Version: 3.2.2
3
+ Version: 3.2.3
4
4
  Summary: OpenPyTEA: An open-source Python toolkit for techno-economic assessment of process plants with economic sensitivity and uncertainty evaluation
5
5
  Maintainer-email: "Panji B. Tamarona" <P.B.Tamarona@tudelft.nl>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/pbtamarona/OpenPyTEA
8
8
  Project-URL: Documentation, https://openpytea.readthedocs.io
9
+ Project-URL: Desktop app, https://github.com/pbtamarona/OpenPyTEA/releases/latest
9
10
  Project-URL: Changelog, https://github.com/pbtamarona/OpenPyTEA/releases
10
11
  Project-URL: Issues, https://github.com/pbtamarona/OpenPyTEA/issues
11
12
  Keywords: chemical-engineering,process-design,power-plant,techno-economic-analysis,process-plant
@@ -47,25 +48,8 @@ https://openpytea.readthedocs.io
47
48
  **For some case-study examples, please check the `examples` folder:**
48
49
  https://github.com/pbtamarona/OpenPyTEA/tree/main/examples
49
50
 
50
- ---
51
- ## 🎓 Workshop
52
-
53
- We are hosting a one-day workshop on open-science techno-economic assessment using **OpenPyTEA**!
54
-
55
- <p align="center">
56
- <img src="https://raw.githubusercontent.com/pbtamarona/OpenPyTEA/main/workshop-flyer.jpg" alt="OpenPyTEA" width="800"/>
57
- </p>
58
-
59
- **Open-Science Techno-Economic Assessment with OpenPyTEA: From Process Design to Economic Insights**
60
-
61
- The workshop covers the full workflow from process design and simulation to economic evaluation, combining lectures, a hands-on session with OpenPyTEA, and an industry talk by Shell. It closes with a community discussion on establishing shared TEA standards, bringing together students, researchers, engineers, and policymakers across chemical, energy, and sustainability sciences.
62
-
63
- - 📅 **Date:** November 6, 2026 | 09:30 – 18:00
64
- - 📍 **Location:** Process & Energy, TU Delft, Delft, The Netherlands
65
- - 📝 **Registration:** [aanmelder.nl/openpytea2026](https://aanmelder.nl/openpytea2026)
66
- - ⏰ **Deadline:** $${\color{red}\textbf{Registration closes on October 15, 2026}}$$
67
-
68
- Lunch, snacks, coffee, and drinks will be provided!
51
+ **To use OpenPyTEA without writing code, download the desktop app for Windows or macOS** (installing is explained in the Graphical User Interface section below):
52
+ https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.3
69
53
 
70
54
  ---
71
55
  ## ✨ Key Features
@@ -160,12 +144,12 @@ Software architecture and data flow of **OpenPyTEA**, illustrating the progressi
160
144
 
161
145
  An optional desktop app provides the full TEA workflow — equipment costing, plant configuration, results, sensitivity/tornado analysis, Monte Carlo, and multi-plant comparison — without writing Python code. No Python or Node.js required.
162
146
 
163
- **Download** the installer for your platform from the **[OpenPyTEA 3.2.2 release](https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.2)**:
147
+ **Download** the installer for your platform from the **[OpenPyTEA 3.2.3 release](https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.3)**:
164
148
 
165
149
  | Platform | File |
166
150
  |---|---|
167
- | **Windows** (x64) | `OpenPyTEA_3.2.2_x64-setup.exe` (or the `.msi`) |
168
- | **macOS** (Apple Silicon) | `OpenPyTEA_3.2.2_aarch64.dmg` |
151
+ | **Windows** (x64) | `OpenPyTEA_3.2.3_x64-setup.exe` (or the `.msi`) |
152
+ | **macOS** (Apple Silicon) | `OpenPyTEA_3.2.3_aarch64.dmg` |
169
153
 
170
154
  **Install:**
171
155
  - **Windows:** run the `.exe` and follow the setup wizard. If SmartScreen shows *"Windows protected your PC"* (the app isn't code-signed), click **More info** → **Run anyway**.
@@ -187,7 +171,7 @@ compressor = Equipment(
187
171
  name='COMP',
188
172
  param=5000, # kW
189
173
  process_type='Fluids',
190
- category='Compressors, fans, & Blowers',
174
+ category='Compressors, fans, & blowers',
191
175
  type='Compressor, centrifugal',
192
176
  material='Carbon steel'
193
177
  )
@@ -216,9 +200,10 @@ psa.breakdown() # one row per sub-component
216
200
  Multiple equipment objects can be grouped into a `Plant` instance for full TEA
217
201
 
218
202
  ```python
219
- from openpytea.plant import Plant
203
+ from openpytea.plant import Plant, PlantConfig
220
204
 
221
- ammonia_plant = Plant({
205
+ # The PlantConfig annotation is optional; it lets your editor complete keys and flag typos
206
+ config: PlantConfig = {
222
207
  'plant_name': 'Ammonia Production Plant',
223
208
  'country': 'Netherlands',
224
209
  'process_type': 'Fluids',
@@ -241,8 +226,9 @@ ammonia_plant = Plant({
241
226
  'price': 2 # US$/kg
242
227
  },
243
228
  },
244
- })
229
+ }
245
230
 
231
+ ammonia_plant = Plant(config)
246
232
  ammonia_plant.calculate_cash_flow(print_results=True)
247
233
  ammonia_plant.calculate_levelized_cost()
248
234
  ```
@@ -321,12 +307,13 @@ Pass `include_process_params=True` to rank consumption and production quantities
321
307
  Monte Carlo Simulation
322
308
  ```python
323
309
  from openpytea.analysis import monte_carlo
324
- from openpytea.plotting import plot_monte_carlo
310
+ from openpytea.plotting import plot_monte_carlo, plot_monte_carlo_cumulative
325
311
 
326
312
  results = monte_carlo(ammonia_plant, num_samples=1_000_000)
327
- fig, ax = plot_monte_carlo(results)
313
+ fig, ax = plot_monte_carlo(results) # histogram
314
+ fig, ax = plot_monte_carlo_cumulative(results) # cumulative distribution
328
315
  ```
329
- Outputs include probability distributions and confidence intervals for LCOP, NPV, ROI, and payback time—supporting uncertainty-informed decision-making. With `plot_multiple_monte_carlo`, **OpenPyTEA** can also visualize Monte Carlo results for multiple plants to enable uncertainty comparisons. `plot_monte_carlo_inputs` shows the sampled inputs themselves, split into **process** and **economic** figures, to confirm each distribution came out as intended.
316
+ Outputs include probability distributions for LCOP, NPV, ROI, and payback time—supporting uncertainty-informed decision-making. Both plots mark the P10, P50 and P90 and list their values; the cumulative plot also reads probabilities such as "P(LCOP ≤ x)" straight off the curve. Given a list of plants, either function compares Monte Carlo results for multiple plants on one plot. `plot_monte_carlo_inputs` shows the sampled inputs themselves, split into **process** and **economic** figures, to confirm each distribution came out as intended.
330
317
 
331
318
  Uncertainty is configured per item: `price_uncertainty` on any `variable_opex_inputs` or `plant_products` entry, `consumption_uncertainty`/`production_uncertainty` for the quantities, and `project_uncertainties` for the project-level scalars.
332
319
 
@@ -19,25 +19,8 @@ https://openpytea.readthedocs.io
19
19
  **For some case-study examples, please check the `examples` folder:**
20
20
  https://github.com/pbtamarona/OpenPyTEA/tree/main/examples
21
21
 
22
- ---
23
- ## 🎓 Workshop
24
-
25
- We are hosting a one-day workshop on open-science techno-economic assessment using **OpenPyTEA**!
26
-
27
- <p align="center">
28
- <img src="https://raw.githubusercontent.com/pbtamarona/OpenPyTEA/main/workshop-flyer.jpg" alt="OpenPyTEA" width="800"/>
29
- </p>
30
-
31
- **Open-Science Techno-Economic Assessment with OpenPyTEA: From Process Design to Economic Insights**
32
-
33
- The workshop covers the full workflow from process design and simulation to economic evaluation, combining lectures, a hands-on session with OpenPyTEA, and an industry talk by Shell. It closes with a community discussion on establishing shared TEA standards, bringing together students, researchers, engineers, and policymakers across chemical, energy, and sustainability sciences.
34
-
35
- - 📅 **Date:** November 6, 2026 | 09:30 – 18:00
36
- - 📍 **Location:** Process & Energy, TU Delft, Delft, The Netherlands
37
- - 📝 **Registration:** [aanmelder.nl/openpytea2026](https://aanmelder.nl/openpytea2026)
38
- - ⏰ **Deadline:** $${\color{red}\textbf{Registration closes on October 15, 2026}}$$
39
-
40
- Lunch, snacks, coffee, and drinks will be provided!
22
+ **To use OpenPyTEA without writing code, download the desktop app for Windows or macOS** (installing is explained in the Graphical User Interface section below):
23
+ https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.3
41
24
 
42
25
  ---
43
26
  ## ✨ Key Features
@@ -132,12 +115,12 @@ Software architecture and data flow of **OpenPyTEA**, illustrating the progressi
132
115
 
133
116
  An optional desktop app provides the full TEA workflow — equipment costing, plant configuration, results, sensitivity/tornado analysis, Monte Carlo, and multi-plant comparison — without writing Python code. No Python or Node.js required.
134
117
 
135
- **Download** the installer for your platform from the **[OpenPyTEA 3.2.2 release](https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.2)**:
118
+ **Download** the installer for your platform from the **[OpenPyTEA 3.2.3 release](https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.3)**:
136
119
 
137
120
  | Platform | File |
138
121
  |---|---|
139
- | **Windows** (x64) | `OpenPyTEA_3.2.2_x64-setup.exe` (or the `.msi`) |
140
- | **macOS** (Apple Silicon) | `OpenPyTEA_3.2.2_aarch64.dmg` |
122
+ | **Windows** (x64) | `OpenPyTEA_3.2.3_x64-setup.exe` (or the `.msi`) |
123
+ | **macOS** (Apple Silicon) | `OpenPyTEA_3.2.3_aarch64.dmg` |
141
124
 
142
125
  **Install:**
143
126
  - **Windows:** run the `.exe` and follow the setup wizard. If SmartScreen shows *"Windows protected your PC"* (the app isn't code-signed), click **More info** → **Run anyway**.
@@ -159,7 +142,7 @@ compressor = Equipment(
159
142
  name='COMP',
160
143
  param=5000, # kW
161
144
  process_type='Fluids',
162
- category='Compressors, fans, & Blowers',
145
+ category='Compressors, fans, & blowers',
163
146
  type='Compressor, centrifugal',
164
147
  material='Carbon steel'
165
148
  )
@@ -188,9 +171,10 @@ psa.breakdown() # one row per sub-component
188
171
  Multiple equipment objects can be grouped into a `Plant` instance for full TEA
189
172
 
190
173
  ```python
191
- from openpytea.plant import Plant
174
+ from openpytea.plant import Plant, PlantConfig
192
175
 
193
- ammonia_plant = Plant({
176
+ # The PlantConfig annotation is optional; it lets your editor complete keys and flag typos
177
+ config: PlantConfig = {
194
178
  'plant_name': 'Ammonia Production Plant',
195
179
  'country': 'Netherlands',
196
180
  'process_type': 'Fluids',
@@ -213,8 +197,9 @@ ammonia_plant = Plant({
213
197
  'price': 2 # US$/kg
214
198
  },
215
199
  },
216
- })
200
+ }
217
201
 
202
+ ammonia_plant = Plant(config)
218
203
  ammonia_plant.calculate_cash_flow(print_results=True)
219
204
  ammonia_plant.calculate_levelized_cost()
220
205
  ```
@@ -293,12 +278,13 @@ Pass `include_process_params=True` to rank consumption and production quantities
293
278
  Monte Carlo Simulation
294
279
  ```python
295
280
  from openpytea.analysis import monte_carlo
296
- from openpytea.plotting import plot_monte_carlo
281
+ from openpytea.plotting import plot_monte_carlo, plot_monte_carlo_cumulative
297
282
 
298
283
  results = monte_carlo(ammonia_plant, num_samples=1_000_000)
299
- fig, ax = plot_monte_carlo(results)
284
+ fig, ax = plot_monte_carlo(results) # histogram
285
+ fig, ax = plot_monte_carlo_cumulative(results) # cumulative distribution
300
286
  ```
301
- Outputs include probability distributions and confidence intervals for LCOP, NPV, ROI, and payback time—supporting uncertainty-informed decision-making. With `plot_multiple_monte_carlo`, **OpenPyTEA** can also visualize Monte Carlo results for multiple plants to enable uncertainty comparisons. `plot_monte_carlo_inputs` shows the sampled inputs themselves, split into **process** and **economic** figures, to confirm each distribution came out as intended.
287
+ Outputs include probability distributions for LCOP, NPV, ROI, and payback time—supporting uncertainty-informed decision-making. Both plots mark the P10, P50 and P90 and list their values; the cumulative plot also reads probabilities such as "P(LCOP ≤ x)" straight off the curve. Given a list of plants, either function compares Monte Carlo results for multiple plants on one plot. `plot_monte_carlo_inputs` shows the sampled inputs themselves, split into **process** and **economic** figures, to confirm each distribution came out as intended.
302
288
 
303
289
  Uncertainty is configured per item: `price_uncertainty` on any `variable_opex_inputs` or `plant_products` entry, `consumption_uncertainty`/`production_uncertainty` for the quantities, and `project_uncertainties` for the project-level scalars.
304
290
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "OpenPyTEA"
3
- version = "3.2.2"
3
+ version = "3.2.3"
4
4
  description = "OpenPyTEA: An open-source Python toolkit for techno-economic assessment of process plants with economic sensitivity and uncertainty evaluation"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -31,6 +31,7 @@ maintainers = [
31
31
  [project.urls]
32
32
  Homepage = "https://github.com/pbtamarona/OpenPyTEA"
33
33
  Documentation = "https://openpytea.readthedocs.io"
34
+ "Desktop app" = "https://github.com/pbtamarona/OpenPyTEA/releases/latest"
34
35
  Changelog = "https://github.com/pbtamarona/OpenPyTEA/releases"
35
36
  Issues = "https://github.com/pbtamarona/OpenPyTEA/issues"
36
37
 
@@ -82,3 +83,15 @@ ignore = []
82
83
 
83
84
  [tool.ruff.format]
84
85
  quote-style = "double"
86
+
87
+ # Type checking, read by VS Code's Pylance and by the pyright CLI
88
+ # (`npx pyright` from the repo root)
89
+ [tool.pyright]
90
+ typeCheckingMode = "basic"
91
+ pythonVersion = "3.10"
92
+ venvPath = "."
93
+ venv = ".venv"
94
+ # The notebooks use `from openpytea.analysis import *` on purpose
95
+ reportWildcardImportFromLibrary = false
96
+ # Don't report type-check diagnostics in notebooks (they're user-facing examples)
97
+ ignore = ["**/*.ipynb"]
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: OpenPyTEA
3
- Version: 3.2.2
3
+ Version: 3.2.3
4
4
  Summary: OpenPyTEA: An open-source Python toolkit for techno-economic assessment of process plants with economic sensitivity and uncertainty evaluation
5
5
  Maintainer-email: "Panji B. Tamarona" <P.B.Tamarona@tudelft.nl>
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/pbtamarona/OpenPyTEA
8
8
  Project-URL: Documentation, https://openpytea.readthedocs.io
9
+ Project-URL: Desktop app, https://github.com/pbtamarona/OpenPyTEA/releases/latest
9
10
  Project-URL: Changelog, https://github.com/pbtamarona/OpenPyTEA/releases
10
11
  Project-URL: Issues, https://github.com/pbtamarona/OpenPyTEA/issues
11
12
  Keywords: chemical-engineering,process-design,power-plant,techno-economic-analysis,process-plant
@@ -47,25 +48,8 @@ https://openpytea.readthedocs.io
47
48
  **For some case-study examples, please check the `examples` folder:**
48
49
  https://github.com/pbtamarona/OpenPyTEA/tree/main/examples
49
50
 
50
- ---
51
- ## 🎓 Workshop
52
-
53
- We are hosting a one-day workshop on open-science techno-economic assessment using **OpenPyTEA**!
54
-
55
- <p align="center">
56
- <img src="https://raw.githubusercontent.com/pbtamarona/OpenPyTEA/main/workshop-flyer.jpg" alt="OpenPyTEA" width="800"/>
57
- </p>
58
-
59
- **Open-Science Techno-Economic Assessment with OpenPyTEA: From Process Design to Economic Insights**
60
-
61
- The workshop covers the full workflow from process design and simulation to economic evaluation, combining lectures, a hands-on session with OpenPyTEA, and an industry talk by Shell. It closes with a community discussion on establishing shared TEA standards, bringing together students, researchers, engineers, and policymakers across chemical, energy, and sustainability sciences.
62
-
63
- - 📅 **Date:** November 6, 2026 | 09:30 – 18:00
64
- - 📍 **Location:** Process & Energy, TU Delft, Delft, The Netherlands
65
- - 📝 **Registration:** [aanmelder.nl/openpytea2026](https://aanmelder.nl/openpytea2026)
66
- - ⏰ **Deadline:** $${\color{red}\textbf{Registration closes on October 15, 2026}}$$
67
-
68
- Lunch, snacks, coffee, and drinks will be provided!
51
+ **To use OpenPyTEA without writing code, download the desktop app for Windows or macOS** (installing is explained in the Graphical User Interface section below):
52
+ https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.3
69
53
 
70
54
  ---
71
55
  ## ✨ Key Features
@@ -160,12 +144,12 @@ Software architecture and data flow of **OpenPyTEA**, illustrating the progressi
160
144
 
161
145
  An optional desktop app provides the full TEA workflow — equipment costing, plant configuration, results, sensitivity/tornado analysis, Monte Carlo, and multi-plant comparison — without writing Python code. No Python or Node.js required.
162
146
 
163
- **Download** the installer for your platform from the **[OpenPyTEA 3.2.2 release](https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.2)**:
147
+ **Download** the installer for your platform from the **[OpenPyTEA 3.2.3 release](https://github.com/pbtamarona/OpenPyTEA/releases/tag/v3.2.3)**:
164
148
 
165
149
  | Platform | File |
166
150
  |---|---|
167
- | **Windows** (x64) | `OpenPyTEA_3.2.2_x64-setup.exe` (or the `.msi`) |
168
- | **macOS** (Apple Silicon) | `OpenPyTEA_3.2.2_aarch64.dmg` |
151
+ | **Windows** (x64) | `OpenPyTEA_3.2.3_x64-setup.exe` (or the `.msi`) |
152
+ | **macOS** (Apple Silicon) | `OpenPyTEA_3.2.3_aarch64.dmg` |
169
153
 
170
154
  **Install:**
171
155
  - **Windows:** run the `.exe` and follow the setup wizard. If SmartScreen shows *"Windows protected your PC"* (the app isn't code-signed), click **More info** → **Run anyway**.
@@ -187,7 +171,7 @@ compressor = Equipment(
187
171
  name='COMP',
188
172
  param=5000, # kW
189
173
  process_type='Fluids',
190
- category='Compressors, fans, & Blowers',
174
+ category='Compressors, fans, & blowers',
191
175
  type='Compressor, centrifugal',
192
176
  material='Carbon steel'
193
177
  )
@@ -216,9 +200,10 @@ psa.breakdown() # one row per sub-component
216
200
  Multiple equipment objects can be grouped into a `Plant` instance for full TEA
217
201
 
218
202
  ```python
219
- from openpytea.plant import Plant
203
+ from openpytea.plant import Plant, PlantConfig
220
204
 
221
- ammonia_plant = Plant({
205
+ # The PlantConfig annotation is optional; it lets your editor complete keys and flag typos
206
+ config: PlantConfig = {
222
207
  'plant_name': 'Ammonia Production Plant',
223
208
  'country': 'Netherlands',
224
209
  'process_type': 'Fluids',
@@ -241,8 +226,9 @@ ammonia_plant = Plant({
241
226
  'price': 2 # US$/kg
242
227
  },
243
228
  },
244
- })
229
+ }
245
230
 
231
+ ammonia_plant = Plant(config)
246
232
  ammonia_plant.calculate_cash_flow(print_results=True)
247
233
  ammonia_plant.calculate_levelized_cost()
248
234
  ```
@@ -321,12 +307,13 @@ Pass `include_process_params=True` to rank consumption and production quantities
321
307
  Monte Carlo Simulation
322
308
  ```python
323
309
  from openpytea.analysis import monte_carlo
324
- from openpytea.plotting import plot_monte_carlo
310
+ from openpytea.plotting import plot_monte_carlo, plot_monte_carlo_cumulative
325
311
 
326
312
  results = monte_carlo(ammonia_plant, num_samples=1_000_000)
327
- fig, ax = plot_monte_carlo(results)
313
+ fig, ax = plot_monte_carlo(results) # histogram
314
+ fig, ax = plot_monte_carlo_cumulative(results) # cumulative distribution
328
315
  ```
329
- Outputs include probability distributions and confidence intervals for LCOP, NPV, ROI, and payback time—supporting uncertainty-informed decision-making. With `plot_multiple_monte_carlo`, **OpenPyTEA** can also visualize Monte Carlo results for multiple plants to enable uncertainty comparisons. `plot_monte_carlo_inputs` shows the sampled inputs themselves, split into **process** and **economic** figures, to confirm each distribution came out as intended.
316
+ Outputs include probability distributions for LCOP, NPV, ROI, and payback time—supporting uncertainty-informed decision-making. Both plots mark the P10, P50 and P90 and list their values; the cumulative plot also reads probabilities such as "P(LCOP ≤ x)" straight off the curve. Given a list of plants, either function compares Monte Carlo results for multiple plants on one plot. `plot_monte_carlo_inputs` shows the sampled inputs themselves, split into **process** and **economic** figures, to confirm each distribution came out as intended.
330
317
 
331
318
  Uncertainty is configured per item: `price_uncertainty` on any `variable_opex_inputs` or `plant_products` entry, `consumption_uncertainty`/`production_uncertainty` for the quantities, and `project_uncertainties` for the project-level scalars.
332
319
 
@@ -5,8 +5,11 @@ economic sensitivity and uncertainty evaluation.
5
5
 
6
6
  from importlib.metadata import version
7
7
 
8
- from .plant import Plant
9
- from .equipment import Equipment, CompositeEquipment, inflation_adjustment
8
+ from .plant import (Plant, PlantConfig, OpexInput, ProductInput,
9
+ Uncertainty, Dependency)
10
+ from .equipment import (Equipment, CompositeEquipment, inflation_adjustment,
11
+ equipment_options, ProcessType, Category,
12
+ EquipmentType, Material)
10
13
  from .analysis import (direct_costs_data, fixed_capital_data,
11
14
  fixed_opex_data, variable_opex_data,
12
15
  levelized_cost_data, cash_flow_data,
@@ -15,6 +18,7 @@ from .analysis import (direct_costs_data, fixed_capital_data,
15
18
  from .plotting import (plot_stacked_bar, plot_cash_flow,
16
19
  plot_sensitivity,
17
20
  plot_tornado, plot_monte_carlo,
21
+ plot_monte_carlo_cumulative,
18
22
  plot_monte_carlo_inputs,
19
23
  plot_multiple_monte_carlo)
20
24
 
@@ -27,9 +31,19 @@ __license__ = "MIT"
27
31
 
28
32
  __all__ = [
29
33
  "Plant",
34
+ "PlantConfig",
35
+ "OpexInput",
36
+ "ProductInput",
37
+ "Uncertainty",
38
+ "Dependency",
30
39
  "Equipment",
31
40
  "CompositeEquipment",
32
41
  "inflation_adjustment",
42
+ "equipment_options",
43
+ "ProcessType",
44
+ "Category",
45
+ "EquipmentType",
46
+ "Material",
33
47
  "direct_costs_data",
34
48
  "fixed_capital_data",
35
49
  "fixed_opex_data",
@@ -44,6 +58,7 @@ __all__ = [
44
58
  "plot_sensitivity",
45
59
  "plot_tornado",
46
60
  "plot_monte_carlo",
61
+ "plot_monte_carlo_cumulative",
47
62
  "plot_monte_carlo_inputs",
48
63
  "plot_multiple_monte_carlo",
49
64
  "load_results",
@@ -2,9 +2,11 @@ import warnings
2
2
  from copy import deepcopy
3
3
  from tqdm.auto import tqdm
4
4
  from scipy import stats
5
+ from scipy.optimize import root_scalar
5
6
  import numpy as np
6
7
 
7
- from openpytea.plant import DEFAULT_OPERATOR_HOURLY_RATE
8
+ from openpytea.plant import (DEFAULT_OPERATOR_HOURLY_RATE,
9
+ _additional_capex_items)
8
10
  from openpytea.helpers import (_make_label,
9
11
  _legacy_label,
10
12
  _tex_escape,
@@ -159,23 +161,19 @@ def fixed_capital_data(plants, additional_capex=False, pct=False):
159
161
  "Contingency": plant.contigency,
160
162
  }
161
163
 
162
- # ponytail: isinstance/try coercion; 0.0 if extra is None else
163
- # float(np.sum(extra))
164
- if additional_capex:
165
- extra = getattr(plant, "additional_capex_cost", None)
166
-
167
- if isinstance(extra, (list, tuple, np.ndarray)):
168
- total_extra = float(
169
- sum(x for x in extra if isinstance(x, (int, float)))
164
+ # Named additional CAPEX ({name: cost}) gets a segment per item,
165
+ # unnamed (a list) one summed "Additional CAPEX" segment
166
+ items = _additional_capex_items(
167
+ plant.additional_capex_cost, plant.additional_capex_years
168
+ ) if additional_capex else None
169
+ if items is not None:
170
+ names, costs, _ = items
171
+ if names:
172
+ components.update(
173
+ {_make_label(n): float(c) for n, c in zip(names, costs)}
170
174
  )
171
- else:
172
- try:
173
- total_extra = float(extra) if extra is not None else 0.0
174
- except (TypeError, ValueError):
175
- total_extra = 0.0
176
-
177
- if total_extra != 0:
178
- components["Additional CAPEX"] = total_extra
175
+ elif costs.sum() != 0:
176
+ components["Additional CAPEX"] = float(costs.sum())
179
177
 
180
178
  components_list.append(components)
181
179
  xlabels.append(plant.name)
@@ -995,6 +993,9 @@ def make_distribution(dist_id, loc=None, scale=None, shape=None,
995
993
  - 10 : Beta (``loc``=alpha, ``shape``=beta, ``maximum``=upper bound)
996
994
  - 11 : GEV (``loc``=mu, ``scale``=sigma, ``shape``=xi)
997
995
  - 12 : Student's t (``loc``=median, ``scale``=scale, ``shape``=nu)
996
+
997
+ 13 (Reversed lognormal) has no frozen SciPy form; only
998
+ :func:`sample_distribution` supports it.
998
999
  loc : float, optional
999
1000
  Location parameter; meaning depends on ``dist_id`` (see above).
1000
1001
  scale : float, optional
@@ -1063,10 +1064,69 @@ def make_distribution(dist_id, loc=None, scale=None, shape=None,
1063
1064
  elif dist_id == 12: # Student's t: loc=median, scale=scale, shape=nu
1064
1065
  return stats.t(df=shape, loc=loc, scale=scale)
1065
1066
 
1067
+ elif dist_id == 13:
1068
+ raise ValueError(
1069
+ "dist_id 13 (Reversed lognormal) has no frozen SciPy "
1070
+ "distribution; draw it with sample_distribution."
1071
+ )
1072
+
1066
1073
  else:
1067
1074
  raise ValueError(f"Unsupported dist_id for make_distribution: {dist_id}")
1068
1075
 
1069
1076
 
1077
+ def _reversed_lognormal_quantile(u, mean, std, minimum, maximum):
1078
+ """
1079
+ Quantiles ``u`` of a lognormal mirrored at ``maximum`` (long tail
1080
+ towards ``minimum``), truncated to ``[minimum, maximum]``.
1081
+
1082
+ ``x = maximum - y`` with ``y`` lognormal on ``(0, maximum - minimum]``.
1083
+ ``sigma`` of ``ln y`` is set from ``std`` (the spread before
1084
+ truncation, so the sampled spread comes out smaller), and ``mu`` is
1085
+ solved so the truncated mean equals ``mean``. Quantiles increase
1086
+ with ``u``.
1087
+ """
1088
+ if maximum is None or minimum is None or mean is None:
1089
+ raise ValueError(
1090
+ "Reversed lognormal (dist_id 13) needs a mean, minimum and "
1091
+ "maximum."
1092
+ )
1093
+ if not minimum < mean < maximum:
1094
+ raise ValueError(
1095
+ "Reversed lognormal (dist_id 13) needs minimum < mean < "
1096
+ f"maximum (got {minimum}, {mean}, {maximum})."
1097
+ )
1098
+ if not std or std <= 0:
1099
+ raise ValueError(
1100
+ f"Reversed lognormal (dist_id 13) needs std > 0 (got {std})."
1101
+ )
1102
+
1103
+ y_mean, y_high = maximum - mean, maximum - minimum
1104
+ sigma = np.sqrt(np.log(1 + (std / y_mean) ** 2))
1105
+ log_high = np.log(y_high)
1106
+
1107
+ def truncated_mean_gap(mu):
1108
+ # E[y | y <= y_high] - y_mean, closed form for a lognormal; y's
1109
+ # lower bound is 0, so only the upper cut appears
1110
+ b = (log_high - mu) / sigma
1111
+ return (np.exp(mu + sigma**2 / 2) * stats.norm.cdf(b - sigma)
1112
+ / stats.norm.cdf(b) - y_mean)
1113
+
1114
+ try:
1115
+ mu = root_scalar(
1116
+ truncated_mean_gap, method="brentq",
1117
+ bracket=(np.log(y_mean) - 5 * sigma - 1, log_high + 3 * sigma),
1118
+ ).root
1119
+ except ValueError:
1120
+ raise ValueError(
1121
+ "Reversed lognormal (dist_id 13): no lognormal with std "
1122
+ f"{std} has mean {mean} within [{minimum}, {maximum}]; the "
1123
+ "mean is too close to the minimum for that spread. Lower std "
1124
+ "or widen the window."
1125
+ ) from None
1126
+ y = stats.lognorm(s=sigma, scale=np.exp(mu))
1127
+ return maximum - y.ppf((1 - np.asarray(u)) * y.cdf(y_high))
1128
+
1129
+
1070
1130
  def sample_distribution(dist_id, size, loc=None, scale=None, shape=None,
1071
1131
  minimum=None, maximum=None, random_state=None):
1072
1132
  """
@@ -1079,6 +1139,13 @@ def sample_distribution(dist_id, size, loc=None, scale=None, shape=None,
1079
1139
  samples are drawn and re-drawn (rejection sampling) until ``size``
1080
1140
  values fall within ``[minimum, maximum]``.
1081
1141
 
1142
+ ``dist_id`` 13 (Reversed lognormal) is drawn here only: a lognormal
1143
+ mirrored at ``maximum``, so its long tail points down to ``minimum``.
1144
+ ``loc`` is the mean of the samples and ``scale`` their std before
1145
+ truncation (the sampled std comes out smaller), both in real units.
1146
+ ``maximum`` is the mirror point, not just a cut-off: moving it moves
1147
+ every sample.
1148
+
1082
1149
  Parameters
1083
1150
  ----------
1084
1151
  dist_id : int
@@ -1121,6 +1188,11 @@ def sample_distribution(dist_id, size, loc=None, scale=None, shape=None,
1121
1188
  if dist_id in (0, 1):
1122
1189
  return np.full(size, loc if loc is not None else 0.0)
1123
1190
 
1191
+ if dist_id == 13: # Reversed lognormal: loc=mean, scale=std, [min, max]
1192
+ rng = np.random.default_rng(random_state)
1193
+ return _reversed_lognormal_quantile(
1194
+ rng.uniform(size=size), loc, scale, minimum, maximum)
1195
+
1124
1196
  dist = make_distribution(dist_id, loc=loc, scale=scale, shape=shape,
1125
1197
  minimum=minimum, maximum=maximum)
1126
1198
 
@@ -1188,8 +1260,10 @@ def _has_uncertainty(cfg):
1188
1260
  return _resolve_scale(cfg) > 0 or "dist_id" in cfg
1189
1261
 
1190
1262
 
1191
- def _resolve_dist_params(cfg, default_loc=0.0, default_scale=0.0,
1192
- default_min=0, default_max=99999, default_id=3):
1263
+ def _resolve_dist_params(cfg, default_loc: float = 0.0,
1264
+ default_scale: float = 0.0,
1265
+ default_min: float = 0, default_max: float = 99999,
1266
+ default_id: int = 3):
1193
1267
  """
1194
1268
  Extract ``(dist_id, loc, scale, shape, minimum, maximum)`` from a config dict.
1195
1269
 
@@ -1238,6 +1312,13 @@ def _resolve_dist_params(cfg, default_loc=0.0, default_scale=0.0,
1238
1312
  where the rest of the distribution config isn't needed yet.
1239
1313
  """
1240
1314
  dist_id = cfg.get("dist_id", default_id)
1315
+ if dist_id == 13 and "max" not in cfg and "maximum" not in cfg:
1316
+ # The cap is where the distribution is mirrored; a default one
1317
+ # (99999, or baseline + 2*std) would silently move every sample
1318
+ raise ValueError(
1319
+ "Reversed lognormal (dist_id 13) needs an explicit 'max': it "
1320
+ "is the cap the distribution is mirrored at."
1321
+ )
1241
1322
  loc = cfg.get(
1242
1323
  "loc", cfg.get("mean", cfg.get("price", cfg.get("rate", default_loc)))
1243
1324
  )
@@ -1590,7 +1671,7 @@ def monte_carlo(plant,
1590
1671
  num_samples: int = 100_000,
1591
1672
  batch_size: int = 10_000,
1592
1673
  additional_capex: bool = False,
1593
- random_seed: int = None):
1674
+ random_seed: int | None = None):
1594
1675
  """
1595
1676
  Run a Monte Carlo uncertainty simulation over a plant's financial metrics.
1596
1677
 
@@ -1740,9 +1821,11 @@ def monte_carlo(plant,
1740
1821
  def cfg(name):
1741
1822
  return op_cfg if name == "operator_hourly_rate" else pu.get(name, {})
1742
1823
 
1743
- factor_window = dict(
1744
- default_loc=1, default_scale=0.3, default_min=0.25, default_max=1.75,
1745
- )
1824
+ def factor_dist(name):
1825
+ return _resolve_dist_params(
1826
+ cfg(name), default_loc=1, default_scale=0.3,
1827
+ default_min=0.25, default_max=1.75,
1828
+ )
1746
1829
  # (name, dist params, sampled only when it configures uncertainty)
1747
1830
  project_inputs = [
1748
1831
  ("plant_utilization", _window_dist_params(
@@ -1750,10 +1833,8 @@ def monte_carlo(plant,
1750
1833
  floor=0.0, cap=1.0), True),
1751
1834
  ("tax_rate", _window_dist_params(
1752
1835
  cfg("tax_rate"), plant.tax_rate, 0, floor=0.0, cap=1.0), True),
1753
- ("fixed_capital_factor", _resolve_dist_params(
1754
- cfg("fixed_capital_factor"), **factor_window), False),
1755
- ("fixed_opex_factor", _resolve_dist_params(
1756
- cfg("fixed_opex_factor"), **factor_window), False),
1836
+ ("fixed_capital_factor", factor_dist("fixed_capital_factor"), False),
1837
+ ("fixed_opex_factor", factor_dist("fixed_opex_factor"), False),
1757
1838
  ("operator_hourly_rate", _resolve_item_dist_params(
1758
1839
  op_cfg, "rate", DEFAULT_OPERATOR_HOURLY_RATE, 10), False),
1759
1840
  ("project_lifetime", _window_dist_params(
@@ -13,12 +13,22 @@ from openpytea.io import run_equipment, run_plant, run_tea, run_openpytea
13
13
 
14
14
 
15
15
  def _print_run_summary(results, output_dir):
16
- ran = ", ".join(sorted(results)) or "(none)"
17
16
  dest = (
18
17
  output_dir
19
18
  if output_dir is not None
20
19
  else "the directory configured in the analysis file (default 'results')"
21
20
  )
21
+ if "plants" in results: # a multi-plant project
22
+ for name, plant_results in results["plants"].items():
23
+ ran = ", ".join(sorted(plant_results)) or "calculations only"
24
+ print(f"{name}: ran {ran}")
25
+ compared = results.get("comparison")
26
+ if compared:
27
+ print(f"Compared across plants: {', '.join(sorted(compared))}")
28
+ print(f"Results written to: {dest} (one folder per plant"
29
+ f"{', plus comparison' if compared else ''})")
30
+ return
31
+ ran = ", ".join(sorted(results)) or "(none)"
22
32
  print(f"Ran: {ran}")
23
33
  print(f"Results written to: {dest}")
24
34