Skip to content

Commit

Permalink
non-threaded version
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSullivan7 committed Dec 13, 2024
1 parent 78e0b3f commit ebdf381
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
4 changes: 2 additions & 2 deletions mantidimaging/gui/windows/live_viewer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def calc_mean_fully(self) -> None:
for image in self.images:
self.add_mean(image, self.image_cache.load_image(image))

def calc_mean_chunk(self, chunk_size: int) -> None:
def calc_mean_chunk(self, chunk_size: int = 10000) -> None:
if self.images is not None:
nanInds = np.argwhere(np.isnan(self.mean))
if self.roi:
Expand All @@ -242,7 +242,7 @@ def calc_mean_chunk(self, chunk_size: int) -> None:
buffer_mean = np.mean(buffer_data[top:bottom, left:right])
np.put(self.mean, ind, buffer_mean)

def calc_mean_all_chunks(self, chunk_size: int) -> None:
def calc_mean_all_chunks(self, chunk_size: int = 10000) -> None:
while np.isnan(self.mean).any():
self.calc_mean_chunk(chunk_size)

Expand Down
27 changes: 2 additions & 25 deletions mantidimaging/gui/windows/live_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@
logger = getLogger(__name__)


class Worker(QObject):
finished = pyqtSignal()

def __init__(self, presenter: LiveViewerWindowPresenter):
super().__init__()
self.presenter = presenter

def run(self):
self.presenter.model.calc_mean_all_chunks(100)
self.finished.emit()


class LiveViewerWindowPresenter(BasePresenter):
"""
The presenter for the Live Viewer window.
Expand Down Expand Up @@ -125,7 +113,6 @@ def display_image(self, image_data_obj: Image_Data) -> None:
self.view.remove_image()
self.view.live_viewer.show_error(message)
return
# self.view.live_viewer.set_image_shape(image_data.shape)
image_data = self.perform_operations(image_data)
if image_data.size == 0:
message = "reading image: {image_path}: Image has zero size"
Expand All @@ -134,9 +121,6 @@ def display_image(self, image_data_obj: Image_Data) -> None:
self.view.live_viewer.show_error(message)
return
self.view.show_most_recent_image(image_data)
# if not self.view.live_viewer.roi_object and self.view.spectrum_action.isChecked():
# self.view.live_viewer.add_roi()
# self.model.roi = self.view.live_viewer.get_roi()
self.view.live_viewer.show_error(None)

def update_image_modified(self, image_path: Path) -> None:
Expand Down Expand Up @@ -190,15 +174,8 @@ def handle_roi_moved(self, force_new_spectrums: bool = False):
self.roi_moving = False

def run_mean_chunk_calc(self):
self.thread = QThread()
self.worker = Worker(self)
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.run)
self.worker.finished.connect(self.update_spectrum_with_mean)
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.thread.start()
self.model.calc_mean_all_chunks()
self.update_spectrum_with_mean()

def handle_roi_moved_start(self):
self.roi_moving = True
Expand Down

0 comments on commit ebdf381

Please sign in to comment.