Skip to content

Commit 28079c4

Browse files
Parse reservoir volume calculation note in GeophiresXResult
1 parent 94a5c5f commit 28079c4

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/geophires_x_client/geophires_x_result.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def __init__(self, field_name: str):
2727
self.field_name: str = field_name
2828

2929

30+
class _UnlabeledStringField:
31+
def __init__(self, field_name: str, marker_prefixes: list[str]):
32+
self.field_name: str = field_name
33+
self.marker_prefixes = marker_prefixes
34+
35+
3036
class GeophiresXResult:
3137
_RESULT_FIELDS_BY_CATEGORY = MappingProxyType(
3238
{
@@ -173,7 +179,15 @@ class GeophiresXResult:
173179
'Fracture area',
174180
'Number of fractures',
175181
'Fracture separation',
176-
# TODO reservoir volume note
182+
_UnlabeledStringField(
183+
'Reservoir volume calculation note',
184+
[
185+
'Reservoir volume calculated',
186+
'Number of fractures calculated',
187+
'Fracture separation calculated',
188+
'Reservoir volume provided as input',
189+
],
190+
),
177191
'Reservoir volume',
178192
'Reservoir impedance',
179193
'Reservoir hydrostatic pressure',
@@ -377,6 +391,10 @@ def __init__(self, output_file_path, logger_name=None):
377391
for field in fields:
378392
if isinstance(field, _EqualSignDelimitedField):
379393
self.result[category][field.field_name] = self._get_equal_sign_delimited_field(field.field_name)
394+
elif isinstance(field, _UnlabeledStringField):
395+
self.result[category][field.field_name] = self._get_unlabeled_string_field(
396+
field.field_name, field.marker_prefixes
397+
)
380398
else:
381399
is_string_field = isinstance(field, _StringValueField)
382400
field_name = field.field_name if is_string_field else field
@@ -596,6 +614,27 @@ def _get_equal_sign_delimited_field(self, field_name):
596614
self._logger.error(f'Unexpected error extracting equal sign-delimited field {field_name}') # Shouldn't happen
597615
return None
598616

617+
def _get_unlabeled_string_field(self, field_name: str, marker_prefixes: list[str]):
618+
matching_lines = set(filter(lambda line: any(m in line for m in marker_prefixes), self._lines))
619+
620+
if len(matching_lines) == 0:
621+
self._logger.debug(f'Unlabeled string field not found: {field_name}')
622+
return None
623+
624+
if len(matching_lines) > 1:
625+
self._logger.warning(
626+
f'Found multiple ({len(matching_lines)}) entries for unlabeled string field: '
627+
f'{field_name}\n\t{matching_lines}'
628+
)
629+
630+
matching_line = matching_lines.pop()
631+
for marker_prefix in marker_prefixes:
632+
if marker_prefix in matching_line:
633+
return matching_line.strip()
634+
635+
self._logger.error(f'Unexpected error extracting unlabeled string field {field_name}') # Shouldn't happen
636+
return None
637+
599638
@property
600639
def power_generation_profile(self):
601640
return self.result['POWER GENERATION PROFILE']

tests/geophires_x_client_tests/test_geophires_x_result.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ def test_get_sam_cash_flow_row_name_unit_split(self) -> None:
1515
with self.subTest(msg=case[0]):
1616
actual = GeophiresXResult._get_sam_cash_flow_row_name_unit_split(case[0])
1717
self.assertListEqual(actual, case[1])
18+
19+
def test_reservoir_volume_calculation_note(self):
20+
r: GeophiresXResult = GeophiresXResult(self._get_test_file_path('../examples/example2.out'))
21+
field_name = 'Reservoir volume calculation note'
22+
self.assertIn(field_name, r.result['RESERVOIR PARAMETERS'])
23+
self.assertEqual(
24+
r.result['RESERVOIR PARAMETERS'][field_name],
25+
'Number of fractures calculated with reservoir volume and fracture separation as input',
26+
)

0 commit comments

Comments
 (0)