Skip to content

Commit 1847b65

Browse files
Move royalty outputs to EXTENDED ECONOMICS
1 parent ecab0f7 commit 1847b65

File tree

5 files changed

+62
-41
lines changed

5 files changed

+62
-41
lines changed

src/geophires_x/Outputs.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import math
33
import time
44
import sys
5+
from io import TextIOWrapper
56
from pathlib import Path
7+
from typing import Any
68

79
# noinspection PyPackageRequirements
810
import numpy as np
@@ -324,19 +326,6 @@ def PrintOutputs(self, model: Model):
324326
if model.surfaceplant.enduse_option.value in [EndUseOptions.ELECTRICITY]:
325327
f.write(f' Estimated Jobs Created: {model.economics.jobs_created.value}\n')
326328

327-
if econ.royalty_rate.Provided:
328-
for royalty_output in [
329-
econ.royalty_holder_npv,
330-
econ.royalty_holder_annual_revenue,
331-
econ.royalty_holder_total_revenue
332-
]:
333-
label = Outputs._field_label(royalty_output.display_name, 49)
334-
f.write(
335-
f' {label}{royalty_output.value:10.2f} {royalty_output.CurrentUnits.value}\n')
336-
337-
338-
339-
340329
f.write(NL)
341330
f.write(' ***ENGINEERING PARAMETERS***\n')
342331
f.write(NL)
@@ -803,9 +792,25 @@ def PrintOutputs(self, model: Model):
803792

804793
addon_df = pd.DataFrame()
805794
addon_results = []
795+
extended_economics_header_printed = False
806796
if model.economics.DoAddOnCalculations.value and not is_sam_econ_model:
807797
# SAM econ models incorporate add-on economics into main economics, not as separate extended economics.
808798
addon_df, addon_results = model.addoutputs.PrintOutputs(model)
799+
extended_economics_header_printed = True
800+
801+
if econ.royalty_rate.Provided:
802+
with open(self.output_file, 'a', encoding='UTF-8') as f_:
803+
if not extended_economics_header_printed:
804+
self._print_extended_economics_header(f_)
805+
806+
for royalty_output in [
807+
econ.royalty_holder_npv,
808+
econ.royalty_holder_annual_revenue,
809+
econ.royalty_holder_total_revenue
810+
]:
811+
label = Outputs._field_label(royalty_output.display_name, 49)
812+
f_.write(
813+
f' {label}{royalty_output.value:10.2f} {royalty_output.CurrentUnits.value}\n')
809814

810815
sdac_df = pd.DataFrame()
811816
sdac_results = []
@@ -909,6 +914,24 @@ def get_sam_cash_flow_profile_output(self, model):
909914

910915
return ret
911916

917+
def _print_extended_economics_header(self, f_output_file: TextIOWrapper | None = None) -> None:
918+
"""
919+
Header may be printed by either OutputsAddOns, or parent class if royalties are calculated and add-ons are not.
920+
"""
921+
922+
close_f = False
923+
if f_output_file is None:
924+
f_output_file = open(self.output_file, 'a', encoding='UTF-8')
925+
close_f = True
926+
927+
f_output_file.write(NL)
928+
f_output_file.write(NL)
929+
f_output_file.write(" ***EXTENDED ECONOMICS***\n")
930+
f_output_file.write(NL)
931+
932+
if close_f:
933+
f_output_file.close()
934+
912935
@staticmethod
913936
def _field_label(field_name: str, print_width_before_value: int) -> str:
914937
return f'{field_name}:{" " * (print_width_before_value - len(field_name) - 1)}'

src/geophires_x/OutputsAddOns.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ def PrintOutputs(self, model) -> tuple[pd.DataFrame, list]:
2929
try:
3030
with open(self.output_file, 'a', encoding='UTF-8') as f:
3131
addon_results: list[OutputTableItem] = []
32-
f.write(NL)
33-
f.write(NL)
34-
f.write(" ***EXTENDED ECONOMICS***\n")
35-
f.write(NL)
32+
self._print_extended_economics_header(f)
33+
3634
if model.economics.LCOE.value > -999.0:
3735
f.write(f" Adjusted Project LCOE (after incentives, grants, AddOns,etc): {model.economics.LCOE.value:10.2f} " + model.economics.LCOE.PreferredUnits.value + NL)
3836
addon_results.append(OutputTableItem('Adjusted Project LCOE (after incentives, grants, AddOns,etc)', '{0:10.2f}'.format(model.economics.LCOE.value), model.economics.LCOE.PreferredUnits.value))

src/geophires_x_client/geophires_x_result.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ class GeophiresXResult:
9393
'Project Payback Period',
9494
'CHP: Percent cost allocation for electrical plant',
9595
'Estimated Jobs Created',
96-
'Royalty Holder NPV',
97-
'Royalty Holder Average Annual Revenue',
98-
'Royalty Holder Total Revenue',
9996
],
10097
'EXTENDED ECONOMICS': [
10198
'Adjusted Project LCOE (after incentives, grants, AddOns,etc)',
@@ -113,6 +110,9 @@ class GeophiresXResult:
113110
'Total Add-on Net Heat',
114111
'Total Add-on Profit',
115112
'AddOns Payback Period',
113+
'Royalty Holder NPV',
114+
'Royalty Holder Average Annual Revenue',
115+
'Royalty Holder Total Revenue',
116116
],
117117
'CCUS ECONOMICS': [
118118
'Total Avoided Carbon Production',

src/geophires_x_schema_generator/geophires-result.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,6 @@
143143
"type": "number",
144144
"description": "",
145145
"units": null
146-
},
147-
"Royalty Holder NPV": {
148-
"type": "number",
149-
"description": "Net Present Value (NPV) of the royalty holder's cash flow stream.",
150-
"units": "MUSD"
151-
},
152-
"Royalty Holder Average Annual Revenue": {
153-
"type": "number",
154-
"description": "The royalty holder's annual revenue stream from the royalty agreement.",
155-
"units": "MUSD/yr"
156-
},
157-
"Royalty Holder Total Revenue": {
158-
"type": "number",
159-
"description": "The total (undiscounted) revenue received by the royalty holder over the project lifetime.",
160-
"units": "MUSD"
161146
}
162147
}
163148
},
@@ -186,7 +171,22 @@
186171
"Total Add-on Net Elec": {},
187172
"Total Add-on Net Heat": {},
188173
"Total Add-on Profit": {},
189-
"AddOns Payback Period": {}
174+
"AddOns Payback Period": {},
175+
"Royalty Holder NPV": {
176+
"type": "number",
177+
"description": "Net Present Value (NPV) of the royalty holder's cash flow stream.",
178+
"units": "MUSD"
179+
},
180+
"Royalty Holder Average Annual Revenue": {
181+
"type": "number",
182+
"description": "The royalty holder's annual revenue stream from the royalty agreement.",
183+
"units": "MUSD/yr"
184+
},
185+
"Royalty Holder Total Revenue": {
186+
"type": "number",
187+
"description": "The total (undiscounted) revenue received by the royalty holder over the project lifetime.",
188+
"units": "MUSD"
189+
}
190190
}
191191
},
192192
"CCUS ECONOMICS": {

tests/test_geophires_x.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
import numpy as np
1111

12-
# @formatter:off
13-
# noinspection PyProtectedMember
14-
from geophires_x.EconomicsSam import _cash_flow_profile_row
1512
from geophires_x.OptionList import PlantType
1613
from geophires_x.OptionList import WellDrillingCostCorrelation
1714
from geophires_x_client import GeophiresXClient
@@ -24,7 +21,10 @@
2421
from geophires_x_client.geophires_input_parameters import ImmutableGeophiresInputParameters
2522
from geophires_x_tests.test_options_list import WellDrillingCostCorrelationTestCase
2623

27-
# @formatter:on
24+
# noinspection PyProtectedMember
25+
# ruff: noqa: I001 # Successful module initialization is dependent on this specific import order.
26+
from geophires_x.EconomicsSam import _cash_flow_profile_row
27+
2828
from tests.base_test_case import BaseTestCase
2929

3030

@@ -1338,7 +1338,7 @@ def test_royalty_rate(self):
13381338

13391339
self.assertEqual(opex_line_item_sum, total_opex_MUSD)
13401340

1341-
econ_result = result.result['ECONOMIC PARAMETERS']
1341+
econ_result = result.result['EXTENDED ECONOMICS']
13421342
royalty_holder_npv_MUSD = econ_result['Royalty Holder NPV']['value']
13431343

13441344
if royalty_rate > 0.0:

0 commit comments

Comments
 (0)