From 6ac80f64135c455c602e0177c5919cababe02cbe Mon Sep 17 00:00:00 2001 From: Clare Shanahan Date: Fri, 9 Aug 2024 16:48:40 -0400 Subject: [PATCH] adding part of a test --- .../tests/test_unit_conversion.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/jdaviz/configs/specviz/plugins/unit_conversion/tests/test_unit_conversion.py b/jdaviz/configs/specviz/plugins/unit_conversion/tests/test_unit_conversion.py index 4380599b02..bf78fc0784 100644 --- a/jdaviz/configs/specviz/plugins/unit_conversion/tests/test_unit_conversion.py +++ b/jdaviz/configs/specviz/plugins/unit_conversion/tests/test_unit_conversion.py @@ -198,6 +198,11 @@ def test_sb_unit_conversion(cubeviz_helper): viewer_1d = cubeviz_helper.app.get_viewer( cubeviz_helper._default_spectrum_viewer_reference_name) + assert label_mouseover.as_text() == ( + "Pixel x=00010.0 y=00008.0 Value +1.00000e+06 MJy / sr", + "World 13h39m59.7037s +27d00m03.2400s (ICRS)", + "204.9987654313 27.0008999946 (deg)") + uc_plg.flux_or_sb.selected = 'Surface Brightness' # Surface Brightness conversion @@ -251,3 +256,51 @@ def test_sb_unit_conversion(cubeviz_helper): la = cubeviz_helper.plugins['Line Analysis']._obj assert la.dataset.get_selected_spectrum(use_display_units=True) + +def test_mouseover_display_unit(cubeviz_helper): + + # custom cube to have Surface Brightness units + wcs_dict = {"CTYPE1": "WAVE-LOG", "CTYPE2": "DEC--TAN", "CTYPE3": "RA---TAN", + "CRVAL1": 4.622e-7, "CRVAL2": 27, "CRVAL3": 205, + "CDELT1": 8e-11, "CDELT2": 0.0001, "CDELT3": -0.0001, + "CRPIX1": 0, "CRPIX2": 0, "CRPIX3": 0, "PIXAR_SR": 8e-11} + w = WCS(wcs_dict) + flux = np.zeros((30, 20, 3001), dtype=np.float32) + flux[5:15, 1:11, :] = 1 + cube = Spectrum1D(flux=flux * (u.MJy / u.sr), wcs=w, meta=wcs_dict) + cubeviz_helper.load_data(cube, data_label="test") + + uc_plg = cubeviz_helper.plugins['Unit Conversion'] + uc_plg.open_in_tray() + + # ensure that per solid angle cube defaults to Flux spectrum + assert uc_plg.flux_or_sb == 'Flux' + + # make sure the mouseover display unit for a cube loaded in surface + # brighntess units reflects the selected 'flux' unit + + + # test mouseover while spectral y axis is in 'Flux' + # coords_info should pick up the selected flux unit to display the + # data unit, which is in surface brightness + label_mouseover._viewer_mouse_event( + flux_viewer, {"event": "mousemove", "domain": {"x": 10, "y": 8}} + ) + + assert label_mouseover.as_text() == ( + "Pixel x=00010.0 y=00008.0 Value +1.00000e+00 MJy / sr", + "World 13h39m59.7037s +27d00m03.2400s (ICRS)", + "204.9987654313 27.0008999946 (deg)") + + # change unit, but spectral y axis is still in 'flux' + # make sure surface brightness display unit still updates + # accordingly + uc_plg.flux_unit = 'Jy' + + assert label_mouseover.as_text() == ( + "Pixel x=00010.0 y=00008.0 Value +1.00000e+06 Jy / sr", + "World 13h39m59.7037s +27d00m03.2400s (ICRS)", + "204.9987654313 27.0008999946 (deg)") + + +