diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_unit_conversion.py b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_unit_conversion.py index 18951593d3..48109f27f0 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_unit_conversion.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_unit_conversion.py @@ -5,7 +5,6 @@ from numpy.testing import assert_allclose from regions import PixCoord, CirclePixelRegion, RectanglePixelRegion from specutils import Spectrum1D -from glue.core.roi import XRangeROI from jdaviz.core.custom_units import PIX2, SPEC_PHOTON_FLUX_DENSITY_UNITS @@ -151,7 +150,6 @@ def test_flux_unit_choices(cubeviz_helper, flux_unit, expected_choices): def test_unit_translation(cubeviz_helper, angle_unit): # custom cube so PIXAR_SR is in metadata, and Flux units, and in MJy w, wcs_dict = cubeviz_wcs_dict() - wcs_dict['PIXAR_SR'] = 10 flux = np.zeros((30, 20, 3001), dtype=np.float32) flux[5:15, 1:11, :] = 1 cube = Spectrum1D(flux=flux * u.MJy / angle_unit, wcs=w, meta=wcs_dict) @@ -177,29 +175,9 @@ def test_unit_translation(cubeviz_helper, angle_unit): viewer_1d = cubeviz_helper.app.get_viewer( cubeviz_helper._default_spectrum_viewer_reference_name) - la = cubeviz_helper.plugins['Line Analysis'] - la.keep_active = True - viewer_1d.apply_roi(XRangeROI(6e-7, 6.2e-7)) - la.spectral_subset.selected = 'Subset 2' - - marks_before = [la._obj.continuum_marks['left'].y, - la._obj.continuum_marks['right'].y] - # change global y-units from Flux -> Surface Brightness uc_plg._obj.spectral_y_type_selected = 'Surface Brightness' - if angle_unit == PIX2: - # translation does not alter spectral_y values in viewer - pixar_sr = 1 - else: - pixar_sr = wcs_dict['PIXAR_SR'] - - marks_after = [la._obj.continuum_marks['left'].y * pixar_sr, - la._obj.continuum_marks['right'].y * pixar_sr] - - # ensure continuum marks update when spectral_y_type is changed - assert_allclose(marks_before, marks_after, rtol=1e-5) - assert uc_plg._obj.spectral_y_type_selected == 'Surface Brightness' y_display_unit = u.Unit(viewer_1d.state.y_display_unit) diff --git a/jdaviz/configs/default/plugins/markers/markers.py b/jdaviz/configs/default/plugins/markers/markers.py index c6112cb283..6497fa5470 100644 --- a/jdaviz/configs/default/plugins/markers/markers.py +++ b/jdaviz/configs/default/plugins/markers/markers.py @@ -69,6 +69,7 @@ def __init__(self, *args, **kwargs): # TODO: add "index" if/when specviz2d supports plotting spectral_axis headers = ['spectral_axis', 'spectral_axis:unit', 'pixel_x', 'pixel_y', 'value', 'value:unit', 'viewer'] + elif self.config == 'mosviz': headers = ['spectral_axis', 'spectral_axis:unit', 'pixel_x', 'pixel_y', 'world_ra', 'world_dec', 'index', diff --git a/jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py b/jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py index c84304e46f..8142d82c78 100644 --- a/jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py +++ b/jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py @@ -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.Jy / sq_angle_unit, + cube = spectrum1d_cube_custom_fluxunit(fluxunit=u.MJy / sq_angle_unit, shape=(25, 25, 4), with_uncerts=True) cubeviz_helper.load_data(cube, data_label="Test Cube") @@ -108,9 +108,46 @@ def test_cubeviz_units(cubeviz_helper, spectrum1d_cube_custom_fluxunit, results = plugin.results assert results[0]['unit'] == 'W / m2' + viewer = cubeviz_helper.app.get_viewer('spectrum-viewer') + viewer.apply_roi(XRangeROI(4.63e-7, 4.64e-7)) + + la = cubeviz_helper.plugins['Line Analysis'] + la.keep_active = True + la.spectral_subset.selected = 'Subset 1' + + marks_before = [la._obj.continuum_marks['left'].y, + la._obj.continuum_marks['right'].y] + + # change flux unit and make sure result stays the same after conversion + uc.flux_unit.selected = 'Jy' + + 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 + 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 + marks_before = marks_after + # now change to surface brightness uc.spectral_y_type = 'Surface Brightness' + if sq_angle_unit == PIX2: + # translation does not alter spectral_y values in viewer + scaling_factor = 1 + else: + scaling_factor = cube.meta.get('PIXAR_SR') + + marks_after = [la._obj.continuum_marks['left'].y, + la._obj.continuum_marks['right'].y] + + # ensure continuum marks update when spectral_y_type is changed + # multiply converted continuum marks by expected pixel scale factor + assert_allclose([mark / scaling_factor for mark in marks_before], marks_after, rtol=1e-5) + results = plugin.results line_flux_before_unit_conversion = results[0] # convert back and forth between unit<>str for string format consistency @@ -125,26 +162,6 @@ def test_cubeviz_units(cubeviz_helper, spectrum1d_cube_custom_fluxunit, np.testing.assert_allclose(float(results[0]['uncertainty']), float(line_flux_before_unit_conversion['uncertainty'])) - viewer = cubeviz_helper.app.get_viewer('spectrum-viewer') - viewer.apply_roi(XRangeROI(4.63e-7, 4.64e-7)) - - la = cubeviz_helper.plugins['Line Analysis'] - la.keep_active = True - la.spectral_subset.selected = 'Subset 1' - - marks_before = [la._obj.continuum_marks['left'].y, - la._obj.continuum_marks['right'].y] - - uc.flux_unit.selected = 'Jy' - - # multiply converted continuum marks by expected scale factor (MJy -> Jy) - scaling_factor = 1e-6 - marks_after = [la._obj.continuum_marks['left'].y * scaling_factor, - la._obj.continuum_marks['right'].y * scaling_factor] - - # ensure continuum marks update to when flux unit is converted - np.testing.assert_allclose(marks_before, marks_after, rtol=1e-5) - def test_user_api(specviz_helper, spectrum1d): label = "Test 1D Spectrum" diff --git a/jdaviz/conftest.py b/jdaviz/conftest.py index ec1fdc7a32..706a3b8827 100644 --- a/jdaviz/conftest.py +++ b/jdaviz/conftest.py @@ -260,7 +260,7 @@ def _create_spectrum1d_cube_with_fluxunit(fluxunit=u.Jy, shape=(2, 2, 4), with_u wcs_dict = {"CTYPE1": "RA---TAN", "CTYPE2": "DEC--TAN", "CTYPE3": "WAVE-LOG", "CRVAL1": 205, "CRVAL2": 27, "CRVAL3": 4.622e-7, "CDELT1": -0.0001, "CDELT2": 0.0001, "CDELT3": 8e-11, - "CRPIX1": 0, "CRPIX2": 0, "CRPIX3": 0, + "CRPIX1": 0, "CRPIX2": 0, "CRPIX3": 0, "PIXAR_SR": 10, # Need these for aperture photometry test. "TELESCOP": "JWST", "BUNIT": fluxunit.to_string(), "PIXAR_A2": 0.01} w = WCS(wcs_dict)