Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Cubeviz coordinate display should follow top visible layer #1445

Merged
merged 2 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def vue_calculate_moment(self, *args):
except ValueError:
raise ValueError("Moment must be a positive integer")
# Need transpose to align JWST mirror shape. Not sure why.
# TODO: WCS can be grabbed from cube.wcs[:, :, 0] but CCDData will not take it.
# But if we use NDData, glue-astronomy translator fails.
self.moment = CCDData(analysis.moment(slab, order=n_moment).T)

fname_label = self.dataset_selected.replace("[", "_").replace("]", "")
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