Skip to content

Commit

Permalink
Spectrum Viewer: for hidden ROIs set spectrum to None instead of Zero
Browse files Browse the repository at this point in the history
Avoid the spectrum plot range being scaled to show zero
  • Loading branch information
samtygier-stfc committed Oct 27, 2023
1 parent 3b18581 commit 37fcd86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self) -> None:
self.nextRow()
self.spectrum = self.addPlot()

self.spectrum_data_dict: dict[str, np.ndarray] = {}
self.spectrum_data_dict: dict[str, np.ndarray | None] = {}
self.nextRow()
self._tof_range_label = self.addLabel()

Expand Down
13 changes: 6 additions & 7 deletions mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ def set_spectrum(self, name: str, spectrum_data: 'np.ndarray'):
self.spectrum.spectrum_data_dict[name] = spectrum_data
self.spectrum.spectrum.clearPlots()

for key, value in self.spectrum.spectrum_data_dict.items():
if key in self.spectrum.roi_dict:
self.spectrum.spectrum.plot(value, name=key, pen=self.spectrum.roi_dict[key].colour)
self.show_visible_spectrums()

def clear(self) -> None:
self.spectrum.spectrum_data_dict = {}
Expand Down Expand Up @@ -256,14 +254,15 @@ def set_roi_alpha(self, alpha: float, roi_name: str) -> None:
"""
self.spectrum.set_roi_alpha(roi_name, alpha)
if alpha == 0:
self.spectrum.spectrum_data_dict[roi_name] = np.zeros(self.spectrum.spectrum_data_dict[roi_name].shape)
else:
self.spectrum.spectrum_data_dict[roi_name] = self.spectrum.spectrum_data_dict[roi_name]
self.spectrum.spectrum_data_dict[roi_name] = None

self.spectrum.spectrum.clearPlots()
self.spectrum.spectrum.update()
self.show_visible_spectrums()

def show_visible_spectrums(self):
for key, value in self.spectrum.spectrum_data_dict.items():
if key in self.spectrum.roi_dict:
if value is not None and key in self.spectrum.roi_dict:
self.spectrum.spectrum.plot(value, name=key, pen=self.spectrum.roi_dict[key].colour)

def add_roi_table_row(self, name: str, colour: tuple[int, int, int]):
Expand Down

0 comments on commit 37fcd86

Please sign in to comment.