Skip to content

Commit

Permalink
Get Rid of Noisy FigureManager error log (#494)
Browse files Browse the repository at this point in the history
* just clone workspace, do not rename, it will get cleaned up anyway and not really impact perf

* mutate axis to prevent errors being tossed in unnecessary handling of workspace rename

* update with the most correct solution

* updforgot a spot

* move mutation to central location
  • Loading branch information
walshmm authored Dec 10, 2024
1 parent 80ea2e0 commit 998393d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/snapred/ui/plotting/Factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def mantidAxisFactory(ax):
"""
Refurbish the axis object with a new rename_workspace method
"""

def rename_workspace(old_name, new_name):
"""
Rename a workspace, and update the artists, creation arguments and tracked workspaces accordingly
:param new_name : the new name of workspace
:param old_name : the old name of workspace
"""
for cargs in ax.creation_args:
# NEW CHECK
func_name = cargs["function"]
if func_name not in ["axhline", "axvline"] and cargs["workspaces"] == old_name:
cargs["workspaces"] = new_name
# Alternatively,
# if cargs.get("workspaces") == old_name:
# cargs["workspaces"] = new_name
for ws_name, ws_artist_list in list(ax.tracked_workspaces.items()):
for ws_artist in ws_artist_list:
if ws_artist.workspace_name == old_name:
ws_artist.rename_data(new_name)
if ws_name == old_name:
ax.tracked_workspaces[new_name] = ax.tracked_workspaces.pop(old_name)

ax.rename_workspace = rename_workspace
return ax
7 changes: 7 additions & 0 deletions src/snapred/ui/view/DiffCalTweakPeakView.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from snapred.meta.decorators.Resettable import Resettable
from snapred.meta.mantid.AllowedPeakTypes import SymmetricPeakEnum
from snapred.meta.mantid.FitPeaksOutput import FitOutputEnum
from snapred.ui.plotting.Factory import mantidAxisFactory
from snapred.ui.view.BackendRequestView import BackendRequestView


Expand Down Expand Up @@ -212,6 +213,7 @@ def updateGraphs(self, workspace, peaks, diagnostic, residual):

# now re-draw the figure
self.figure.clear()

for wkspIndex in range(numGraphs):
peaks = self.peaks[wkspIndex].peaks
# collect the fit chi-sq parameters for this spectrum, and the fits
Expand All @@ -220,6 +222,11 @@ def updateGraphs(self, workspace, peaks, diagnostic, residual):
self.badPeaks[wkspIndex] = [peak for chi2, peak in zip(chisq, peaks) if chi2 >= maxChiSq]
# prepare the plot area
ax = self.figure.add_subplot(nrows, ncols, wkspIndex + 1, projection="mantid")

# NOTE: Mutate the ax object as the mantidaxis does not account for lines
# TODO: Bubble this up to the mantid codebase and remove this mutation.
ax = mantidAxisFactory(ax)

ax.tick_params(direction="in")
ax.set_title(f"Group ID: {wkspIndex + 1}")
# plot the data and fitted curve
Expand Down
6 changes: 6 additions & 0 deletions src/snapred/ui/view/NormalizationTweakPeakView.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from snapred.backend.dao import GroupPeakList
from snapred.meta.Config import Config
from snapred.meta.decorators.Resettable import Resettable
from snapred.ui.plotting.Factory import mantidAxisFactory
from snapred.ui.view.BackendRequestView import BackendRequestView
from snapred.ui.widget.SmoothingSlider import SmoothingSlider

Expand Down Expand Up @@ -178,6 +179,11 @@ def _updateGraphs(self, peaks):
self.figure.clear()
for i in range(numGraphs):
ax = self.figure.add_subplot(nrows, ncols, i + 1, projection="mantid")

# NOTE: Mutate the ax object as the mantidaxis does not account for lines
# TODO: Bubble this up to the mantid codebase and remove this mutation.
ax = mantidAxisFactory(ax)

ax.plot(focusedWorkspace, wkspIndex=i, label="Focused Data", normalize_by_bin_width=True)
ax.plot(smoothedWorkspace, wkspIndex=i, label="Smoothed Data", normalize_by_bin_width=True, linestyle="--")
ax.legend()
Expand Down
6 changes: 6 additions & 0 deletions src/snapred/ui/view/reduction/ArtificialNormalizationView.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from snapred.meta.Config import Config
from snapred.meta.decorators.Resettable import Resettable
from snapred.ui.plotting.Factory import mantidAxisFactory
from snapred.ui.view.BackendRequestView import BackendRequestView


Expand Down Expand Up @@ -133,6 +134,11 @@ def _updateGraphs(self):
self.figure.clear()
for i in range(numGraphs):
ax = self.figure.add_subplot(nrows, ncols, i + 1, projection="mantid")

# NOTE: Mutate the ax object as the mantidaxis does not account for lines
# TODO: Bubble this up to the mantid codebase and remove this mutation.
ax = mantidAxisFactory(ax)

ax.plot(diffractionWorkspace, wkspIndex=i, label="Diffcal Data", normalize_by_bin_width=True)
ax.plot(
artificialNormWorkspace,
Expand Down

0 comments on commit 998393d

Please sign in to comment.