-
Notifications
You must be signed in to change notification settings - Fork 75
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
Improve coordinates display panel for spectrum viewer #1894
Changes from all commits
686d0c2
aa30511
a1bb696
ac3871e
71625dc
129820d
c74be61
19fb2b2
ef6d3b7
18c9d34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
import pytest | ||
from jdaviz import Application | ||
from astropy.utils.exceptions import AstropyUserWarning | ||
from specutils import Spectrum1D | ||
|
||
from jdaviz.configs.default.plugins.gaussian_smooth.gaussian_smooth import GaussianSmooth | ||
|
||
|
||
def test_linking_after_spectral_smooth(spectrum1d_cube): | ||
|
||
app = Application(configuration="cubeviz") | ||
def test_linking_after_spectral_smooth(cubeviz_helper, spectrum1d_cube): | ||
app = cubeviz_helper.app | ||
dc = app.data_collection | ||
app.add_data(spectrum1d_cube, 'test') | ||
app.add_data_to_viewer('flux-viewer', 'test') | ||
cubeviz_helper.load_data(spectrum1d_cube, data_label='test') | ||
spec_viewer = cubeviz_helper.app.get_viewer('spectrum-viewer') | ||
|
||
assert len(dc) == 1 | ||
|
||
gs = GaussianSmooth(app=app) | ||
gs.dataset_selected = 'test' | ||
gs = cubeviz_helper.plugins['Gaussian Smooth']._obj | ||
gs.dataset_selected = 'test[FLUX]' | ||
gs.mode_selected = 'Spectral' | ||
gs.stddev = 3.2 | ||
gs.add_to_viewer_selected = 'None' | ||
|
@@ -40,8 +37,8 @@ def test_linking_after_spectral_smooth(spectrum1d_cube): | |
# itself is prepended to the default label, and there is no longer | ||
# an overwrite warning. | ||
assert len(gs.dataset_items) == 2 | ||
assert gs.dataset_selected == 'test' | ||
assert gs.results_label == 'test spectral-smooth stddev-3.2' | ||
assert gs.dataset_selected == 'test[FLUX]' | ||
assert gs.results_label == 'test[FLUX] spectral-smooth stddev-3.2' | ||
assert gs.results_label_overwrite is False | ||
|
||
assert len(dc) == 2 | ||
|
@@ -68,21 +65,100 @@ def test_linking_after_spectral_smooth(spectrum1d_cube): | |
assert dc.external_links[2].cids1[0] == dc[0].pixel_component_ids[2] | ||
assert dc.external_links[2].cids2[0] == dc[-1].pixel_component_ids[2] | ||
|
||
# Mouseover should automatically jump from one spectrum | ||
# to another, depending on which one is closer. | ||
|
||
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 4.6236e-7, 'y': 60}}) | ||
assert spec_viewer.label_mouseover.pixel == '4.62360e-07, 6.00000e+01' | ||
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' | ||
assert spec_viewer.label_mouseover.world_ra == '4.62360e-07 m (1 pix)' | ||
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' | ||
assert spec_viewer.label_mouseover.world_ra_deg == '9.20000e+01 Jy' | ||
assert spec_viewer.label_mouseover.icon == 'a' | ||
|
||
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 4.6236e-7, 'y': 20}}) | ||
assert spec_viewer.label_mouseover.pixel == '4.62360e-07, 2.00000e+01' | ||
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' | ||
assert spec_viewer.label_mouseover.world_ra == '4.62360e-07 m (1 pix)' | ||
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' | ||
assert spec_viewer.label_mouseover.world_ra_deg == '1.47943e+01 Jy' | ||
assert spec_viewer.label_mouseover.icon == 'b' | ||
|
||
# Check mouseover behavior when we hide everything. | ||
for lyr in spec_viewer.layers: | ||
lyr.visible = False | ||
|
||
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 4.6236e-7, 'y': 60}}) | ||
assert spec_viewer.label_mouseover.pixel == '' | ||
assert spec_viewer.label_mouseover.world_label_prefix == '\xa0' | ||
assert spec_viewer.label_mouseover.world_ra == '' | ||
assert spec_viewer.label_mouseover.world_dec == '' | ||
assert spec_viewer.label_mouseover.world_label_prefix_2 == '\xa0' | ||
assert spec_viewer.label_mouseover.world_ra_deg == '' | ||
assert spec_viewer.label_mouseover.world_dec_deg == '' | ||
assert spec_viewer.label_mouseover.icon == '' | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore::UserWarning") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the warning check to the affected line. This way, we won't accidentally ignore warning that we're not supposed to ignore. |
||
def test_spatial_convolution(cubeviz_helper, spectrum1d_cube): | ||
dc = cubeviz_helper.app.data_collection | ||
cubeviz_helper.app.add_data(spectrum1d_cube, 'test') | ||
cubeviz_helper.app.add_data_to_viewer('flux-viewer', 'test') | ||
cubeviz_helper.load_data(spectrum1d_cube, data_label='test') | ||
|
||
gs = GaussianSmooth(app=cubeviz_helper.app) | ||
gs.dataset_selected = 'test' | ||
gs = cubeviz_helper.plugins['Gaussian Smooth']._obj | ||
gs.dataset_selected = 'test[FLUX]' | ||
gs.mode_selected = 'Spatial' | ||
gs.stddev = 3 | ||
assert gs.results_label == 'spatial-smooth stddev-3.0' | ||
gs.vue_apply() | ||
with pytest.warns( | ||
AstropyUserWarning, | ||
match='The following attributes were set on the data object, but will be ignored'): | ||
gs.vue_apply() | ||
|
||
assert len(dc) == 2 | ||
assert dc[1].label == "spatial-smooth stddev-3.0" | ||
assert dc[1].shape == (2, 4, 2) # specutils moved spectral axis to last | ||
assert (dc["spatial-smooth stddev-3.0"].get_object(cls=Spectrum1D, statistic=None).shape | ||
== (4, 2, 2)) | ||
== (2, 4, 2)) | ||
|
||
|
||
def test_spectrum1d_smooth(specviz_helper, spectrum1d): | ||
dc = specviz_helper.app.data_collection | ||
specviz_helper.load_data(spectrum1d, data_label='test') | ||
spec_viewer = specviz_helper.app.get_viewer('spectrum-viewer') | ||
|
||
gs = specviz_helper.plugins['Gaussian Smooth']._obj | ||
gs.dataset_selected = 'test' | ||
gs.mode_selected = 'Spectral' | ||
gs.stddev = 10 | ||
gs.vue_apply() | ||
|
||
assert len(dc) == 2 | ||
assert dc[1].label == 'smooth stddev-10.0' | ||
|
||
# Mouseover should automatically jump from one spectrum | ||
# to another, depending on which one is closer. | ||
|
||
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6400, 'y': 120}}) | ||
assert spec_viewer.label_mouseover.pixel == '6.40000e+03, 1.20000e+02' | ||
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' | ||
assert spec_viewer.label_mouseover.world_ra == '6.44444e+03 Angstrom (2 pix)' | ||
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' | ||
assert spec_viewer.label_mouseover.world_ra_deg == '1.35366e+01 Jy' | ||
assert spec_viewer.label_mouseover.icon == 'a' | ||
|
||
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 6400, 'y': 5}}) | ||
assert spec_viewer.label_mouseover.world_label_prefix == 'Wave' | ||
assert spec_viewer.label_mouseover.world_ra == '6.44444e+03 Angstrom (2 pix)' | ||
assert spec_viewer.label_mouseover.world_label_prefix_2 == 'Flux' | ||
assert spec_viewer.label_mouseover.world_ra_deg == '5.34688e+00 Jy' | ||
assert spec_viewer.label_mouseover.icon == 'b' | ||
|
||
# Out-of-bounds shows nothing. | ||
spec_viewer.on_mouse_or_key_event({'event': 'mousemove', 'domain': {'x': 5500, 'y': 120}}) | ||
assert spec_viewer.label_mouseover.pixel == '' | ||
assert spec_viewer.label_mouseover.world_label_prefix == '\xa0' | ||
assert spec_viewer.label_mouseover.world_ra == '' | ||
assert spec_viewer.label_mouseover.world_dec == '' | ||
assert spec_viewer.label_mouseover.world_label_prefix_2 == '\xa0' | ||
assert spec_viewer.label_mouseover.world_ra_deg == '' | ||
assert spec_viewer.label_mouseover.world_dec_deg == '' | ||
assert spec_viewer.label_mouseover.icon == '' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from traitlets import Bool, Unicode | ||
|
||
from jdaviz.configs.specviz.plugins.viewers import SpecvizProfileView | ||
from jdaviz.core.registries import tool_registry | ||
from jdaviz.core.template_mixin import TemplateMixin | ||
from jdaviz.core.marks import PluginScatter | ||
|
||
__all__ = ['CoordsInfo'] | ||
|
||
|
@@ -10,9 +12,11 @@ | |
class CoordsInfo(TemplateMixin): | ||
template_file = __file__, "coords_info.vue" | ||
icon = Unicode("").tag(sync=True) | ||
pixel_prefix = Unicode("Pixel").tag(sync=True) | ||
pixel = Unicode("").tag(sync=True) | ||
value = Unicode("").tag(sync=True) | ||
world_label_prefix = Unicode("\u00A0").tag(sync=True) | ||
world_label_prefix_2 = Unicode("\u00A0").tag(sync=True) | ||
world_label_icrs = Unicode("\u00A0").tag(sync=True) | ||
world_label_deg = Unicode("\u00A0").tag(sync=True) | ||
world_ra = Unicode("").tag(sync=True) | ||
|
@@ -22,8 +26,33 @@ class CoordsInfo(TemplateMixin): | |
unreliable_world = Bool(False).tag(sync=True) | ||
unreliable_pixel = Bool(False).tag(sync=True) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._marks = {} | ||
|
||
@property | ||
def marks(self): | ||
""" | ||
Access the marks created by this plugin. | ||
""" | ||
if self._marks: | ||
# TODO: replace with cache property? | ||
return self._marks | ||
|
||
# create marks for each of the spectral viewers (will need a listener event to create marks | ||
# for new viewers if dynamic creation of spectral viewers is ever supported) | ||
for id, viewer in self.app._viewer_store.items(): | ||
if isinstance(viewer, SpecvizProfileView): | ||
self._marks[id] = PluginScatter(viewer, | ||
marker='rectangle', stroke_width=1, | ||
visible=False) | ||
viewer.figure.marks = viewer.figure.marks + [self._marks[id]] | ||
return self._marks | ||
|
||
def reset_coords_display(self): | ||
self.pixel_prefix = "Pixel" | ||
self.world_label_prefix = '\u00A0' | ||
self.world_label_prefix_2 = '\u00A0' | ||
self.world_label_icrs = '\u00A0' | ||
self.world_label_deg = '\u00A0' | ||
self.world_ra = '' | ||
|
@@ -44,6 +73,7 @@ def set_coords(self, sky, unreliable_world=False, unreliable_pixel=False): | |
if "nan" in (world_ra, world_dec, world_ra_deg, world_dec_deg): | ||
self.reset_coords_display() | ||
else: | ||
self.pixel_prefix = 'Pixel' | ||
self.world_label_prefix = 'World' | ||
self.world_label_icrs = '(ICRS)' | ||
self.world_label_deg = '(deg)' | ||
|
@@ -53,3 +83,7 @@ def set_coords(self, sky, unreliable_world=False, unreliable_pixel=False): | |
self.world_dec_deg = world_dec_deg | ||
self.unreliable_world = unreliable_world | ||
self.unreliable_pixel = unreliable_pixel | ||
if unreliable_world: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this statement always true? 😏 |
||
self.world_label_prefix_2 = '(est.)' | ||
else: | ||
self.world_label_prefix_2 = '\u00A0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is slight behavior change when you use the proper route to load the data into Cubeviz. I think this is more correct as a test because this is how user will actually load it.