Skip to content

Commit a1bb509

Browse files
1 parent 66ae602 commit a1bb509

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/geophires_x/MatplotlibUtils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""
22
Workarounds for intermittent Windows GitHub Actions failures - see https://github.com/NREL/GEOPHIRES-X/issues/365
3+
4+
TODO fix the actual Tcl/Tk installation issue (perhaps using suggestions from i.e.
5+
https://stackoverflow.com/questions/29320039/trying-to-use-tkinter-throws-tcl-error-cant-find-a-usable-init-tcl)
36
"""
47

58
from __future__ import annotations
@@ -34,6 +37,13 @@ def plt_subplots(**kw_args) -> Any:
3437
_handle_tcl_error_on_windows_github_actions(e)
3538

3639

40+
def plt_figure(*args, **kw_args) -> Any:
41+
try:
42+
return plt.figure(*args, **kw_args)
43+
except Exception as e:
44+
_handle_tcl_error_on_windows_github_actions(e)
45+
46+
3747
def _handle_tcl_error_on_windows_github_actions(e) -> None:
3848
# Can't import TclError directly since Python is not configured for Tk on all systems
3949
tcl_error_name = 'TclError'

src/geophires_x/SUTRAReservoir.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22

3-
from .MatplotlibUtils import plt_show
3+
from .MatplotlibUtils import plt_show, plt_figure
44
from .Parameter import strParameter, OutputParameter
55
from .Units import *
66
import geophires_x.Model as Model
@@ -211,7 +211,7 @@ def Calculate(self, model: Model):
211211

212212
# create plots of imported SUTRA data
213213
plt.close('all')
214-
plt.figure(1)
214+
plt_figure(1)
215215
year = np.arange(1, 31, 1) # make an array of days for plot x-axis
216216
plt.plot(year, abs(self.AnnualHeatStored.value), label='Annual Heat Stored')
217217
plt.plot(year, abs(self.AnnualHeatSupplied.value), label='Annual Heat Supplied')
@@ -222,7 +222,7 @@ def Calculate(self, model: Model):
222222
plt.title('SUTRA Heat Balance')
223223
plt_show(block=False)
224224

225-
plt.figure(2)
225+
plt_figure(2)
226226
plt.plot(self.TimeProfile.value[0:-1:2], self.TargetHeat.value[0:-1:2], label='Target Heat')
227227
plt.plot(self.TimeProfile.value[0:-1:2], self.SimulatedHeat.value[0:-1:2], label='Simulated Heat')
228228
plt.xlabel('Hour')
@@ -232,7 +232,7 @@ def Calculate(self, model: Model):
232232
plt.title('SUTRA Target and Simulated Heat')
233233
plt_show(block=False)
234234

235-
plt.figure(3)
235+
plt_figure(3)
236236
plt.plot(self.TimeProfile.value[0:-1:2], self.StorageWellFlowRate.value[0:-1:2], label='Storage Well Flow Rate')
237237
plt.plot(self.TimeProfile.value[0:-1:2], self.BalanceWellFlowRate.value[0:-1:2], label='Balance Well Flow Rate')
238238
plt.xlabel('Hour')
@@ -242,7 +242,7 @@ def Calculate(self, model: Model):
242242
plt.title('SUTRA Well Flow Rates')
243243
plt_show(block=False)
244244

245-
plt.figure(4)
245+
plt_figure(4)
246246
plt.plot(self.TimeProfile.value[0:-1:2], self.StorageWellTemperature.value[0:-1:2], label='Storage Well Temperature')
247247
plt.plot(self.TimeProfile.value[0:-1:2], self.BalanceWellTemperature.value[0:-1:2], label='Balance Well Temperature')
248248
plt.xlabel('Hour')

0 commit comments

Comments
 (0)