From e0fd97616d370722e2ebf12d0f93862ac35cb20d Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Thu, 11 Dec 2025 18:11:45 +0100 Subject: [PATCH] fix(heatmap): flush image if config changes during scan --- bec_widgets/widgets/plots/heatmap/heatmap.py | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bec_widgets/widgets/plots/heatmap/heatmap.py b/bec_widgets/widgets/plots/heatmap/heatmap.py index 4c646d85..e1142aa1 100644 --- a/bec_widgets/widgets/plots/heatmap/heatmap.py +++ b/bec_widgets/widgets/plots/heatmap/heatmap.py @@ -268,6 +268,20 @@ class Heatmap(ImageBase): if show_config_label is None: show_config_label = self._image_config.show_config_label + def _device_key(device: HeatmapDeviceSignal | None) -> tuple[str | None, str | None]: + return (device.name if device else None, device.entry if device else None) + + prev_cfg = getattr(self, "_image_config", None) + config_changed = False + if prev_cfg and prev_cfg.x_device and prev_cfg.y_device and prev_cfg.z_device: + config_changed = any( + ( + _device_key(prev_cfg.x_device) != (x_name, x_entry), + _device_key(prev_cfg.y_device) != (y_name, y_entry), + _device_key(prev_cfg.z_device) != (z_name, z_entry), + ) + ) + self._image_config = HeatmapConfig( parent_id=self.gui_id, x_device=HeatmapDeviceSignal(name=x_name, entry=x_entry), @@ -282,7 +296,10 @@ class Heatmap(ImageBase): show_config_label=show_config_label, ) self.color_map = color_map - self.reload = reload + self.reload = reload or config_changed + if config_changed: + self._grid_index = None + self.main_image.clear() self.update_labels() self._fetch_running_scan() @@ -613,6 +630,8 @@ class Heatmap(ImageBase): if data is None or data.shape != shape: data = np.empty(shape) data.fill(np.nan) + elif self.reload: + data.fill(np.nan) def _get_grid_data(axis, snaked=True): x_grid, y_grid = np.meshgrid(axis[0], axis[1])