Closed john-science closed 3 weeks ago
@ntouran Just FYI
I note that in the gallery example run_fuelManagement.py
, we call plotFaceMap()
twice, but don't pass it an fName
parameter. Looking at the method, that means we will never write an output file for this plot. So THAT is definitely the problem with three of the above gallery examples.
The gallery plugin expects a plt.show()
to be called and it intercepts the result from memory. plotFaceMap only plots with a plt.show()
when no filename is passed in. So it's called correctly. Looks like the issue here is the plt.close()
that's called immediately after the plt.show()
!
I think all the close()'s that come right after show()'s that are used in these gallery examples probably broke due to https://github.com/terrapower/armi/pull/1698.
To fix I think we have to close plots differently, e.g. from the caller. If a caller wants a plt.show() then you are responsible for calling plt.close(). Otherwise you'll never see the plot.
To confirm, I've commented some plt.close()'s out and have seen the plotFacemap plots re-appear!
patch:
diff --git a/armi/utils/plotting.py b/armi/utils/plotting.py
index 8e713eeb..1cc50f86 100644
--- a/armi/utils/plotting.py
+++ b/armi/utils/plotting.py
@@ -408,7 +408,7 @@ def plotFaceMap(
else:
plt.show()
- plt.close(fig)
+ #plt.close(fig)
return fName
diff --git a/doc/conf.py b/doc/conf.py
index d21b56a8..4a24489a 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -125,6 +125,19 @@ class ExecDirective(Directive):
docname, self.lineno, datetime.datetime.now(), str(e)
)
)
diff --git a/doc/gallery-src/analysis/run_hexReactorToRZ.py b/doc/gallery-src/analysis/run_hexReactorToRZ.py
index 89b3e627..1baa4c7e 100644
--- a/doc/gallery-src/analysis/run_hexReactorToRZ.py
+++ b/doc/gallery-src/analysis/run_hexReactorToRZ.py
@@ -55,4 +55,3 @@ converter.convert(r)
figs = converter.plotConvertedReactor()
plt.show()
-plt.close()
diff --git a/doc/gallery-src/framework/run_fuelManagement.py b/doc/gallery-src/framework/run_fuelManagement.py
index 44a18df1..fc3709e1 100644
--- a/doc/gallery-src/framework/run_fuelManagement.py
+++ b/doc/gallery-src/framework/run_fuelManagement.py
@@ -72,5 +72,4 @@ for num in range(8):
fuelHandler.swapAssemblies(high, low)
# show final burnup distribution
-plotting.plotFaceMap(reactor.core, param="percentBu")
-plt.close()
+plotting.plotFaceMap(reactor.core, param="percentBu")
\ No newline at end of file
diff --git a/doc/gallery-src/framework/run_reactorFacemap.py b/doc/gallery-src/framework/run_reactorFacemap.py
index 7b961d46..457aa3f5 100644
--- a/doc/gallery-src/framework/run_reactorFacemap.py
+++ b/doc/gallery-src/framework/run_reactorFacemap.py
@@ -33,4 +33,3 @@ for b in reactor.core.getBlocks():
b.p.pdens = x**2 + y**2 + z**2
plotting.plotFaceMap(reactor.core, param="pdens", labelFmt="{0:.1e}")
-plotting.close()
Testing further, I reverted the whole 'close all plots' commit and then removed a few other .close()
calls and everything's back online.
Adding plt.close()
after plt.show()
eliminates the possibility of using the plotting function interactively, e.g. in a jupyter notebook or ipython. This is probably not what we want. I think we should revert that change and instead do one that makes the calling clients either always pass a .show()
-suppressing fname, or only do a .close()
only in the if-branch where a file was passed and is being written (not the one with a show()
.
We can configure sphinx-gallery to read from actual written files, but this is not a good solution because it still leaves users without the ability to do any interactive plotting, which is a big bummer when you're rapidly iterating on a core design. Also, if you're running our interactive tutorials you aren't gonna see any of the plots when it tells you to plot. They'll flash and instantly disappear.
Net result with all closes removed:
Okay, that makes sense.
The only place where we NEED plt.close()
is after the plots are written to file. So this is an easy change to make.
Thanks, Sphinx Guru!
The current ARMI Gallery has apparently had several broken examples for months now:
How embarrassing for me. I guess no one looks at these much.