Skip to content

Commit

Permalink
WIP - discount rate preferred/current unit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareengineerprogrammer committed Oct 11, 2024
1 parent 04f9feb commit 1802f98
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/geophires_x/Economics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import os
import sys
import numpy as np
import numpy_financial as npf
Expand Down Expand Up @@ -2147,15 +2148,38 @@ def read_parameters(self, model: Model) -> None:
if key.startswith("AddOn"):
self.DoAddOnCalculations.value = True
break

for key in model.InputParameters.keys():
if key.startswith("S-DAC-GT"):
self.DoSDACGTCalculations.value = True
break

coerce_int_params_to_enum_values(self.ParameterDict)
self.sync_discount_rate_and_fixed_internal_rate(model)

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

def sync_discount_rate_and_fixed_internal_rate(self, model):
if self.discountrate.Provided ^ self.FixedInternalRate.Provided:
if self.discountrate.Provided:
self.FixedInternalRate.value = self.discountrate.quantity().to(
convertible_unit(self.FixedInternalRate.CurrentUnits)).magnitude
model.logger.info(f'Set {self.FixedInternalRate.Name} to {self.FixedInternalRate.quantity()} '
f'because {self.discountrate.Name} was provided ({self.discountrate.value})')
else:
self.discountrate.value = self.FixedInternalRate.quantity().to(
convertible_unit(self.discountrate.CurrentUnits)).magnitude
model.logger.info(
f'Set {self.discountrate.Name} to {self.discountrate.value} because '
f'{self.FixedInternalRate.Name} was provided ({self.FixedInternalRate.quantity()})')

if self.discountrate.Provided and self.FixedInternalRate.Provided \
and self.discountrate.quantity().to(convertible_unit(self.FixedInternalRate.CurrentUnits)).magnitude \
!= self.FixedInternalRate.value:
model.logger.warning(f'{self.discountrate.Name} and {self.FixedInternalRate.Name} provided with different '
f'values ({self.discountrate.value}; {self.FixedInternalRate.quantity()}). '
f'It is recommended to only provide one of these values.')

def Calculate(self, model: Model) -> None:
"""
The Calculate function is where all the calculations are done.
Expand Down
30 changes: 26 additions & 4 deletions tests/test_geophires_x.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_geophires_x_end_use_direct_use_heat(self):

def test_geophires_x_end_use_electricity(self):
client = GeophiresXClient()
result = client.get_geophires_result(
client.get_geophires_result(
GeophiresInputParameters(
{
'Print Output to Console': 0,
Expand All @@ -80,9 +80,6 @@ def test_geophires_x_end_use_electricity(self):
)
)

assert result is not None
assert result.result['metadata']['End-Use Option'] == 'ELECTRICITY'

def test_reservoir_model_2(self):
client = GeophiresXClient()
result = client.get_geophires_result(
Expand Down Expand Up @@ -537,3 +534,28 @@ def s(r):

# deprecated is ignored if both are present.
self.assertDictEqual(both_params.result, non_deprecated_param.result)

def test_discount_rate_and_fixed_internal_rate(self):
def input_params(discount_rate=None, fixed_internal_rate=None):
params = {
'End-Use Option': EndUseOption.ELECTRICITY.value,
'Reservoir Model': 1,
'Reservoir Depth': 3,
'Gradient 1': 50,
}

if discount_rate is not None:
params['Discount Rate'] = discount_rate

if fixed_internal_rate is not None:
params['Fixed Internal Rate'] = fixed_internal_rate

return GeophiresInputParameters(params)

client = GeophiresXClient()
with self.assertLogs(level='INFO') as logs: # noqa: F841
result = client.get_geophires_result(input_params(discount_rate='0.042'))

assert result is not None
assert result.result['ECONOMIC PARAMETERS']['Interest Rate']['value'] == 4.2
assert result.result['ECONOMIC PARAMETERS']['Interest Rate']['unit'] == '%'

0 comments on commit 1802f98

Please sign in to comment.