Skip to content

Commit

Permalink
address spec density edge case, test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gibsongreen committed Dec 19, 2024
1 parent 0ffdb5d commit 98f2852
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_markers_cubeviz_flux_unit_conversion(cubeviz_helper,
assert last_row['value:unit'] == new_cube_unit_str


def test_markers_specviz2d_flux_unit_conversion(specviz2d_helper, spectrum2d):
def test_markers_specviz2d_unit_conversion(specviz2d_helper, spectrum2d):
data = np.zeros((5, 10))
data[3] = np.arange(10)
spectrum2d = Spectrum1D(flux=data*u.MJy, spectral_axis=data[3]*u.AA)
Expand All @@ -258,10 +258,44 @@ def test_markers_specviz2d_flux_unit_conversion(specviz2d_helper, spectrum2d):
viewer2d = specviz2d_helper.app.get_viewer("spectrum-2d-viewer")
label_mouseover._viewer_mouse_event(viewer2d, {"event": "mousemove",
"domain": {"x": 6, "y": 3}})
assert label_mouseover.as_text() == ('Pixel x=06.0 y=03.0 Value +6.00000e+00 MJy',
'Wave 6.00000e+00 Angstrom',
'')
mp._obj._on_viewer_key_event(viewer2d, {'event': 'keydown',
'key': 'm'})

assert label_mouseover.as_dict()['value:unit'] == uc.flux_unit
# make sure last marker added to table reflects new unit selection
last_row = mp.export_table()[-1]
assert last_row['value:unit'] == uc.flux_unit
assert last_row['spectral_axis:unit'] == uc.spectral_unit

# ensure marks work with flux conversion where spectral axis is required and
# spectral axis conversion
uc.flux_unit = 'erg / (Angstrom s cm2)'
uc.spectral_unit = 'Ry'
label_mouseover._viewer_mouse_event(viewer2d, {"event": "mousemove",
"domain": {"x": 4, "y": 3}})
assert label_mouseover.as_text() == ('Pixel x=04.0 y=03.0 Value +7.49481e+00 erg / (Angstrom s cm2)', # noqa
'Wave 2.27817e+02 Ry',
'')
mp._obj._on_viewer_key_event(viewer2d, {'event': 'keydown',
'key': 'm'})

# make sure last marker added to table reflects new unit selection
last_row = mp.export_table()[-1]
assert last_row['value:unit'] == uc.flux_unit
assert last_row['spectral_axis:unit'] == uc.spectral_unit

second_marker_flux_unit = uc.flux_unit.selected
second_marker_spectral_unit = uc.spectral_unit.selected

# test edge case two non-native spectral axis required conversions
uc.flux_unit = 'ph / (Angstrom s cm2)'
uc.spectral_unit = 'eV'

# make sure table flux and spectral unit doesn't update
assert last_row['value:unit'] == second_marker_flux_unit
assert last_row['spectral_axis:unit'] == second_marker_spectral_unit


class TestImvizMultiLayer(BaseImviz_WCS_NoWCS):
Expand Down
5 changes: 2 additions & 3 deletions jdaviz/core/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ def set_y_unit(self, unit=None):
if self.yunit is not None and not np.all([s == 0 for s in self.y.shape]): # noqa

if self.viewer.default_class is Spectrum1D:

spec = self.viewer.state.reference_data.get_object(cls=Spectrum1D)
if self.xunit is None:
self.xunit = self.viewer.jdaviz_helper.app._get_display_unit('spectral')
return

Check warning on line 143 in jdaviz/core/marks.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/core/marks.py#L143

Added line #L143 was not covered by tests
spec = self.viewer.state.reference_data.get_object(cls=Spectrum1D)

pixar_sr = spec.meta.get('PIXAR_SR', 1)
cube_wave = self.x * self.xunit
Expand Down

0 comments on commit 98f2852

Please sign in to comment.