Skip to content

Commit c4400be

Browse files
Workaround for NREL#365 with show_plot utility method
1 parent 40dfdd8 commit c4400be

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/geophires_x/GeoPHIRESUtils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
from __future__ import annotations
22

33
import logging
4+
import os
45
import sys
56
from enum import Enum
67
from os.path import exists
78
import dataclasses
89
import json
910
import numbers
1011
from functools import lru_cache
12+
from tkinter import TclError
1113
from typing import Optional, Any
1214

1315
import scipy
1416
from pint.facets.plain import PlainQuantity
1517
from scipy.interpolate import interp1d
1618
import numpy as np
19+
import matplotlib.pyplot as plt
1720

1821
import CoolProp.CoolProp as CP
1922

@@ -621,3 +624,20 @@ def static_pressure_MPa(rho_kg_per_m3: float, depth_m: float) -> float:
621624

622625
return pressure_mpa
623626

627+
628+
def show_plot(**kw_args):
629+
"""
630+
Workaround for intermittent Windows GitHub Actions failures - see https://github.com/NREL/GEOPHIRES-X/issues/365
631+
"""
632+
try:
633+
plt.show(**kw_args)
634+
except Exception as e:
635+
# Can't import TclError directly since Python is not configured for Tk on all systems
636+
is_tcl_error = e.__class__.__name__ == 'TclError'
637+
638+
is_windows_on_github_actions = os.name == 'nt' and 'TOXPYTHON' in os.environ
639+
if is_tcl_error and is_windows_on_github_actions:
640+
_logger.warning(f'Ignoring TclError when attempting to show plot '
641+
f'since we appear to be running on Windows in GitHub Actions ({str(e)})')
642+
else:
643+
raise e

src/geophires_x/SBTReservoir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def generate_wireframe_model(lateral_endpoint_depth: float, number_of_laterals:
150150

151151
az, el = 71.5676, 10.4739
152152
ax.view_init(az, el)
153-
plt.show()
153+
show_plot(block=False)
154154

155155
return xinj, yinj, zinj, xprod, yprod, zprod, xlat, ylat, zlat
156156

src/geophires_x/SUTRAReservoir.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import sys
2+
3+
from .GeoPHIRESUtils import show_plot
24
from .Parameter import strParameter, OutputParameter
35
from .Units import *
46
import geophires_x.Model as Model
@@ -218,7 +220,7 @@ def Calculate(self, model: Model):
218220
#plt.ylim([0, max(model.surfaceplant.daily_heating_demand.value) * 1.05])
219221
plt.legend()
220222
plt.title('SUTRA Heat Balance')
221-
plt.show(block=False)
223+
show_plot(block=False)
222224

223225
plt.figure(2)
224226
plt.plot(self.TimeProfile.value[0:-1:2], self.TargetHeat.value[0:-1:2], label='Target Heat')
@@ -228,7 +230,7 @@ def Calculate(self, model: Model):
228230
#plt.ylim([0, max(model.surfaceplant.daily_heating_demand.value) * 1.05])
229231
plt.legend()
230232
plt.title('SUTRA Target and Simulated Heat')
231-
plt.show(block=False)
233+
show_plot(block=False)
232234

233235
plt.figure(3)
234236
plt.plot(self.TimeProfile.value[0:-1:2], self.StorageWellFlowRate.value[0:-1:2], label='Storage Well Flow Rate')
@@ -238,7 +240,7 @@ def Calculate(self, model: Model):
238240
#plt.ylim([0, max(model.surfaceplant.daily_heating_demand.value) * 1.05])
239241
plt.legend()
240242
plt.title('SUTRA Well Flow Rates')
241-
plt.show(block=False)
243+
show_plot(block=False)
242244

243245
plt.figure(4)
244246
plt.plot(self.TimeProfile.value[0:-1:2], self.StorageWellTemperature.value[0:-1:2], label='Storage Well Temperature')
@@ -248,6 +250,6 @@ def Calculate(self, model: Model):
248250
# plt.ylim([0, max(model.surfaceplant.daily_heating_demand.value) * 1.05])
249251
plt.legend()
250252
plt.title('SUTRA Well Temperatures')
251-
plt.show(block=False)
253+
show_plot(block=False)
252254

253255
model.logger.info("Complete " + str(__class__) + ": " + sys._getframe().f_code.co_name)

0 commit comments

Comments
 (0)