Skip to content

Commit

Permalink
BUG: Cubeviz coords info to show top layer
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Jul 4, 2022
1 parent 050b62d commit e87e4cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ Cubeviz

- Fixed linking of plugin data to the reference data that was used to create it [#1412]

- Fixed coordinates display not showing the top layer information when multiple
layers are loaded into the image viewer. [#1445]

Imviz
^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
def test_moment_calculation(cubeviz_helper, spectrum1d_cube, tmpdir):
dc = cubeviz_helper.app.data_collection
cubeviz_helper.load_data(spectrum1d_cube, data_label='test')
flux_viewer = cubeviz_helper.app.get_viewer('flux-viewer')

# Since we are not really displaying, need this to trigger GUI stuff.
flux_viewer.shape = (100, 100)
flux_viewer.state._set_axes_aspect_ratio(1)

mm = MomentMap(app=cubeviz_helper.app)
mm.dataset_selected = 'test[FLUX]'
Expand All @@ -33,20 +38,29 @@ def test_moment_calculation(cubeviz_helper, spectrum1d_cube, tmpdir):
assert mm.results_label == 'moment 0'
assert mm.results_label_overwrite is True

# Make sure coordinate display works
flux_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
assert flux_viewer.state.slices == (0, 0, 1)
assert flux_viewer.label_mouseover.pixel == 'x=00.0 y=00.0'
assert flux_viewer.label_mouseover.value == '+8.00000e+00 Jy' # Slice 0 has 8 pixels, this is Slice 1 # noqa
assert flux_viewer.label_mouseover.world_ra_deg == '204.9997755346'
assert flux_viewer.label_mouseover.world_dec_deg == '27.0000999998'

# Make sure adding it to viewer does not crash.
cubeviz_helper.app.add_data_to_viewer('flux-viewer', 'moment 0')

result = dc[1].get_object(cls=CCDData)
assert result.shape == (4, 2) # Cube shape is (2, 2, 4)

# FIXME: Need spatial WCS, see https://github.com/spacetelescope/jdaviz/issues/1025
assert dc[1].coords is None

# Make sure coordinate display still works
flux_viewer = cubeviz_helper.app.get_viewer('flux-viewer')
# Make sure coordinate display now show moment map info (no WCS)
flux_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 0, 'y': 0}})
assert flux_viewer.state.slices == (0, 0, 1)
assert flux_viewer.label_mouseover.pixel == 'x=00.0 y=00.0'
assert flux_viewer.label_mouseover.value == '+8.00000e+00 Jy' # Slice 0 has 8 pixels, this is Slice 1 # noqa
assert flux_viewer.label_mouseover.world_ra_deg == '204.9997755346'
assert flux_viewer.label_mouseover.world_dec_deg == '27.0000999998'
assert flux_viewer.label_mouseover.world_ra_deg == ''
assert flux_viewer.label_mouseover.world_dec_deg == ''

assert mm.filename == 'moment0_test_FLUX.fits' # Auto-populated on calculate.
mm.filename = str(tmpdir.join(mm.filename)) # But we want it in tmpdir for testing.
Expand Down Expand Up @@ -82,5 +96,5 @@ def test_moment_calculation(cubeviz_helper, spectrum1d_cube, tmpdir):
# Coordinate display should be unaffected.
assert flux_viewer.label_mouseover.pixel == 'x=00.0 y=00.0'
assert flux_viewer.label_mouseover.value == '+8.00000e+00 Jy' # Slice 0 has 8 pixels, this is Slice 1 # noqa
assert flux_viewer.label_mouseover.world_ra_deg == '204.9997755346'
assert flux_viewer.label_mouseover.world_dec_deg == '27.0000999998'
assert flux_viewer.label_mouseover.world_ra_deg == ''
assert flux_viewer.label_mouseover.world_dec_deg == ''
7 changes: 4 additions & 3 deletions jdaviz/configs/cubeviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def on_mouse_or_key_event(self, data):

# Extract first dataset from visible layers and use this for coordinates - the choice
# of dataset shouldn't matter if the datasets are linked correctly
image = visible_layers[0].layer
active_layer = visible_layers[-1]
image = active_layer.layer

# Extract data coordinates - these are pixels in the reference image
x = data['domain']['x']
Expand Down Expand Up @@ -94,8 +95,8 @@ def on_mouse_or_key_event(self, data):
# Extract data values at this position.
# 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
and hasattr(active_layer, 'attribute')):
attribute = active_layer.attribute
if len(image.shape) == 3:
value = image.get_data(attribute)[int(round(x)), int(round(y)),
self.state.slices[-1]]
Expand Down

0 comments on commit e87e4cf

Please sign in to comment.