Skip to content

Commit 1802f98

Browse files
WIP - discount rate preferred/current unit issues
1 parent 04f9feb commit 1802f98

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

src/geophires_x/Economics.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import math
2+
import os
23
import sys
34
import numpy as np
45
import numpy_financial as npf
@@ -2147,15 +2148,38 @@ def read_parameters(self, model: Model) -> None:
21472148
if key.startswith("AddOn"):
21482149
self.DoAddOnCalculations.value = True
21492150
break
2151+
21502152
for key in model.InputParameters.keys():
21512153
if key.startswith("S-DAC-GT"):
21522154
self.DoSDACGTCalculations.value = True
21532155
break
21542156

21552157
coerce_int_params_to_enum_values(self.ParameterDict)
2158+
self.sync_discount_rate_and_fixed_internal_rate(model)
21562159

21572160
model.logger.info(f'complete {__class__!s}: {sys._getframe().f_code.co_name}')
21582161

2162+
def sync_discount_rate_and_fixed_internal_rate(self, model):
2163+
if self.discountrate.Provided ^ self.FixedInternalRate.Provided:
2164+
if self.discountrate.Provided:
2165+
self.FixedInternalRate.value = self.discountrate.quantity().to(
2166+
convertible_unit(self.FixedInternalRate.CurrentUnits)).magnitude
2167+
model.logger.info(f'Set {self.FixedInternalRate.Name} to {self.FixedInternalRate.quantity()} '
2168+
f'because {self.discountrate.Name} was provided ({self.discountrate.value})')
2169+
else:
2170+
self.discountrate.value = self.FixedInternalRate.quantity().to(
2171+
convertible_unit(self.discountrate.CurrentUnits)).magnitude
2172+
model.logger.info(
2173+
f'Set {self.discountrate.Name} to {self.discountrate.value} because '
2174+
f'{self.FixedInternalRate.Name} was provided ({self.FixedInternalRate.quantity()})')
2175+
2176+
if self.discountrate.Provided and self.FixedInternalRate.Provided \
2177+
and self.discountrate.quantity().to(convertible_unit(self.FixedInternalRate.CurrentUnits)).magnitude \
2178+
!= self.FixedInternalRate.value:
2179+
model.logger.warning(f'{self.discountrate.Name} and {self.FixedInternalRate.Name} provided with different '
2180+
f'values ({self.discountrate.value}; {self.FixedInternalRate.quantity()}). '
2181+
f'It is recommended to only provide one of these values.')
2182+
21592183
def Calculate(self, model: Model) -> None:
21602184
"""
21612185
The Calculate function is where all the calculations are done.

tests/test_geophires_x.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_geophires_x_end_use_direct_use_heat(self):
6666

6767
def test_geophires_x_end_use_electricity(self):
6868
client = GeophiresXClient()
69-
result = client.get_geophires_result(
69+
client.get_geophires_result(
7070
GeophiresInputParameters(
7171
{
7272
'Print Output to Console': 0,
@@ -80,9 +80,6 @@ def test_geophires_x_end_use_electricity(self):
8080
)
8181
)
8282

83-
assert result is not None
84-
assert result.result['metadata']['End-Use Option'] == 'ELECTRICITY'
85-
8683
def test_reservoir_model_2(self):
8784
client = GeophiresXClient()
8885
result = client.get_geophires_result(
@@ -537,3 +534,28 @@ def s(r):
537534

538535
# deprecated is ignored if both are present.
539536
self.assertDictEqual(both_params.result, non_deprecated_param.result)
537+
538+
def test_discount_rate_and_fixed_internal_rate(self):
539+
def input_params(discount_rate=None, fixed_internal_rate=None):
540+
params = {
541+
'End-Use Option': EndUseOption.ELECTRICITY.value,
542+
'Reservoir Model': 1,
543+
'Reservoir Depth': 3,
544+
'Gradient 1': 50,
545+
}
546+
547+
if discount_rate is not None:
548+
params['Discount Rate'] = discount_rate
549+
550+
if fixed_internal_rate is not None:
551+
params['Fixed Internal Rate'] = fixed_internal_rate
552+
553+
return GeophiresInputParameters(params)
554+
555+
client = GeophiresXClient()
556+
with self.assertLogs(level='INFO') as logs: # noqa: F841
557+
result = client.get_geophires_result(input_params(discount_rate='0.042'))
558+
559+
assert result is not None
560+
assert result.result['ECONOMIC PARAMETERS']['Interest Rate']['value'] == 4.2
561+
assert result.result['ECONOMIC PARAMETERS']['Interest Rate']['unit'] == '%'

0 commit comments

Comments
 (0)