Skip to content

Commit 38a1aeb

Browse files
handle comment parameters
1 parent 18021a0 commit 38a1aeb

7 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/geophires_docs/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from pint.facets.plain import PlainQuantity
1010

11+
from geophires_x.ParameterUtils import COMMENT_PARAMETER_NAME_PREFIX
1112
from geophires_x_client import GeophiresInputParameters
1213
from geophires_x_client import GeophiresXClient
1314
from geophires_x_client import GeophiresXResult
@@ -77,7 +78,7 @@ def _get_input_parameters_dict( # TODO consolidate with FervoProjectCape5TestCa
7778
ret[field] = fieldValue.strip()
7879

7980
if include_line_comments and field.startswith('#'):
80-
ret[f'_COMMENT-{comment_idx}'] = line.strip()
81+
ret[f'{COMMENT_PARAMETER_NAME_PREFIX}{comment_idx}'] = line.strip()
8182
comment_idx += 1
8283

8384
# TODO preserve newlines

src/geophires_docs/generate_fervo_project_cape_5_md.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from geophires_docs import _get_project_root
2525
from geophires_x.GeoPHIRESUtils import is_int
2626
from geophires_x.GeoPHIRESUtils import sig_figs
27+
from geophires_x.ParameterUtils import COMMENT_PARAMETER_NAME_PREFIX
2728
from geophires_x_client import GeophiresInputParameters
2829
from geophires_x_client import GeophiresXResult
2930
from geophires_x_client import ImmutableGeophiresInputParameters
@@ -219,7 +220,7 @@ def get_fpc_category_parameters_table_md(
219220

220221
table_entries = []
221222
for param_name, param_val_comment in input_params_dict.items():
222-
if param_name.startswith(('#', '_COMMENT-')):
223+
if param_name.startswith(('#', COMMENT_PARAMETER_NAME_PREFIX)):
223224
continue
224225

225226
if param_name in parameters_to_exclude:

src/geophires_x/ParameterUtils.py

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

1010
_log = logging.getLogger(__name__)
1111

12+
COMMENT_PARAMETER_NAME_PREFIX = '_COMMENT-'
13+
1214

1315
def expand_schedule_dsl(
1416
schedule_strings: list[str | float], total_years: int, allow_schedule_length_to_exceed_total_years: bool = False

src/geophires_x_client/geophires_input_parameters.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from typing_extensions import override
1818

19+
from geophires_x.ParameterUtils import COMMENT_PARAMETER_NAME_PREFIX
20+
1921

2022
class EndUseOption(Enum):
2123
"""
@@ -248,8 +250,12 @@ def _row_entries(param_name: str, param_value_raw: str) -> list[str]:
248250
units_entry = ''
249251
comment_entry = ''
250252

251-
if parse_units_and_comments:
253+
if param_name.startswith(COMMENT_PARAMETER_NAME_PREFIX):
254+
comment_entry = param_value_raw
255+
value_entry = ''
256+
elif parse_units_and_comments:
252257
# TODO consolidate with other codebase parameter parsing logic...
258+
253259
param_schema = request_schema['properties'].get(param_name, {param_name: {}})
254260
is_array_type = param_schema.get('type') == 'array'
255261

tests/geophires_x_tests/test_fervo_project_cape_5.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from geophires_x.GeoPHIRESUtils import quantity
1313
from geophires_x.GeoPHIRESUtils import sig_figs
1414
from geophires_x.Parameter import HasQuantity
15+
from geophires_x.ParameterUtils import COMMENT_PARAMETER_NAME_PREFIX
1516
from geophires_x_client import GeophiresInputParameters
1617
from geophires_x_client import GeophiresXClient
1718
from geophires_x_client import GeophiresXResult
@@ -85,7 +86,7 @@ def _get_input_parameters(
8586
ret[field] = fieldValue.strip()
8687

8788
if include_line_comments and field.startswith('#'):
88-
ret[f'_COMMENT-{comment_idx}'] = line.strip()
89+
ret[f'{COMMENT_PARAMETER_NAME_PREFIX}{comment_idx}'] = line.strip()
8990
comment_idx += 1
9091

9192
# TODO preserve newlines

tests/input-parameters-with-parsed-units-and-comments.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
INPUT PARAMETERS,_COMMENT-0,,,,# My parameters
12
INPUT PARAMETERS,Reservoir Depth,,3000,m,
23
INPUT PARAMETERS,Gradient 1,,50,degC/km,
34
INPUT PARAMETERS,End-Use Option,,1,,Direct-Use Heat

tests/test_geophires_x_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ def test_csv_with_input_parameters(self):
671671
def test_csv_with_input_parameters_parse_units_and_comments(self):
672672
csv_input_with_units_and_comments = ImmutableGeophiresInputParameters(
673673
params={
674+
'_COMMENT-0': '# My parameters',
674675
'Reservoir Depth': '3000 m',
675676
'Gradient 1': 50,
676677
'End-Use Option': '1, -- Direct-Use Heat',

0 commit comments

Comments
 (0)