Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter bin selection performance bug #74

Merged
merged 3 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions openmc_plotter/docks.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ def _createFilterTree(self, spatial_filters):
self.filterTree.setHeaderItem(header)
self.filterTree.setItemHidden(header, True)
self.filterTree.setColumnCount(1)
self.filterTree.itemChanged.connect(self.updateFilters)

self.filter_map = {}
self.bin_map = {}
Expand Down Expand Up @@ -489,8 +488,6 @@ def selectTally(self, tally_label=None):

# scores
self.score_map = {}
self.scoresListWidget.itemClicked.connect(
self.main_window.updateScores)
self.score_map.clear()
self.scoresListWidget.clear()

Expand Down Expand Up @@ -525,7 +522,6 @@ def selectTally(self, tally_label=None):

# nuclides
self.nuclide_map = {}
self.nuclidesListWidget.itemClicked.connect(self.main_window.updateNuclides)
self.nuclide_map.clear()
self.nuclidesListWidget.clear()

Expand Down Expand Up @@ -574,13 +570,27 @@ def updateSelectedTally(self):
self.tallySelector.setCurrentIndex(idx)

def updateFilters(self):
# if the filters header is checked, uncheck all bins and return
applied_filters = defaultdict(tuple)
for f, f_item in self.filter_map.items():
if type(f) == openmc.MeshFilter:
continue

filter_checked = f_item.checkState(0)
if filter_checked != QtCore.Qt.Unchecked:
if filter_checked == QtCore.Qt.Unchecked:
for i in range(f_item.childCount()):
bin_item = f_item.child(i)
bin_item.setCheckState(0, QtCore.Qt.Unchecked)
applied_filters[f] = tuple()
elif filter_checked == QtCore.Qt.Checked:
if isinstance(f, openmc.EnergyFunctionFilter):
bins = [0]
else:
for i in range(f_item.childCount()):
bin_item = f_item.child(i)
bin_item.setCheckState(0, QtCore.Qt.Checked)
applied_filters[f] = tuple(range(f_item.childCount()))
elif filter_checked == QtCore.Qt.PartiallyChecked:
selected_bins = []
if isinstance(f, openmc.EnergyFunctionFilter):
bins = [0]
Expand All @@ -593,7 +603,7 @@ def updateFilters(self):
selected_bins.append(idx)
applied_filters[f] = tuple(selected_bins)

self.model.appliedFilters = applied_filters
self.model.appliedFilters = applied_filters

def updateScores(self):
applied_scores = []
Expand Down Expand Up @@ -649,6 +659,11 @@ def updateNuclides(self):
nuclide_box.setFlags(empty_item.flags() | QtCore.Qt.ItemIsUserCheckable)
nuclide_box.setFlags(empty_item.flags() & ~QtCore.Qt.ItemIsSelectable)

def updateModel(self):
self.updateFilters()
self.updateScores()
self.updateNuclides()

def update(self):

# update the color form
Expand Down
8 changes: 2 additions & 6 deletions openmc_plotter/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ def applyChanges(self):
if self.model.activeView != self.model.currentView:
self.statusBar().showMessage('Generating Plot...')
QApplication.processEvents()
if self.model.activeView.selectedTally is not None:
self.tallyDock.updateModel()
self.model.storeCurrent()
self.model.subsequentViews = []
self.plotIm.generatePixmap()
Expand Down Expand Up @@ -901,12 +903,6 @@ def editTallyValue(self, event):
av = self.model.activeView
av.tallyValue = event

def updateScores(self, state):
self.tallyDock.updateScores()

def updateNuclides(self, state):
self.tallyDock.updateNuclides()

def toggleTallyVisibility(self, state, apply=False):
av = self.model.activeView
av.tallyDataVisible = bool(state)
Expand Down
4 changes: 2 additions & 2 deletions openmc_plotter/plotmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ def _do_op(array, tally_value, ax=0):
if type(tally_filter) == openmc.MeshFilter:
continue

if tally_filter in self.appliedFilters:
selected_bins = self.appliedFilters[tally_filter]
selected_bins = self.appliedFilters[tally_filter]
if selected_bins:
# sum filter data for the selected bins
data = data[np.array(selected_bins)].sum(axis=0)
else:
Expand Down