Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gibsongreen committed Jan 24, 2025
1 parent 3e7d1ae commit d2411c1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
13 changes: 4 additions & 9 deletions jdaviz/configs/mosviz/plugins/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,13 @@ def _is_matched_viewer(self, viewer):
def _map_limits(self, from_viewer, to_viewer, limits={}):
components = self.viewer.state.data_collection[0]._components
# Determine cid for spectral axis
cid = None
for key in components.keys():
if 'Wavelength' in str(key):
cid = str(key)
strkey = str(key)
if 'Wavelength' in strkey or 'Wave' in strkey:
native_unit = u.Unit(self.viewer.state.data_collection[0].get_component(strkey).units) # noqa
break

Check warning on line 28 in jdaviz/configs/mosviz/plugins/tools.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/configs/mosviz/plugins/tools.py#L27-L28

Added lines #L27 - L28 were not covered by tests
elif 'Wave' in str(key):
cid = str(key)
break

if cid is not None:
native_unit = u.Unit(self.viewer.state.data_collection[0].get_component(cid).units)
else:
# no matches found
native_unit = ''
current_display_unit = u.Unit(self.viewer.jdaviz_helper.app._get_display_unit('spectral'))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_cubeviz_units(cubeviz_helper, spectrum1d_cube_custom_fluxunit,
is in flux/pix2 and flux/sr, and that the results remain consistant
between translations of the spectral y axis flux<>surface brightness.
"""
cube = spectrum1d_cube_custom_fluxunit(fluxunit=u.MJy / sq_angle_unit,
cube = spectrum1d_cube_custom_fluxunit(fluxunit=u.Jy / sq_angle_unit,
shape=(25, 25, 4), with_uncerts=True)
cubeviz_helper.load_data(cube, data_label="Test Cube")

Expand All @@ -119,14 +119,14 @@ def test_cubeviz_units(cubeviz_helper, spectrum1d_cube_custom_fluxunit,
la._obj.continuum_marks['right'].y]

# change flux unit and make sure result stays the same after conversion
uc.flux_unit.selected = 'Jy'
uc.flux_unit.selected = 'MJy'

marks_after = [la._obj.continuum_marks['left'].y,
la._obj.continuum_marks['right'].y]

# ensure continuum marks update when spectral_y is changed by
# multiply converted continuum marks by expected scale factor (MJy -> Jy)
scaling_factor = 1e6
scaling_factor = 1e-6
assert_allclose([mark * scaling_factor for mark in marks_before], marks_after, rtol=1e-5)

# reset to test again after spectral_y_type is changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ def import_trace(self, trace):
else: # pragma: no cover
raise NotImplementedError(f"trace of type {trace.__class__.__name__} not supported")

# UPDATE HERE
@with_spinner('trace_spinner')
def export_trace(self, add_data=False, **kwargs):
"""
Expand Down
27 changes: 27 additions & 0 deletions jdaviz/core/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from astropy.nddata import NDData
from numpy.testing import assert_allclose
from photutils.datasets import make_4gaussians_image
from specutils import Spectrum1D

from jdaviz.tests.test_utils import PHOTUTILS_LT_1_12_1

Expand Down Expand Up @@ -170,3 +171,29 @@ def test_unit_conversion_limits_update(specviz2d_helper, mos_spectrum2d):
# test again when matching viewer's limits are reset
assert_allclose(spec_viewer_lims_before, spec_viewer.get_limits())
assert_allclose(spec2d_viewer_lims_before, spec2d_viewer.get_limits())


def test_match_limits_without_wave_component(specviz2d_helper):
data = np.zeros((5, 10))
spec2d = Spectrum1D(flux=data*u.MJy)
specviz2d_helper.load_data(spec2d)

spec_viewer = specviz2d_helper.app.get_viewer(
specviz2d_helper.app._jdaviz_helper._default_spectrum_viewer_reference_name)
spec2d_viewer = specviz2d_helper.app.get_viewer(
specviz2d_helper.app._jdaviz_helper._default_spectrum_2d_viewer_reference_name)

spec_viewer_lims_before = spec_viewer.get_limits()
spec2d_viewer_lims_before = spec2d_viewer.get_limits()

spec_viewer.reset_limits()

# ensure limits reset when Wave nor Wavelength component is present
assert_allclose(spec_viewer_lims_before, spec_viewer.get_limits())
assert_allclose(spec2d_viewer_lims_before, spec2d_viewer.get_limits())

spec2d_viewer.reset_limits()

# test again when when limits are reset with spectrum2d-viewer
assert_allclose(spec_viewer_lims_before, spec_viewer.get_limits())
assert_allclose(spec2d_viewer_lims_before, spec2d_viewer.get_limits())

0 comments on commit d2411c1

Please sign in to comment.