From de47f7f50edf4a968b3cdeb9446fb04d7da883b9 Mon Sep 17 00:00:00 2001 From: Zak V Date: Fri, 31 Jul 2020 16:38:06 -0400 Subject: [PATCH 1/2] IMAQdx camera blacs tab now saves/restores more of the display's settings. --- labscript_devices/IMAQdxCamera/blacs_tabs.py | 75 +++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/labscript_devices/IMAQdxCamera/blacs_tabs.py b/labscript_devices/IMAQdxCamera/blacs_tabs.py index f3b42226..035c53ae 100644 --- a/labscript_devices/IMAQdxCamera/blacs_tabs.py +++ b/labscript_devices/IMAQdxCamera/blacs_tabs.py @@ -169,13 +169,40 @@ def initialise_GUI(self): self.supports_smart_programming(self.use_smart_programming) def get_save_data(self): - return { + save_data = { 'attribute_visibility': self.attributes_dialog.comboBox.currentText(), 'acquiring': self.acquiring, 'max_rate': self.ui.doubleSpinBox_maxrate.value(), 'colormap': repr(self.image.ui.histogram.gradient.saveState()) } + # Save info about plot settings if an image is plotted. + image = self.image.image + if image is not None: + # Save the shape and dtype of the image. + save_data['image_shape'] = repr(image.shape) + save_data['image_dtype'] = str(image.dtype) + + # Get the view_box to access its settings. + view_box = self.image.getImageItem().getViewBox() + + # Save x and y ranges. + targetRange_x, targetRange_y = view_box.targetRange() + save_data['targetRange_x'] = targetRange_x + save_data['targetRange_y'] = targetRange_y + + # Save whether the x and y ranges are automatically adjusted. + autoRange_x, autoRange_y = view_box.autoRangeEnabled() + save_data['autoRange_x'] = autoRange_x + save_data['autoRange_y'] = autoRange_y + + # Save color scale limits. + color_scale_min, color_scale_max = self.image.getLevels() + save_data['color_scale_min'] = color_scale_min + save_data['color_scale_max'] = color_scale_max + + return save_data + def restore_save_data(self, save_data): self.attributes_dialog.comboBox.setCurrentText( save_data.get('attribute_visibility', 'simple') @@ -189,6 +216,52 @@ def restore_save_data(self, save_data): ast.literal_eval(save_data['colormap']) ) + # Restore plot settings if they were saved. + if 'image_shape' in save_data and 'image_dtype' in save_data: + # Some image must be displayed now, otherwise the plot settings will + # be overwritten once the first image is displayed. We'll display a + # mostly blank image of the saved size and data type. + image_shape = ast.literal_eval(save_data['image_shape']) + image_dtype = np.dtype(save_data['image_dtype']) + dummy_image = np.zeros(image_shape, dtype=image_dtype) + # Make one pixel nonzero to avoid a histogram binning error. This is + # fixed by in pyqtgraph 0.11 by + # https://github.com/pyqtgraph/pyqtgraph/pull/767 but is retained + # for compatability with older versions. + if dummy_image.ndim == 2: + dummy_image[0, 0] = 1 + if dummy_image.ndim == 3: + dummy_image[:, 0, 0] = 1 + self.image.setImage(dummy_image) + + # Restore x and y ranges. + try: + view_box = self.image.getImageItem().getViewBox() + view_box.setRange( + xRange=save_data['targetRange_x'], + yRange=save_data['targetRange_y'], + ) + except KeyError: + pass + + # Restore whether the x and y ranges are automatically adjusted. + try: + view_box.enableAutoRange( + x=save_data['autoRange_x'], + y=save_data['autoRange_y'], + ) + except KeyError: + pass + + # Restore color scale range. + try: + self.image.setLevels( + save_data['color_scale_min'], + save_data['color_scale_max'], + ) + except KeyError: + pass + def initialise_workers(self): table = self.settings['connection_table'] From b61e878ece35a3407007d577f7d30de5be420181 Mon Sep 17 00:00:00 2001 From: Zak V Date: Sun, 22 Aug 2021 10:36:49 -0400 Subject: [PATCH 2/2] Clarified a comment in IMAQdxCameraTab.restore_save_data(). --- labscript_devices/IMAQdxCamera/blacs_tabs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/labscript_devices/IMAQdxCamera/blacs_tabs.py b/labscript_devices/IMAQdxCamera/blacs_tabs.py index 035c53ae..a9fea696 100644 --- a/labscript_devices/IMAQdxCamera/blacs_tabs.py +++ b/labscript_devices/IMAQdxCamera/blacs_tabs.py @@ -226,8 +226,8 @@ def restore_save_data(self, save_data): dummy_image = np.zeros(image_shape, dtype=image_dtype) # Make one pixel nonzero to avoid a histogram binning error. This is # fixed by in pyqtgraph 0.11 by - # https://github.com/pyqtgraph/pyqtgraph/pull/767 but is retained - # for compatability with older versions. + # https://github.com/pyqtgraph/pyqtgraph/pull/767 but this + # workaround is retained for compatibility with older versions. if dummy_image.ndim == 2: dummy_image[0, 0] = 1 if dummy_image.ndim == 3: