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.8
current_version = 3.13.9
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.8
version: 3.13.9
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.9: `Add hip-ra-x-result.json schema and HipRaXResult <https://github.com/softwareengineerprogrammer/GEOPHIRES/pull/157>`__ | `release <https://github.com/NREL/GEOPHIRES-X/releases/tag/v3.13.9>`__

3.13.8: `Fix drilling cost types output unit conversion issue; Project Location (Latitude & Longitude); SHR Example 3 update <https://github.com/NatLabRockies/GEOPHIRES-X/pull/497>`__ | `release <https://github.com/NREL/GEOPHIRES-X/releases/tag/v3.13.8>`__

3.13.5: `Fix CHP Electrical Plant Cost Allocation Ratio check for non-cogen end-use option with fixed Surface Plant Capital Cost. Add example_SHR-3. <https://github.com/NatLabRockies/GEOPHIRES-X/pull/496>`__ | `release <https://github.com/NREL/GEOPHIRES-X/releases/tag/v3.13.5>`__
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.8.svg
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.13.9.svg
:alt: Commits since latest release
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.13.8...main
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.13.9...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.8'
version = release = '3.13.9'

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.8',
version='3.13.9',
license='MIT',
description='GEOPHIRES is a free and open-source geothermal techno-economic simulator.',
long_description='{}\n{}'.format(
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.8'
__version__ = '3.13.9'
1 change: 1 addition & 0 deletions src/geophires_x_schema_generator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ all_messages_conf.log
!geophires-request.json
!geophires-result.json
!hip-ra-x-request.json
!hip-ra-x-result.json
85 changes: 39 additions & 46 deletions src/geophires_x_schema_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import json
import os
import sys
from pathlib import Path
from typing import Tuple, Any
from typing import Any, Callable

# Ruff disabled because imports are order-dependent
# ruff: noqa: I001
Expand Down Expand Up @@ -38,7 +40,8 @@

class GeophiresXSchemaGenerator:
def __init__(self):
pass
# noinspection PyProtectedMember
self.result_fields_by_category: dict[str, list[Any]] = GeophiresXResult._RESULT_FIELDS_BY_CATEGORY

@staticmethod
def _get_dummy_model():
Expand Down Expand Up @@ -85,7 +88,7 @@ def get_parameter_sources(self) -> list:
def get_schema_title(self) -> str:
return 'GEOPHIRES'

def get_parameters_json(self) -> Tuple[str, str]:
def get_parameters_json(self) -> tuple[str, str]:

def with_category(param_dict: dict, category: str):
def _with_cat(p: Parameter, cat: str):
Expand All @@ -103,10 +106,10 @@ def _with_cat(p: Parameter, cat: str):

return json_dumpse(input_params), json_dumpse(output_params)

def generate_json_schema(self) -> Tuple[dict, dict]:
def generate_json_schema(self) -> tuple[dict, dict]:
"""
:return: request schema, result schema
:rtype: Tuple[dict, dict]
:rtype: tuple[dict, dict]
"""
input_params_json, output_params_json = self.get_parameters_json()
input_params = json.loads(input_params_json)
Expand Down Expand Up @@ -165,11 +168,10 @@ def get_result_json_schema(self, output_params_json) -> dict:

output_params = {**output_params, **display_name_aliases}

# noinspection PyProtectedMember
for category in GeophiresXResult._RESULT_FIELDS_BY_CATEGORY:
for category in self.result_fields_by_category:
cat_properties = {}
# noinspection PyProtectedMember
for field in GeophiresXResult._RESULT_FIELDS_BY_CATEGORY[category]:

for field in self.result_fields_by_category[category]:
param_name = field if isinstance(field, str) else field.field_name

ignored_output_param_names = ['After-Tax IRR'] # Silently ignored in favor of "After-tax IRR"
Expand Down Expand Up @@ -357,7 +359,7 @@ def _get_key(param: dict, k: str, default_val='') -> Any:
return default_val


def _get_min_and_max(param: dict, default_val='') -> Tuple:
def _get_min_and_max(param: dict, default_val='') -> tuple:
min_val = _get_key(param, 'Min', default_val=default_val)
max_val = _get_key(param, 'Max', default_val=default_val)

Expand All @@ -377,8 +379,34 @@ def _fix_floating_point_error(val: Any) -> Any:


class HipRaXSchemaGenerator(GeophiresXSchemaGenerator):
"""
TODO fix JSON & RST metadata generation for outputs that are also inputs (like Reservoir Depth) - currently only
Names are correctly processed
"""

def __init__(self):
dummy_model = HIP_RA_X()

def _get_result_fields_for_category(
output_config: list[tuple[Parameter, Callable[[Parameter], str]]],
) -> list[Any]:
return [it[0].Name for it in output_config]

# noinspection PyProtectedMember
self.result_fields_by_category: dict[str, list[Any]] = {
HIP_RA_X._SUMMARY_OF_RESULTS_OUTPUT_CATEGORY: _get_result_fields_for_category(
dummy_model._get_output_config_for_summary_of_results_category(None, None)
),
HIP_RA_X._SUMMARY_OF_INPUTS_OUTPUT_CATEGORY: _get_result_fields_for_category(
dummy_model._get_output_config_for_summary_of_inputs_category(None, None)
),
}

def get_parameter_sources(self) -> list:
"""
Single implicit input category used to keep the result schema shape consistent
with the GEOPHIRES result schema (top-level properties -> category -> properties -> fields).

:rtype: list[Tuple[Any, str]]
"""
dummy_model = HIP_RA_X()
Expand All @@ -387,43 +415,8 @@ def get_parameter_sources(self) -> list:
def get_schema_title(self) -> str:
return 'HIP-RA-X'

def get_result_json_schema(self, output_params_json) -> dict:
return None # FIXME TODO

def get_output_params_table_rst(self, output_params_json) -> str:
"""
FIXME TODO consolidate with generated result schema
"""

output_params = json.loads(output_params_json)

output_rst = """
.. list-table:: Outputs
:header-rows: 1

* - Name
- Description
- Preferred Units
- Default Value Type"""

for param_name in output_params:
param = output_params[param_name]

def get_key(k):
if k in param and str(param[k]) != '': # noqa
return param[k] # noqa
else:
return ''

output_rst += f"""\n * - {param['Name']}
- {get_key('ToolTipText')}
- {get_key('PreferredUnits')}
- {get_key('json_parameter_type')}"""

return output_rst

def get_input_schema_reference(self) -> str:
return 'hip-ra-x-request.json'

def get_output_schema_reference(self) -> str:
return None
return 'hip-ra-x-result.json'
130 changes: 130 additions & 0 deletions src/geophires_x_schema_generator/hip-ra-x-result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "HIP-RA-X Result Schema",
"required": [],
"properties": {
"SUMMARY OF RESULTS": {
"type": "object",
"properties": {
"Reservoir Depth": {},
"Reservoir Pressure": {},
"Reservoir Volume (reservoir)": {
"type": "number",
"description": "",
"units": "km**3"
},
"Reservoir Volume (rock)": {
"type": "number",
"description": "",
"units": "km**3"
},
"Recoverable Volume (recoverable fluid)": {
"type": "number",
"description": "",
"units": "km**3"
},
"Stored Heat (reservoir)": {
"type": "number",
"description": "",
"units": "kJ"
},
"Stored Heat (rock)": {
"type": "number",
"description": "",
"units": "kJ"
},
"Stored Heat (fluid)": {
"type": "number",
"description": "",
"units": "kJ"
},
"Mass of Reservoir (rock)": {
"type": "number",
"description": "",
"units": "kilogram"
},
"Mass of Reservoir (fluid)": {
"type": "number",
"description": "",
"units": "kilogram"
},
"Specific Enthalpy (reservoir)": {
"type": "number",
"description": "",
"units": "kJ/kg"
},
"Specific Enthalpy (rock)": {
"type": "number",
"description": "",
"units": "kJ/kg"
},
"Specific Enthalpy (fluid)": {
"type": "number",
"description": "",
"units": "kJ/kg"
},
"Recovery Factor (reservoir)": {
"type": "number",
"description": "",
"units": "%"
},
"Available Heat (reservoir)": {
"type": "number",
"description": "",
"units": "kJ"
},
"Producible Heat (reservoir)": {
"type": "number",
"description": "",
"units": "kJ"
},
"Producible Heat/Unit Area (reservoir)": {
"type": "number",
"description": "",
"units": "kJ/km**2"
},
"Producible Heat/Unit Volume (reservoir)": {
"type": "number",
"description": "",
"units": "kJ/km**3"
},
"Producible Electricity (reservoir)": {
"type": "number",
"description": "",
"units": "MW"
},
"Producible Electricity/Unit Area (reservoir)": {
"type": "number",
"description": "",
"units": "MW/km**2"
},
"Producible Electricity/Unit Volume (reservoir)": {
"type": "number",
"description": "",
"units": "MW/km**3"
}
}
},
"SUMMARY OF INPUTS": {
"type": "object",
"properties": {
"Reservoir Temperature": {},
"Rejection Temperature": {},
"Reservoir Porosity": {},
"Reservoir Area": {},
"Reservoir Thickness": {},
"Reservoir Life Cycle": {},
"Rock Heat Capacity": {},
"Fluid Specific Heat Capacity": {},
"Density Of Reservoir Fluid": {},
"Density Of Reservoir Rock": {},
"Recoverable Fluid Factor": {},
"Recoverable Heat from Rock": {},
"Reservoir Depth": {},
"Reservoir Pressure": {}
}
}
}
}
1 change: 1 addition & 0 deletions src/hip_ra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path
from typing import Any

# noinspection PyProtectedMember
from geophires_x_client.common import _get_logger
from hip_ra import HIP_RA

Expand Down
10 changes: 7 additions & 3 deletions src/hip_ra_x/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from hip_ra import HipRaInputParameters
from hip_ra import HipRaResult
from hip_ra_x import hip_ra_x
from hip_ra_x.hip_ra_x_result import HipRaXResult


class HipRaXClient:
Expand All @@ -20,14 +21,17 @@ def get_hip_ra_result(self, input_params: HipRaInputParameters) -> HipRaResult:
try:
hip_ra_x.main(enable_hip_ra_logging_config=False)
except Exception as e:
raise RuntimeError(f'HIP-RA encountered an exception: {e!s}') from e
raise RuntimeError(f'HIP-RA-X encountered an exception: {e!s}') from e
except SystemExit:
raise RuntimeError('HIP-RA exited without giving a reason') from None
raise RuntimeError('HIP-RA-X exited without giving a reason') from None
finally:
# Undo HIP-RA internal global settings changes
sys.argv = stash_sys_argv
os.chdir(stash_cwd)

self._logger.info(f'HIP-RA output file: {input_params.output_file_path}')
self._logger.info(f'HIP-RA-X output file: {input_params.output_file_path}')

return HipRaResult(input_params.output_file_path)

def get_hip_ra_x_result(self, input_params: HipRaInputParameters) -> HipRaXResult:
return HipRaXResult.from_hip_ra_result(self.get_hip_ra_result(input_params))
Loading
Loading