Skip to content

Commit d7eb2fd

Browse files
authored
Merge pull request #122 from SteSeg/include_puns_colormaps
Include puns colormaps
2 parents 14db121 + 09c2898 commit d7eb2fd

File tree

2 files changed

+96
-50
lines changed

2 files changed

+96
-50
lines changed

openmc_plotter/docks.py

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
QComboBox, QSpinBox, QDoubleSpinBox, QSizePolicy,
99
QCheckBox, QDockWidget, QScrollArea, QListWidget,
1010
QListWidgetItem, QTreeWidget, QTreeWidgetItem)
11-
from matplotlib import cm as mcolormaps
11+
import matplotlib.pyplot as plt
1212
import numpy as np
1313
import openmc
1414

@@ -22,6 +22,7 @@ class PlotterDock(QDockWidget):
2222
"""
2323
Dock widget with common settings for the plotting application
2424
"""
25+
2526
def __init__(self, model, font_metric, parent=None):
2627
super().__init__(parent)
2728

@@ -36,6 +37,7 @@ class DomainDock(PlotterDock):
3637
"""
3738
Domain options dock
3839
"""
40+
3941
def __init__(self, model, font_metric, parent=None):
4042
super().__init__(model, font_metric, parent)
4143

@@ -159,7 +161,8 @@ def _createOptionsBox(self):
159161
self.domainAlphaBox.setSingleStep(0.05)
160162
self.domainAlphaBox.setDecimals(2)
161163
self.domainAlphaBox.setRange(0.0, 1.0)
162-
self.domainAlphaBox.valueChanged.connect(self.main_window.editPlotAlpha)
164+
self.domainAlphaBox.valueChanged.connect(
165+
self.main_window.editPlotAlpha)
163166

164167
# Visibility
165168
self.visibilityBox = QCheckBox(self)
@@ -179,8 +182,10 @@ def _createOptionsBox(self):
179182

180183
# Advanced Color Options
181184
self.colorOptionsButton = QPushButton('Color Options...')
182-
self.colorOptionsButton.setMinimumHeight(self.font_metric.height() * 1.6)
183-
self.colorOptionsButton.clicked.connect(self.main_window.showColorDialog)
185+
self.colorOptionsButton.setMinimumHeight(
186+
self.font_metric.height() * 1.6)
187+
self.colorOptionsButton.clicked.connect(
188+
self.main_window.showColorDialog)
184189

185190
# Options Form Layout
186191
self.opLayout = QFormLayout()
@@ -393,16 +398,19 @@ def _createFilterTree(self, spatial_filters):
393398
# make checkable
394399
if not spatial_filters:
395400
filter_item.setFlags(QtCore.Qt.ItemIsUserCheckable)
396-
filter_item.setToolTip(0, "Only tallies with spatial filters are viewable.")
401+
filter_item.setToolTip(
402+
0, "Only tallies with spatial filters are viewable.")
397403
else:
398-
filter_item.setFlags(filter_item.flags() | QtCore.Qt.ItemIsTristate | QtCore.Qt.ItemIsUserCheckable)
404+
filter_item.setFlags(
405+
filter_item.flags() | QtCore.Qt.ItemIsTristate | QtCore.Qt.ItemIsUserCheckable)
399406
filter_item.setCheckState(0, QtCore.Qt.Unchecked)
400407

401408
# all mesh bins are selected by default and not shown in the dock
402409
if isinstance(tally_filter, openmc.MeshFilter):
403410
filter_item.setCheckState(0, QtCore.Qt.Checked)
404411
filter_item.setFlags(QtCore.Qt.ItemIsUserCheckable)
405-
filter_item.setToolTip(0, "All Mesh bins are selected automatically")
412+
filter_item.setToolTip(
413+
0, "All Mesh bins are selected automatically")
406414
continue
407415

408416
def _bin_sort_val(bin):
@@ -423,7 +431,8 @@ def _bin_sort_val(bin):
423431
item = QTreeWidgetItem(filter_item, [str(bin),])
424432
if not spatial_filters:
425433
item.setFlags(QtCore.Qt.ItemIsUserCheckable)
426-
item.setToolTip(0, "Only tallies with spatial filters are viewable.")
434+
item.setToolTip(
435+
0, "Only tallies with spatial filters are viewable.")
427436
else:
428437
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
429438
item.setCheckState(0, QtCore.Qt.Unchecked)
@@ -487,7 +496,8 @@ def selectTally(self, tally_label=None):
487496

488497
if not spatial_filters:
489498
self.valueBox.setEnabled(False)
490-
self.valueBox.setToolTip("Only tallies with spatial filters are viewable.")
499+
self.valueBox.setToolTip(
500+
"Only tallies with spatial filters are viewable.")
491501

492502
# scores
493503
self.score_map = {}
@@ -520,7 +530,8 @@ def selectTally(self, tally_label=None):
520530

521531
self.scoresGroupBoxLayout = QVBoxLayout()
522532
self.scoresGroupBoxLayout.addWidget(self.scoresListWidget)
523-
self.scoresGroupBox = Expander("Scores:", layout=self.scoresGroupBoxLayout)
533+
self.scoresGroupBox = Expander(
534+
"Scores:", layout=self.scoresGroupBoxLayout)
524535
self.tallySelectorLayout.addRow(self.scoresGroupBox)
525536

526537
# nuclides
@@ -554,7 +565,8 @@ def selectTally(self, tally_label=None):
554565

555566
self.nuclidesGroupBoxLayout = QVBoxLayout()
556567
self.nuclidesGroupBoxLayout.addWidget(self.nuclidesListWidget)
557-
self.nuclidesGroupBox = Expander("Nuclides:", layout=self.nuclidesGroupBoxLayout)
568+
self.nuclidesGroupBox = Expander(
569+
"Nuclides:", layout=self.nuclidesGroupBoxLayout)
558570
self.tallySelectorLayout.addRow(self.nuclidesGroupBox)
559571

560572
def updateMinMax(self):
@@ -620,27 +632,34 @@ def updateScores(self):
620632
for score, score_box in self.score_map.items():
621633
sunits = _SCORE_UNITS.get(score, _REACTION_UNITS)
622634
empty_item = QListWidgetItem()
623-
score_box.setFlags(empty_item.flags() | QtCore.Qt.ItemIsUserCheckable)
624-
score_box.setFlags(empty_item.flags() & ~QtCore.Qt.ItemIsSelectable)
635+
score_box.setFlags(empty_item.flags() |
636+
QtCore.Qt.ItemIsUserCheckable)
637+
score_box.setFlags(empty_item.flags() &
638+
~QtCore.Qt.ItemIsSelectable)
625639
elif 'total' in applied_scores:
626640
self.model.appliedScores = ('total',)
627641
# if total is selected, disable all other scores
628642
for score, score_box in self.score_map.items():
629643
if score != 'total':
630644
score_box.setFlags(QtCore.Qt.ItemIsUserCheckable)
631-
score_box.setToolTip("De-select 'total' to enable other scores")
645+
score_box.setToolTip(
646+
"De-select 'total' to enable other scores")
632647
else:
633648
# get units of applied scores
634-
selected_units = _SCORE_UNITS.get(applied_scores[0], _REACTION_UNITS)
649+
selected_units = _SCORE_UNITS.get(
650+
applied_scores[0], _REACTION_UNITS)
635651
# disable scores with incompatible units
636652
for score, score_box in self.score_map.items():
637653
sunits = _SCORE_UNITS.get(score, _REACTION_UNITS)
638654
if sunits != selected_units:
639655
score_box.setFlags(QtCore.Qt.ItemIsUserCheckable)
640-
score_box.setToolTip("Score is incompatible with currently selected scores")
656+
score_box.setToolTip(
657+
"Score is incompatible with currently selected scores")
641658
else:
642-
score_box.setFlags(score_box.flags() | QtCore.Qt.ItemIsUserCheckable)
643-
score_box.setFlags(score_box.flags() & ~QtCore.Qt.ItemIsSelectable)
659+
score_box.setFlags(score_box.flags() |
660+
QtCore.Qt.ItemIsUserCheckable)
661+
score_box.setFlags(score_box.flags() &
662+
~QtCore.Qt.ItemIsSelectable)
644663

645664
def updateNuclides(self):
646665
applied_nuclides = []
@@ -654,13 +673,16 @@ def updateNuclides(self):
654673
for nuclide, nuclide_box in self.nuclide_map.items():
655674
if nuclide != 'total':
656675
nuclide_box.setFlags(QtCore.Qt.ItemIsUserCheckable)
657-
nuclide_box.setToolTip("De-select 'total' to enable other nuclides")
676+
nuclide_box.setToolTip(
677+
"De-select 'total' to enable other nuclides")
658678
elif not applied_nuclides:
659679
# if no nuclides are selected, enable all nuclides again
660680
for nuclide, nuclide_box in self.nuclide_map.items():
661681
empty_item = QListWidgetItem()
662-
nuclide_box.setFlags(empty_item.flags() | QtCore.Qt.ItemIsUserCheckable)
663-
nuclide_box.setFlags(empty_item.flags() & ~QtCore.Qt.ItemIsSelectable)
682+
nuclide_box.setFlags(empty_item.flags() |
683+
QtCore.Qt.ItemIsUserCheckable)
684+
nuclide_box.setFlags(empty_item.flags() &
685+
~QtCore.Qt.ItemIsSelectable)
664686

665687
def updateModel(self):
666688
self.updateFilters()
@@ -678,9 +700,11 @@ def update(self):
678700
self.tallySelector.addItem("None")
679701
for idx, tally in enumerate(self.model.statepoint.tallies.values()):
680702
if tally.name == "":
681-
self.tallySelector.addItem(f'Tally {tally.id}', userData=tally.id)
703+
self.tallySelector.addItem(
704+
f'Tally {tally.id}', userData=tally.id)
682705
else:
683-
self.tallySelector.addItem(f'Tally {tally.id} "{tally.name}"', userData=tally.id)
706+
self.tallySelector.addItem(
707+
f'Tally {tally.id} "{tally.name}"', userData=tally.id)
684708
self.tally_map[idx] = tally
685709
self.updateSelectedTally()
686710
self.updateMinMax()
@@ -734,6 +758,7 @@ class ColorForm(QWidget):
734758
comma-separated set of values is entered, those values will be used as
735759
levels in the contour plot.
736760
"""
761+
737762
def __init__(self, model, main_window, field, colormaps=None):
738763
super().__init__()
739764

@@ -759,16 +784,19 @@ def __init__(self, model, main_window, field, colormaps=None):
759784
# Color map selector
760785
self.colormapBox = QComboBox()
761786
if colormaps is None:
762-
colormaps = sorted(m for m in mcolormaps.datad if not m.endswith("_r"))
787+
colormaps = sorted(
788+
m for m in plt.colormaps() if not m.endswith("_r"))
763789
for colormap in colormaps:
764790
self.colormapBox.addItem(colormap)
765791
cmap_connector = partial(main_window.editTallyDataColormap)
766792
self.colormapBox.currentTextChanged[str].connect(cmap_connector)
767793

768794
# Data indicator line check box
769795
self.dataIndicatorCheckBox = QCheckBox()
770-
data_indicator_connector = partial(main_window.toggleTallyDataIndicator)
771-
self.dataIndicatorCheckBox.stateChanged.connect(data_indicator_connector)
796+
data_indicator_connector = partial(
797+
main_window.toggleTallyDataIndicator)
798+
self.dataIndicatorCheckBox.stateChanged.connect(
799+
data_indicator_connector)
772800

773801
# User specified min/max check box
774802
self.userMinMaxBox = QCheckBox()

0 commit comments

Comments
 (0)