Skip to content

Commit

Permalink
release note
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSullivan7 committed Feb 20, 2025
1 parent 23f9158 commit bda5df1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#2490: The Live Viewer Intensity plot now updates correctly when images are modified, i.e. deleted or multiple added files
12 changes: 7 additions & 5 deletions mantidimaging/gui/windows/live_viewer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def _handle_image_changed_in_list(self, image_files: list[Image_Data]) -> None:

def handle_image_modified(self, image_path: Path) -> None:
self.presenter.update_image_modified(image_path)
self.presenter.notify_update_image_list()

def close(self) -> None:
"""Close the model."""
Expand All @@ -192,7 +191,7 @@ def close(self) -> None:
self.image_watcher = None
self.presenter = None # type: ignore # Model instance to be destroyed -type can be inconsistent

def add_mean(self, image_data_obj: Image_Data, image_array: np.ndarray | None) -> None:
def add_mean(self, image_path: Path, image_array: np.ndarray | None) -> None:
if image_array is None:
mean_to_add = np.nan
mean_readable = 0
Expand All @@ -203,9 +202,12 @@ def add_mean(self, image_data_obj: Image_Data, image_array: np.ndarray | None) -
else:
mean_to_add = np.mean(image_array)
mean_readable = 1
self.mean_paths[image_data_obj.image_path] = (mean_to_add, mean_readable)
self.mean = np.array(list(dict(sorted(self.mean_paths.items())).values()))[:, 0]
self.mean_readable = np.array(list(dict(sorted(self.mean_paths.items())).values()))[:, 1]
self.update_mean_dict(image_path, mean_to_add, mean_readable)

def update_mean_dict(self, image_path: Path, mean_to_add: float, mean_readable: int) -> None:
self.mean_paths[image_path] = (mean_to_add, mean_readable)
self.mean = np.array(list(self.mean_paths.values()))[:, 0]
self.mean_readable = np.array(list(self.mean_paths.values()))[:, 1]

def clear_mean_partial(self) -> None:
self.mean_paths = dict.fromkeys(self.mean_paths, (np.nan, 1))
Expand Down
20 changes: 12 additions & 8 deletions mantidimaging/gui/windows/live_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,9 @@ def update_image_list(self) -> None:
if not self.view.live_viewer.roi_object:
self.view.live_viewer.add_roi()
self.model.roi = self.view.live_viewer.get_roi()
self.model.images = images_list
images_list_paths = [image.image_path for image in images_list]
if self.old_image_list_paths == images_list_paths[:-1]:
try:
image_data = self.model.image_cache.load_image(images_list[-1])
self.model.add_mean(images_list[-1], image_data)
self.update_intensity_with_mean()
except ImageLoadFailError as error:
logger.error(error.message)
self.model.add_mean(images_list[-1], None)
self.try_add_mean(images_list[-1])
self.update_intensity(self.model.mean)
self.old_image_list_paths = images_list_paths
else:
Expand All @@ -132,6 +125,15 @@ def update_image_list(self) -> None:
def notify_update_image_list(self) -> None:
self.update_image_list_timer.start(IMAGE_lIST_UPDATE_TIME)

def try_add_mean(self, image: Image_Data) -> None:
try:
image_data = self.model.image_cache.load_image(image)
self.model.add_mean(image.image_path, image_data)
self.update_intensity_with_mean()
except ImageLoadFailError as error:
logger.error(error.message)
self.model.add_mean(image.image_path, None)

def select_image(self, index: int) -> None:
if not self.model.images:
return
Expand Down Expand Up @@ -196,6 +198,8 @@ def update_image_modified(self, image_path: Path) -> None:
"""
if self.selected_image and image_path == self.selected_image.image_path:
self.display_image(self.selected_image)
self.try_add_mean(self.selected_image)
self.update_intensity_with_mean()

def update_image_operation(self) -> None:
"""
Expand Down

0 comments on commit bda5df1

Please sign in to comment.