Skip to content

Commit

Permalink
Clarifying the inputs of plotAssemblyTypes (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Jul 15, 2022
1 parent 80c2bfc commit be99de9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
32 changes: 19 additions & 13 deletions armi/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def colorGenerator(skippedColors=10):
-----
Will cycle indefinitely to accommodate large cores. Colors will repeat.
"""

colors = list(mcolors.CSS4_COLORS)

for start in itertools.cycle(range(20, 20 + skippedColors)):
Expand Down Expand Up @@ -293,7 +292,6 @@ def plotFaceMap(
Plotting a BOL assembly type facemap with a legend::
>>> plotFaceMap(core, param='typeNumAssem', cmapName='RdYlBu')
"""
if referencesToKeep:
patches, collection, texts = referencesToKeep
Expand Down Expand Up @@ -582,9 +580,7 @@ def legend_artist(self, _legend, orig_handle, _fontsize, handlebox):


class DepthSlider(Slider):
"""
Page slider used to view params at different depths.
"""
"""Page slider used to view params at different depths."""

def __init__(
self,
Expand Down Expand Up @@ -703,7 +699,7 @@ def updatePageDepthColor(self, newVal):


def plotAssemblyTypes(
blueprints,
blueprints=None,
fileName=None,
assems=None,
maxAssems=None,
Expand All @@ -717,13 +713,13 @@ def plotAssemblyTypes(
Parameters
----------
blueprints: Blueprints
The blueprints to plot assembly types of.
The blueprints to plot assembly types of. (Either this or ``assems`` must be non-None.)
fileName : str or None
Base for filename to write, or None for just returning the fig
assems: list
list of assembly objects to be plotted.
list of assembly objects to be plotted. (Either this or ``blueprints`` must be non-None.)
maxAssems: integer
maximum number of assemblies to plot in the assems list.
Expand All @@ -742,6 +738,12 @@ def plotAssemblyTypes(
fig : plt.Figure
The figure object created
"""
# input validation
if assems is None and blueprints is None:
raise ValueError(
"At least one of these inputs must be non-None: blueprints, assems"
)

# handle defaults
if assems is None:
assems = list(blueprints.assemblies.values())
Expand Down Expand Up @@ -956,6 +958,8 @@ def __init__(
self.peak = peak
self.avgHistogram = None
self.eHistogram = None
self.peakHistogram = None
self.E = None

if not blockList:
self.avgFlux = numpy.zeros(self.nGroup)
Expand Down Expand Up @@ -1046,21 +1050,25 @@ def getTable(self):

if max(bf1.avgFlux) <= 0.0:
runLog.warning(
"Cannot plot flux with maxval=={0} in {1}".format(eMax, bList[0])
"Cannot plot flux with maxval=={0} in {1}".format(bf1.avgFlux, bList[0])
)
return

plt.figure()
plt.plot(bf1.eHistogram, bf1.avgHistogram, bf1.lineAvg, label=bf1.labelAvg)

if peak:
plt.plot(bf1.eHistogram, bf1.peakHistogram, bf1.linePeak, label=bf1.labelPeak)

ax = plt.gca()
ax.set_xscale("log")
ax.set_yscale("log")
plt.xlabel("Energy (MeV)")
plt.ylabel("Flux (n/cm$^2$/s)")

if peak or bList2:
plt.legend(loc="lower right")

plt.grid(color="0.70")
if bList2:
if adjoint:
Expand Down Expand Up @@ -1138,7 +1146,6 @@ def _makeBlockPinPatches(block, cold):
name : list
list of the names of these components
"""

patches = []
data = []
names = []
Expand Down Expand Up @@ -1237,7 +1244,6 @@ def _makeComponentPatch(component, position, cold):
-----
Currently accepts components of shape DerivedShape, Helix, Circle, or Square
"""

x = position[0]
y = position[1]

Expand Down Expand Up @@ -1526,9 +1532,9 @@ def plotNucXs(
----------
isotxs : IsotxsLibrary
A collection of cross sections (XS) for both neutron and gamma reactions.
nucName : str or list
nucNames : str or list
The nuclides to plot
xsName : str or list
xsNames : str or list
the XS to plot e.g. n,g, n,f, nalph, etc. see xsCollections for actual names.
fName : str, optional
if fName is given, the file will be written rather than plotting to screen
Expand Down
12 changes: 7 additions & 5 deletions armi/utils/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Tests for functions in util.plotting.py
"""
"""Tests for basic plotting tools"""
import os
import unittest

from armi.nuclearDataIO.cccc import isotxs
from armi.utils import plotting
from armi.reactor.flags import Flags
from armi.reactor.tests import test_reactors
from armi.tests import ISOAA_PATH, TEST_ROOT
from armi.reactor.flags import Flags
from armi.utils import plotting
from armi.utils.directoryChangers import TemporaryDirectoryChanger


Expand Down Expand Up @@ -64,6 +62,9 @@ def test_plotAssemblyTypes(self):
)
self._checkExists(plotPath)

with self.assertRaises(ValueError):
plotting.plotAssemblyTypes(None, plotPath, None)

def test_plotBlockFlux(self):
try:
xslib = isotxs.readBinary(ISOAA_PATH)
Expand Down Expand Up @@ -103,6 +104,7 @@ def test_plotHexBlock(self):
self.assertTrue(os.path.exists("blockDiagram23.svg"))

def test_plotCartesianBlock(self):
# pylint: disable=import-outside-toplevel
from armi import settings
from armi.reactor import blueprints, reactors

Expand Down

0 comments on commit be99de9

Please sign in to comment.