From ce25f7f6e860c4d068b375356807c9ff179f65f0 Mon Sep 17 00:00:00 2001 From: Jesse Averbukh Date: Tue, 17 May 2022 12:19:55 -0400 Subject: [PATCH] Allow cubeviz image viewer to display coords for 2D data --- jdaviz/configs/cubeviz/plugins/viewers.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/viewers.py b/jdaviz/configs/cubeviz/plugins/viewers.py index c88c889d56..88c26aff17 100644 --- a/jdaviz/configs/cubeviz/plugins/viewers.py +++ b/jdaviz/configs/cubeviz/plugins/viewers.py @@ -91,13 +91,16 @@ def on_mouse_or_key_event(self, data): self.label_mouseover.reset_coords_display() # Extract data values at this position. - # Assume shape is [x, y, z] and not [y, x] like Imviz. - if (x > -0.5 and y > -0.5 - and x < image.shape[0] - 0.5 and y < image.shape[1] - 0.5 + # Check if shape is [x, y, z] or [x, y] and show value accordingly. + if (-0.5 < x < image.shape[0] - 0.5 and -0.5 < y < image.shape[1] - 0.5 and hasattr(visible_layers[0], 'attribute')): attribute = visible_layers[0].attribute - value = image.get_data(attribute)[int(round(x)), int(round(y)), - self.state.slices[-1]] + if len(image.shape) == 3: + value = image.get_data(attribute)[int(round(x)), int(round(y)), + self.state.slices[-1]] + elif len(image.shape) == 2: + value = image.get_data(attribute)[int(round(x)), int(round(y))] + unit = image.get_component(attribute).units self.label_mouseover.value = f'{value:+10.5e} {unit}' else: