Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: P. L. Lim <[email protected]>
  • Loading branch information
kecnry and pllim committed Feb 6, 2023
1 parent 72c9af8 commit d9e0a92
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
10 changes: 6 additions & 4 deletions jdaviz/configs/cubeviz/plugins/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ def test_fits_image_hdu_with_microns(image_cube_hdu_obj_microns, cubeviz_helper)
unc_viewer = cubeviz_helper.app.get_viewer('uncert-viewer')
label_mouseover._viewer_mouse_event(unc_viewer,
{'event': 'mousemove', 'domain': {'x': -1, 'y': 0}})
assert label_mouseover.as_text() == ('Pixel x=-1.0 y=00.0',
'World 13h41m45.5759s +27d00m12.3044s (ICRS)',
'205.4398995981 27.0034178810 (deg)') # noqa
assert label_mouseover.as_text()[0] == 'Pixel x=-1.0 y=00.0' # Out of bounds
# remaining lines are unvalidated,
# see https://github.com/spacetelescope/jdaviz/pull/1976#discussion_r1093199919
# 'World 13h41m45.5759s +27d00m12.3044s (ICRS)',
# '205.4398995981 27.0034178810 (deg)') # noqa


def test_spectrum1d_with_fake_fixed_units(spectrum1d, cubeviz_helper):
Expand Down Expand Up @@ -115,7 +117,7 @@ def test_fits_image_hdu_parse_from_file(tmpdir, image_cube_hdu_obj, cubeviz_help
unc_viewer = cubeviz_helper.app.get_viewer(cubeviz_helper._default_uncert_viewer_reference_name)
label_mouseover._viewer_mouse_event(unc_viewer,
{'event': 'mousemove', 'domain': {'x': -1, 'y': 0}})
assert label_mouseover.as_text() == ('Pixel x=-1.0 y=00.0',
assert label_mouseover.as_text() == ('Pixel x=-1.0 y=00.0', # Out of bounds
'World 13h41m46.5994s +26d59m58.6136s (ICRS)',
'205.4441642302 26.9996148973 (deg)') # noqa

Expand Down
4 changes: 1 addition & 3 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _viewer_mouse_clear_event(self, viewer, data=None):
marks.visible = False

def _viewer_mouse_event(self, viewer, data):
if data['event'] in ['mouseleave', 'mouseenter']:
if data['event'] in ('mouseleave', 'mouseenter'):
return self._viewer_mouse_clear_event(viewer, data)

if len(self.app.data_collection) < 1:
Expand Down Expand Up @@ -143,8 +143,6 @@ def _layers_changed(self, viewer):
self.update_display(viewer, self._x, self._y)

def update_display(self, viewer, x, y):
"""
"""
if isinstance(viewer, SpecvizProfileView):
self._spectrum_viewer_update(viewer, x, y)
elif isinstance(viewer,
Expand Down
29 changes: 14 additions & 15 deletions jdaviz/configs/imviz/tests/test_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,11 @@ def test_wcslink_affine_with_extras(self):
{'event': 'mousemove',
'domain': {'x': 0, 'y': 0}})

# assert label_mouseover.as_text() == ('Pixel x=00.0 y=00.0 Value +1.00000e+00',
# 'World 22h30m04.8674s -20d49m59.9990s (ICRS)',
# '337.5202808000 -20.8333330600 (deg)')
# for some reason getting:
# ('Pixel x=01.0 y=-0.0 Value +1.00000e+00',
# 'World 22h30m04.8674s -20d49m59.9990s (ICRS)',
# '337.5202808000 -20.8333330600 (deg)')
lmtext = label_mouseover.as_text()
assert lmtext[0] in ('Pixel x=01.0 y=00.0 Value +1.00000e+00',
'Pixel x=01.0 y=-0.0 Value +1.00000e+00')
assert lmtext[1:] == ('World 22h30m04.8674s -20d49m59.9990s (ICRS)',
'337.5202808000 -20.8333330600 (deg)')

# blink image through clicking with blink tool
self.viewer.toolbar.active_tool_id = 'jdaviz:blinkonce'
Expand Down Expand Up @@ -286,12 +284,11 @@ def test_wcslink_offset(self):
label_mouseover = self.imviz.app.session.application._tools['g-coords-info']
label_mouseover._viewer_mouse_event(self.viewer,
{'event': 'mousemove', 'domain': {'x': 10, 'y': 3}})
assert label_mouseover.as_text() in [('Pixel x=07.0 y=00.0 Value +0.00000e+00',
'World 00h14m19.6291s -30d23m30.9692s (ICRS)',
'3.5817877198 -30.3919358920 (deg)'),
('Pixel x=07.0 y=-0.0 Value +0.00000e+00',
'World 00h14m19.6291s -30d23m30.9692s (ICRS)',
'3.5817877198 -30.3919358920 (deg)')]
lmtext = label_mouseover.as_text()
assert lmtext[0] in ('Pixel x=07.0 y=00.0 Value +0.00000e+00',
'Pixel x=07.0 y=-0.0 Value +0.00000e+00')
assert lmtext[1:] == ('World 00h14m19.6291s -30d23m30.9692s (ICRS)',
'3.5817877198 -30.3919358920 (deg)')

assert label_mouseover.row1_unreliable
assert label_mouseover.row2_unreliable
Expand Down Expand Up @@ -349,9 +346,11 @@ def test_pixel_linking(self):
label_mouseover._viewer_mouse_event(self.viewer,
{'event': 'keydown', 'key': 'b',
'domain': {'x': -1, 'y': -1}})
self.viewer.on_mouse_or_key_event({'event': 'keydown', 'key': 'b',
'domain': {'x': -1, 'y': -1}})
assert label_mouseover.as_text() == ('Pixel x=-1.0 y=-1.0',
'World 00h14m19.5987s -30d23m31.0683s (ICRS)',
'3.5816611274 -30.3919634282 (deg)')
'World 00h14m19.5829s -30d23m30.9860s (ICRS)',
'3.5815955408 -30.3919405616 (deg)')
assert not label_mouseover.row1_unreliable
assert label_mouseover.row2_unreliable
assert label_mouseover.row3_unreliable
Expand Down
6 changes: 4 additions & 2 deletions jdaviz/configs/mosviz/tests/test_data_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_load_single_image_multi_spec(mosviz_helper, mos_image, spectrum1d, mos_

# Coordinates info panel should not crash even when nothing is loaded.
label_mouseover = mosviz_helper.app.session.application._tools['g-coords-info']
label_mouseover._viewer_mouse_event(image_viewer, {'event': 'mouseover',
label_mouseover._viewer_mouse_event(image_viewer, {'event': 'mousemove',
'domain': {'x': 0, 'y': 0}})
assert label_mouseover.as_text() == ('', '', '')

Expand Down Expand Up @@ -214,9 +214,11 @@ def test_load_single_image_multi_spec(mosviz_helper, mos_image, spectrum1d, mos_
assert label_mouseover.as_text() == ('Pixel x=00010.0 y=00100.0 Value +8.12986e-01', '', '')
assert label_mouseover.icon == 'b'

# need to trigger a mouseleave or mouseover to reset the traitlets
label_mouseover._viewer_mouse_event(spec1d_viewer, {'event': 'mouseenter'})
label_mouseover._viewer_mouse_event(spec1d_viewer,
{'event': 'mousemove', 'domain': {'x': 7000, 'y': 170}})
assert label_mouseover.as_text() == ('Cursor 7.00000e+03, 1.70000e+02 Value +8.12986e-01',
assert label_mouseover.as_text() == ('Cursor 7.00000e+03, 1.70000e+02',
'Wave 6.88889e+03 Angstrom (4 pix)',
'Flux 1.35436e+01 Jy')
assert label_mouseover.icon == 'c'
Expand Down
4 changes: 3 additions & 1 deletion jdaviz/configs/specviz2d/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ def test_2d_parser_no_unit(specviz2d_helper, mos_spectrum2d):
assert label_mouseover.icon == 'a'

viewer_1d = specviz2d_helper.app.get_viewer('spectrum-viewer')
# need to trigger a mouseleave or mouseover to reset the traitlets
label_mouseover._viewer_mouse_event(viewer_1d, {'event': 'mouseenter'})
label_mouseover._viewer_mouse_event(viewer_1d,
{'event': 'mousemove', 'domain': {'x': 6.5, 'y': 3}})
assert label_mouseover.as_text() == ('Cursor 6.50000e+00, 3.00000e+00 Value +3.74540e-01',
assert label_mouseover.as_text() == ('Cursor 6.50000e+00, 3.00000e+00',
'Wave 6.00000e+00 pix',
'Flux -3.59571e+00')
assert label_mouseover.icon == 'b'
Expand Down

0 comments on commit d9e0a92

Please sign in to comment.