Skip to content

Commit c87714e

Browse files
Merge pull request #157 from softwareengineerprogrammer/hip-ra-x-result-json-schema-2
Add hip-ra-x-result.json schema and HipRaXResult [v3.13.9]
2 parents 7b0c97e + b8368ef commit c87714e

15 files changed

Lines changed: 309 additions & 110 deletions

File tree

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.13.8
2+
current_version = 3.13.9
33
commit = True
44
tag = True
55

.cookiecutterrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ default_context:
5454
sphinx_doctest: "no"
5555
sphinx_theme: "sphinx-py3doc-enhanced-theme"
5656
test_matrix_separate_coverage: "no"
57-
version: 3.13.8
57+
version: 3.13.9
5858
version_manager: "bump2version"
5959
website: "https://github.com/NREL"
6060
year_from: "2023"

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ GEOPHIRES v3 (2023-2026)
88
3.13
99
^^^^
1010

11+
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>`__
12+
1113
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>`__
1214

1315
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>`__

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ Free software: `MIT license <LICENSE>`__
5858
:alt: Supported implementations
5959
:target: https://pypi.org/project/geophires-x
6060

61-
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.13.8.svg
61+
.. |commits-since| image:: https://img.shields.io/github/commits-since/softwareengineerprogrammer/GEOPHIRES-X/v3.13.9.svg
6262
:alt: Commits since latest release
63-
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.13.8...main
63+
:target: https://github.com/softwareengineerprogrammer/GEOPHIRES-X/compare/v3.13.9...main
6464

6565
.. |docs| image:: https://readthedocs.org/projects/GEOPHIRES-X/badge/?style=flat
6666
:target: https://softwareengineerprogrammer.github.io/GEOPHIRES

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
year = '2025'
1919
author = 'NREL'
2020
copyright = f'{year}, {author}'
21-
version = release = '3.13.8'
21+
version = release = '3.13.9'
2222

2323
pygments_style = 'trac'
2424
templates_path = ['./templates']

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def read(*names, **kwargs):
1313

1414
setup(
1515
name='geophires-x',
16-
version='3.13.8',
16+
version='3.13.9',
1717
license='MIT',
1818
description='GEOPHIRES is a free and open-source geothermal techno-economic simulator.',
1919
long_description='{}\n{}'.format(

src/geophires_x/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.13.8'
1+
__version__ = '3.13.9'

src/geophires_x_schema_generator/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ all_messages_conf.log
33
!geophires-request.json
44
!geophires-result.json
55
!hip-ra-x-request.json
6+
!hip-ra-x-result.json

src/geophires_x_schema_generator/__init__.py

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from __future__ import annotations
2+
13
import json
24
import os
35
import sys
46
from pathlib import Path
5-
from typing import Tuple, Any
7+
from typing import Any, Callable
68

79
# Ruff disabled because imports are order-dependent
810
# ruff: noqa: I001
@@ -38,7 +40,8 @@
3840

3941
class GeophiresXSchemaGenerator:
4042
def __init__(self):
41-
pass
43+
# noinspection PyProtectedMember
44+
self.result_fields_by_category: dict[str, list[Any]] = GeophiresXResult._RESULT_FIELDS_BY_CATEGORY
4245

4346
@staticmethod
4447
def _get_dummy_model():
@@ -85,7 +88,7 @@ def get_parameter_sources(self) -> list:
8588
def get_schema_title(self) -> str:
8689
return 'GEOPHIRES'
8790

88-
def get_parameters_json(self) -> Tuple[str, str]:
91+
def get_parameters_json(self) -> tuple[str, str]:
8992

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

104107
return json_dumpse(input_params), json_dumpse(output_params)
105108

106-
def generate_json_schema(self) -> Tuple[dict, dict]:
109+
def generate_json_schema(self) -> tuple[dict, dict]:
107110
"""
108111
:return: request schema, result schema
109-
:rtype: Tuple[dict, dict]
112+
:rtype: tuple[dict, dict]
110113
"""
111114
input_params_json, output_params_json = self.get_parameters_json()
112115
input_params = json.loads(input_params_json)
@@ -165,11 +168,10 @@ def get_result_json_schema(self, output_params_json) -> dict:
165168

166169
output_params = {**output_params, **display_name_aliases}
167170

168-
# noinspection PyProtectedMember
169-
for category in GeophiresXResult._RESULT_FIELDS_BY_CATEGORY:
171+
for category in self.result_fields_by_category:
170172
cat_properties = {}
171-
# noinspection PyProtectedMember
172-
for field in GeophiresXResult._RESULT_FIELDS_BY_CATEGORY[category]:
173+
174+
for field in self.result_fields_by_category[category]:
173175
param_name = field if isinstance(field, str) else field.field_name
174176

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

359361

360-
def _get_min_and_max(param: dict, default_val='') -> Tuple:
362+
def _get_min_and_max(param: dict, default_val='') -> tuple:
361363
min_val = _get_key(param, 'Min', default_val=default_val)
362364
max_val = _get_key(param, 'Max', default_val=default_val)
363365

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

378380

379381
class HipRaXSchemaGenerator(GeophiresXSchemaGenerator):
382+
"""
383+
TODO fix JSON & RST metadata generation for outputs that are also inputs (like Reservoir Depth) - currently only
384+
Names are correctly processed
385+
"""
386+
387+
def __init__(self):
388+
dummy_model = HIP_RA_X()
389+
390+
def _get_result_fields_for_category(
391+
output_config: list[tuple[Parameter, Callable[[Parameter], str]]],
392+
) -> list[Any]:
393+
return [it[0].Name for it in output_config]
394+
395+
# noinspection PyProtectedMember
396+
self.result_fields_by_category: dict[str, list[Any]] = {
397+
HIP_RA_X._SUMMARY_OF_RESULTS_OUTPUT_CATEGORY: _get_result_fields_for_category(
398+
dummy_model._get_output_config_for_summary_of_results_category(None, None)
399+
),
400+
HIP_RA_X._SUMMARY_OF_INPUTS_OUTPUT_CATEGORY: _get_result_fields_for_category(
401+
dummy_model._get_output_config_for_summary_of_inputs_category(None, None)
402+
),
403+
}
404+
380405
def get_parameter_sources(self) -> list:
381406
"""
407+
Single implicit input category used to keep the result schema shape consistent
408+
with the GEOPHIRES result schema (top-level properties -> category -> properties -> fields).
409+
382410
:rtype: list[Tuple[Any, str]]
383411
"""
384412
dummy_model = HIP_RA_X()
@@ -387,43 +415,8 @@ def get_parameter_sources(self) -> list:
387415
def get_schema_title(self) -> str:
388416
return 'HIP-RA-X'
389417

390-
def get_result_json_schema(self, output_params_json) -> dict:
391-
return None # FIXME TODO
392-
393-
def get_output_params_table_rst(self, output_params_json) -> str:
394-
"""
395-
FIXME TODO consolidate with generated result schema
396-
"""
397-
398-
output_params = json.loads(output_params_json)
399-
400-
output_rst = """
401-
.. list-table:: Outputs
402-
:header-rows: 1
403-
404-
* - Name
405-
- Description
406-
- Preferred Units
407-
- Default Value Type"""
408-
409-
for param_name in output_params:
410-
param = output_params[param_name]
411-
412-
def get_key(k):
413-
if k in param and str(param[k]) != '': # noqa
414-
return param[k] # noqa
415-
else:
416-
return ''
417-
418-
output_rst += f"""\n * - {param['Name']}
419-
- {get_key('ToolTipText')}
420-
- {get_key('PreferredUnits')}
421-
- {get_key('json_parameter_type')}"""
422-
423-
return output_rst
424-
425418
def get_input_schema_reference(self) -> str:
426419
return 'hip-ra-x-request.json'
427420

428421
def get_output_schema_reference(self) -> str:
429-
return None
422+
return 'hip-ra-x-result.json'
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"definitions": {},
3+
"$schema": "http://json-schema.org/draft-04/schema#",
4+
"type": "object",
5+
"title": "HIP-RA-X Result Schema",
6+
"required": [],
7+
"properties": {
8+
"SUMMARY OF RESULTS": {
9+
"type": "object",
10+
"properties": {
11+
"Reservoir Depth": {},
12+
"Reservoir Pressure": {},
13+
"Reservoir Volume (reservoir)": {
14+
"type": "number",
15+
"description": "",
16+
"units": "km**3"
17+
},
18+
"Reservoir Volume (rock)": {
19+
"type": "number",
20+
"description": "",
21+
"units": "km**3"
22+
},
23+
"Recoverable Volume (recoverable fluid)": {
24+
"type": "number",
25+
"description": "",
26+
"units": "km**3"
27+
},
28+
"Stored Heat (reservoir)": {
29+
"type": "number",
30+
"description": "",
31+
"units": "kJ"
32+
},
33+
"Stored Heat (rock)": {
34+
"type": "number",
35+
"description": "",
36+
"units": "kJ"
37+
},
38+
"Stored Heat (fluid)": {
39+
"type": "number",
40+
"description": "",
41+
"units": "kJ"
42+
},
43+
"Mass of Reservoir (rock)": {
44+
"type": "number",
45+
"description": "",
46+
"units": "kilogram"
47+
},
48+
"Mass of Reservoir (fluid)": {
49+
"type": "number",
50+
"description": "",
51+
"units": "kilogram"
52+
},
53+
"Specific Enthalpy (reservoir)": {
54+
"type": "number",
55+
"description": "",
56+
"units": "kJ/kg"
57+
},
58+
"Specific Enthalpy (rock)": {
59+
"type": "number",
60+
"description": "",
61+
"units": "kJ/kg"
62+
},
63+
"Specific Enthalpy (fluid)": {
64+
"type": "number",
65+
"description": "",
66+
"units": "kJ/kg"
67+
},
68+
"Recovery Factor (reservoir)": {
69+
"type": "number",
70+
"description": "",
71+
"units": "%"
72+
},
73+
"Available Heat (reservoir)": {
74+
"type": "number",
75+
"description": "",
76+
"units": "kJ"
77+
},
78+
"Producible Heat (reservoir)": {
79+
"type": "number",
80+
"description": "",
81+
"units": "kJ"
82+
},
83+
"Producible Heat/Unit Area (reservoir)": {
84+
"type": "number",
85+
"description": "",
86+
"units": "kJ/km**2"
87+
},
88+
"Producible Heat/Unit Volume (reservoir)": {
89+
"type": "number",
90+
"description": "",
91+
"units": "kJ/km**3"
92+
},
93+
"Producible Electricity (reservoir)": {
94+
"type": "number",
95+
"description": "",
96+
"units": "MW"
97+
},
98+
"Producible Electricity/Unit Area (reservoir)": {
99+
"type": "number",
100+
"description": "",
101+
"units": "MW/km**2"
102+
},
103+
"Producible Electricity/Unit Volume (reservoir)": {
104+
"type": "number",
105+
"description": "",
106+
"units": "MW/km**3"
107+
}
108+
}
109+
},
110+
"SUMMARY OF INPUTS": {
111+
"type": "object",
112+
"properties": {
113+
"Reservoir Temperature": {},
114+
"Rejection Temperature": {},
115+
"Reservoir Porosity": {},
116+
"Reservoir Area": {},
117+
"Reservoir Thickness": {},
118+
"Reservoir Life Cycle": {},
119+
"Rock Heat Capacity": {},
120+
"Fluid Specific Heat Capacity": {},
121+
"Density Of Reservoir Fluid": {},
122+
"Density Of Reservoir Rock": {},
123+
"Recoverable Fluid Factor": {},
124+
"Recoverable Heat from Rock": {},
125+
"Reservoir Depth": {},
126+
"Reservoir Pressure": {}
127+
}
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)