Skip to content

Commit 08cb6b6

Browse files
include GEOPHIRES-modeled temperature in graph
1 parent 43a8ddb commit 08cb6b6

1 file changed

Lines changed: 56 additions & 23 deletions

File tree

src/geophires_docs/generate_fervo_project_red_2026_docs.py

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
from geophires_docs import _PROJECT_ROOT
1111
from geophires_docs import _get_full_production_temperature_profile
12+
from geophires_docs import _get_input_parameters_dict
1213
from geophires_docs import _get_logger
14+
from geophires_x_client import GeophiresInputParameters
1315
from geophires_x_client import GeophiresXResult
1416
from geophires_x_client import ImmutableGeophiresInputParameters
1517

@@ -218,7 +220,6 @@ def _get_steady_state_mask(df_prod: pd.DataFrame, steady_state_start_years: floa
218220
mean_temp = float(np.mean(history))
219221
std_temp = float(np.std(history, ddof=1))
220222

221-
# Prevent excessively tight windows during flat extractions
222223
std_temp = max(std_temp, _STATISTICAL_MIN_STD)
223224

224225
if abs(temp - mean_temp) > _STATISTICAL_Z_SCORE * std_temp:
@@ -230,13 +231,13 @@ def _get_steady_state_mask(df_prod: pd.DataFrame, steady_state_start_years: floa
230231
return is_steady
231232

232233

233-
def _generate_production_temperature_graph_from_fervo_graph_data_csv_and_project_red_geophires_result_data(
234+
def _regenerate_graph_from_csv(
234235
production_csv_path: Path,
235236
model_csv_path: Path,
236-
# steady_state_csv_path: Path, # unused...
237+
steady_state_csv_path: Path,
237238
output_path: Path,
238239
steady_state_start_years: float = _STEADY_STATE_START_YEARS,
239-
# TODO/WIP pass GEOPHIRES production profile data
240+
geophires_data: pd.Series | None = None,
240241
) -> None:
241242
df_prod = pd.read_csv(production_csv_path)
242243
df_model = pd.read_csv(model_csv_path)
@@ -259,7 +260,7 @@ def _generate_production_temperature_graph_from_fervo_graph_data_csv_and_project
259260
alpha=0.85,
260261
label='Measured '
261262
# f'Flowing '
262-
'Temperature (Thermal Conditioning and Steady State)',
263+
'Temperature (Thermal Conditioning and Steady State)', # TODO exclude Thermal Conditioning
263264
# f', n={len(df_included)}',
264265
)
265266

@@ -284,32 +285,71 @@ def _generate_production_temperature_graph_from_fervo_graph_data_csv_and_project
284285
color='black',
285286
linestyle='--',
286287
linewidth=1.5,
287-
label='Fervo-Modeled Temperature',
288+
label='Fervo-Modeled Temperature' if geophires_data is not None else 'Modeled output',
288289
)
289290

291+
if geophires_data is not None:
292+
ax.plot(
293+
geophires_data.index,
294+
geophires_data.values,
295+
color='#1f77b4',
296+
linestyle='-.',
297+
linewidth=1.5,
298+
label='GEOPHIRES-Modeled Temperature (Gringarten)',
299+
)
300+
290301
ax.set_xlabel('Time (Years)', fontsize=12)
291-
ax.set_ylabel('Temperature (°C)', fontsize=12)
292-
ax.set_title(
293-
'Project Red Temperature: Measured vs. Fervo-Modeled' ' vs. GEOPHIRES-Modeled' '',
294-
fontsize=13,
295-
)
302+
ax.set_ylabel('Flowing Temperature (°C)', fontsize=12)
303+
304+
title = 'Fervo Project Red: Measured vs. Modeled Flowing Temperature (Regenerated)'
305+
if geophires_data is not None:
306+
title = 'Project Red Temperature: Measured vs. Fervo-Modeled vs. GEOPHIRES-Modeled'
307+
ax.set_title(title, fontsize=13)
296308

297309
ax.set_xlim(0.0, 2.0)
298310
ax.set_ylim(0.0, 200.0)
299311
ax.grid(True, linestyle='--', alpha=0.5)
300312

301-
# Position the legend below the graph, centered horizontally.
302313
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12), ncol=1, frameon=False, fontsize=11)
303314

304315
output_path.parent.mkdir(parents=True, exist_ok=True)
305316
fig.savefig(output_path, dpi=150, bbox_inches='tight')
306317
plt.close(fig)
307318

308319

309-
def _get_file_path(file_name) -> Path:
320+
def _get_file_path(file_name: str) -> Path:
310321
return Path(__file__).parent / file_name
311322

312323

324+
def get_project_red_production_temperature_profile_series() -> pd.Series:
325+
input_params: GeophiresInputParameters = ImmutableGeophiresInputParameters(
326+
from_file_path=_get_file_path('../../tests/examples/Fervo_Project_Red-2026.txt')
327+
)
328+
input_and_result = (
329+
input_params,
330+
GeophiresXResult(_get_file_path('../../tests/examples/Fervo_Project_Red-2026.out')),
331+
)
332+
333+
project_red_geophires_result_data: list = _get_full_production_temperature_profile(input_and_result)
334+
335+
# Fetch the 'Time' profile data to align exactly with the GEOPHIRES temperature curve
336+
time_steps_per_year: int = int(_get_input_parameters_dict(input_params)['Time steps per year'])
337+
geophires_time_data = [
338+
float(step) / float(time_steps_per_year) for step, _ in enumerate(project_red_geophires_result_data)
339+
]
340+
341+
geophires_x = geophires_time_data
342+
geophires_y = [q.magnitude for q in project_red_geophires_result_data]
343+
344+
# Interpolate the GEOPHIRES curve along the exact timestamps established by the model dashed line extraction
345+
geophires_interpolator = interp1d(geophires_x, geophires_y, kind='linear', fill_value='extrapolate')
346+
geophires_interpolated_y = geophires_interpolator(df_model['Time_Years'])
347+
348+
geophires_series = pd.Series(data=geophires_interpolated_y, index=df_model['Time_Years'])
349+
350+
return geophires_series
351+
352+
313353
if __name__ == '__main__':
314354
IMAGE_PATH = _get_file_path('fervo-project-red-2026_figure-5_measured-flowing-temperature.png')
315355
PRODUCTION_IMAGE_PATH = _get_file_path('fervo_project_red-2026_graph-data-extraction_production-series-edited.png')
@@ -346,18 +386,11 @@ def _get_file_path(file_name) -> Path:
346386
df_steady_state.to_csv(steady_state_csv_path, index=False)
347387
_log.info(f'Wrote variance analysis CSV: {steady_state_csv_path}')
348388

349-
project_red_geophires_result_data = _get_full_production_temperature_profile(
350-
ImmutableGeophiresInputParameters(
351-
from_file_path=_get_file_path('../../tests/examples/Fervo_Project_Red-2026.txt')
352-
),
353-
GeophiresXResult(_get_file_path('../../tests/examples/Fervo_Project_Red-2026.out')),
354-
)
355-
356-
_generate_production_temperature_graph_from_fervo_graph_data_csv_and_project_red_geophires_result_data(
389+
_regenerate_graph_from_csv(
357390
production_csv_path,
358391
model_csv_path,
359-
# steady_state_csv_path, # unused...
392+
steady_state_csv_path,
360393
regenerated_graph_path,
361-
# TODO/WIP pass project_red_geophires_result_data as series with interpolation matching csvs
394+
geophires_data=get_project_red_production_temperature_profile_series(),
362395
)
363396
_log.info(f'Wrote regenerated graph: {regenerated_graph_path}')

0 commit comments

Comments
 (0)