Skip to content

Commit b5b7cfd

Browse files
consolidate tabulation into shared method
1 parent 63e228b commit b5b7cfd

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/geophires_x/EconomicsSam.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
# noinspection PyPackageRequirements
2323
import PySAM.Utilityrate5 as UtilityRate
24+
from tabulate import tabulate
2425

2526
import geophires_x.Model as Model
27+
from geophires_x import Model as Model
2628
from geophires_x.EconomicsSamCashFlow import _calculate_sam_economics_cash_flow
2729
from geophires_x.Parameter import Parameter
2830
from geophires_x.Units import convertible_unit
@@ -89,6 +91,16 @@ def calculate_sam_economics(model: Model) -> dict[str, dict[str, Any]]:
8991
return ret
9092

9193

94+
def get_sam_cash_flow_profile_tabulated_output(model: Model, **tabulate_kw_args) -> str:
95+
"""
96+
Note model must have already calculated economics for this to work (used in Outputs)
97+
"""
98+
99+
_tabulate_kw_args = {'tablefmt': 'tsv', 'floatfmt': '.2f', 'intfmt': ',', **tabulate_kw_args}
100+
101+
return tabulate(model.economics.sam_economics.value[_SAM_CASH_FLOW_PROFILE_KEY], **_tabulate_kw_args)
102+
103+
92104
def _get_utility_rate_parameters(model: Model) -> dict[str, Any]:
93105
econ = model.economics
94106

src/geophires_x/EconomicsSamCashFlow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from PySAM import Singleowner
1212

13-
from geophires_x import Model as Model
13+
import geophires_x.Model as Model
1414

1515

1616
@lru_cache(maxsize=12)

src/geophires_x/Outputs.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import geophires_x
1010
import geophires_x.Model as Model
1111
from geophires_x.Economics import Economics
12-
from geophires_x.EconomicsSam import _SAM_CASH_FLOW_PROFILE_KEY
12+
from geophires_x.EconomicsSam import get_sam_cash_flow_profile_tabulated_output
1313
from geophires_x.OutputsRich import print_outputs_rich
1414
from geophires_x.Parameter import ConvertUnitsBack, ConvertOutputUnits, LookupUnits, strParameter, boolParameter, \
1515
OutputParameter, ReadParameter
@@ -770,16 +770,7 @@ def get_sam_cash_flow_profile_output(self, model):
770770
ret += ' * SAM CASH FLOW PROFILE *\n'
771771
ret += ' ***************************\n'
772772

773-
ret += tabulate(
774-
model.economics.sam_economics.value[_SAM_CASH_FLOW_PROFILE_KEY],
775-
# tablefmt='pretty',
776-
# tablefmt='psql',
777-
# tablefmt='simple_grid',
778-
#tablefmt='fancy_grid',
779-
tablefmt='tsv',
780-
floatfmt='.2f',
781-
# headers='keys'
782-
)
773+
ret += get_sam_cash_flow_profile_tabulated_output(model)
783774

784775
return ret
785776

tests/geophires_x_tests/test_economics_sam.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from pathlib import Path
66
from typing import Any
77

8-
from tabulate import tabulate
98

109
from base_test_case import BaseTestCase
1110

@@ -18,6 +17,7 @@
1817
_sig_figs,
1918
_SAM_CASH_FLOW_PROFILE_KEY,
2019
_GEOPHIRES_TO_SAM_PRICING_MODEL_RATE_CONVERSION_CONSTANT,
20+
get_sam_cash_flow_profile_tabulated_output,
2121
)
2222

2323
# noinspection PyProtectedMember
@@ -81,13 +81,13 @@ def test_cash_flow(self):
8181
self.assertIsNotNone(cash_flow)
8282

8383
print(
84-
tabulate(
85-
cash_flow,
84+
get_sam_cash_flow_profile_tabulated_output(
85+
m,
86+
# cash_flow,
8687
# tablefmt='pretty',
8788
# tablefmt='psql',
8889
# tablefmt='simple_grid',
8990
tablefmt='fancy_grid',
90-
floatfmt='.2f',
9191
# headers='keys'
9292
)
9393
)

0 commit comments

Comments
 (0)