Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.13.12
current_version = 3.13.13
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion .cookiecutterrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ default_context:
sphinx_doctest: "no"
sphinx_theme: "sphinx-py3doc-enhanced-theme"
test_matrix_separate_coverage: "no"
version: 3.13.12
version: 3.13.13
version_manager: "bump2version"
website: "https://github.com/NREL"
year_from: "2023"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ GEOPHIRES v3 (2023-2026)
3.13
^^^^

3.13.13: `Input params CSV unit and comment parsing <https://github.com/softwareengineerprogrammer/GEOPHIRES/pull/167>`__ | `release <https://github.com/NREL/GEOPHIRES-X/releases/tag/v3.13.13>`__

3.13.12: `Drawdown Parameter Schedule <https://github.com/softwareengineerprogrammer/GEOPHIRES/pull/166>`__ | `release <https://github.com/NREL/GEOPHIRES-X/releases/tag/v3.13.12>`__

3.13.10: `Well integrity parameterization to trigger redrilling <https://github.com/softwareengineerprogrammer/GEOPHIRES/pull/163>`__ | `release <https://github.com/NREL/GEOPHIRES-X/releases/tag/v3.13.10>`__
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ Free software: `MIT license <LICENSE>`__
:alt: Supported implementations
:target: https://pypi.org/project/geophires-x

.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.13.12.svg
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.13.13.svg
:alt: Commits since latest release
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.13.12...main
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.13.13...main

.. |docs| image:: https://readthedocs.org/projects/GEOPHIRES-X/badge/?style=flat
:target: https://softwareengineerprogrammer.github.io/GEOPHIRES
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
year = '2025'
author = 'NREL'
copyright = f'{year}, {author}'
version = release = '3.13.12'
version = release = '3.13.13'

pygments_style = 'trac'
templates_path = ['./templates']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def read(*names, **kwargs):

setup(
name='geophires-x',
version='3.13.12',
version='3.13.13',
license='MIT',
description='GEOPHIRES is a free and open-source geothermal techno-economic simulator.',
long_description='{}\n{}'.format(
Expand Down
3 changes: 2 additions & 1 deletion src/geophires_docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pint.facets.plain import PlainQuantity

from geophires_x.ParameterUtils import COMMENT_PARAMETER_NAME_PREFIX
from geophires_x_client import GeophiresInputParameters
from geophires_x_client import GeophiresXClient
from geophires_x_client import GeophiresXResult
Expand Down Expand Up @@ -77,7 +78,7 @@ def _get_input_parameters_dict( # TODO consolidate with FervoProjectCape5TestCa
ret[field] = fieldValue.strip()

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

# TODO preserve newlines
Expand Down
3 changes: 2 additions & 1 deletion src/geophires_docs/generate_fervo_project_cape_5_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from geophires_docs import _get_project_root
from geophires_x.GeoPHIRESUtils import is_int
from geophires_x.GeoPHIRESUtils import sig_figs
from geophires_x.ParameterUtils import COMMENT_PARAMETER_NAME_PREFIX
from geophires_x_client import GeophiresInputParameters
from geophires_x_client import GeophiresXResult
from geophires_x_client import ImmutableGeophiresInputParameters
Expand Down Expand Up @@ -219,7 +220,7 @@ def get_fpc_category_parameters_table_md(

table_entries = []
for param_name, param_val_comment in input_params_dict.items():
if param_name.startswith(('#', '_COMMENT-')):
if param_name.startswith(('#', COMMENT_PARAMETER_NAME_PREFIX)):
continue

if param_name in parameters_to_exclude:
Expand Down
2 changes: 2 additions & 0 deletions src/geophires_x/ParameterUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

_log = logging.getLogger(__name__)

COMMENT_PARAMETER_NAME_PREFIX: str = '_COMMENT-'


def expand_schedule_dsl(
schedule_strings: list[str | float], total_years: int, allow_schedule_length_to_exceed_total_years: bool = False
Expand Down
2 changes: 1 addition & 1 deletion src/geophires_x/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.13.12'
__version__ = '3.13.13'
70 changes: 68 additions & 2 deletions src/geophires_x_client/geophires_input_parameters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import csv
import json
import os
import tempfile
import uuid
from dataclasses import dataclass
Expand All @@ -8,12 +10,16 @@
from pathlib import Path
from types import MappingProxyType
from typing import Any
from typing import Dict
from typing import List
from typing import Mapping
from typing import Optional
from typing import Union

from typing_extensions import override

from geophires_x.ParameterUtils import COMMENT_PARAMETER_NAME_PREFIX


class EndUseOption(Enum):
"""
Expand Down Expand Up @@ -220,16 +226,76 @@ def get_output_file_path(self) -> Path:
"""Returns a unique path for the GEOPHIRES output file."""
return Path(tempfile.gettempdir(), f'geophires-result_{self._instance_id!s}.out')

def as_csv(self) -> str:
def as_csv(self, parse_units_and_comments: bool = False) -> str:
"""
This method returns the input parameters in CSV (Comma-Separated Values) format, using its
internal dictionary as the definitive source. It does not include a header, but uses the
same columns as GeophiresXResult.as_csv, and is meant to be used in conjunction with the same.
"""

if self.from_file_path:
raise NotImplementedError('CSV from file path is not implemented.')

if parse_units_and_comments:

def _get_file_path(file_name: Union[str, Path]) -> str:
return os.path.join(os.path.abspath(os.path.dirname(__file__)), str(file_name))

with open(_get_file_path('../geophires_x_schema_generator/geophires-request.json'), encoding='utf-8') as f:
request_schema: Dict[str, Any] = json.loads(f.read())

f = StringIO()
w = csv.writer(f)
w.writerows([['INPUT PARAMETERS', key, '', value, ''] for key, value in self.params.items()])

def _row_entries(param_name: str, param_value_raw: str) -> List[str]:
value_entry = (str(param_value_raw) if param_value_raw is not None else '').strip()
units_entry = ''
comment_entry = ''

if param_name.startswith(COMMENT_PARAMETER_NAME_PREFIX):
comment_entry = param_value_raw
value_entry = ''
elif parse_units_and_comments:
# TODO consolidate with other codebase parameter parsing logic...

param_schema = request_schema['properties'].get(param_name, {param_name: {}})
is_array_type = param_schema.get('type') == 'array'

value_non_value_split = (
value_entry.split(' ', maxsplit=1) if not is_array_type else value_entry.split(', --', maxsplit=1)
)
value_entry = value_non_value_split[0].rstrip(',').rstrip()
remainder = value_non_value_split[1] if len(value_non_value_split) > 1 else ''

default_units_for_param = param_schema.get('units', '')

if is_array_type:
# For array-type params, the ', --' split already consumed the comment delimiter;
# whatever remains is the comment (no units possible from the value string).
comment_entry = remainder.lstrip() if remainder else ''
units_entry = default_units_for_param
else:
# For scalar params, remainder is either "<units>" or "-- <comment>"
# (optionally "<units> -- <comment>").
unit_and_comment_split = remainder.split(' --', maxsplit=1) if remainder else ['']
units_part = unit_and_comment_split[0]
if units_part.lstrip().startswith('--'):
# No units, just an inline comment introduced by '-- '.
comment_entry = units_part.lstrip()[2:].lstrip()
units_entry = default_units_for_param
else:
units_entry = units_part if units_part != '' else default_units_for_param
if len(unit_and_comment_split) > 1:
comment_entry = unit_and_comment_split[1].lstrip()

return [
'INPUT PARAMETERS',
param_name,
'', # Year column, N/A for input parameters
value_entry,
units_entry,
comment_entry,
]

w.writerows([_row_entries(key, value) for key, value in self.params.items()])
return f.getvalue()
Loading
Loading