From 60a564b4150684122f0fc7eae9e9db46964c9ac8 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:29:39 -0500 Subject: [PATCH] Fix table GUI for slice wavelength and display slice wavelength instead of index in read-only text field. --- docs/cubeviz/export_data.rst | 2 +- .../plugins/tests/test_cubeviz_aperphot.py | 14 +++++++------- .../plugins/aper_phot_simple/aper_phot_simple.py | 15 +++++++-------- .../plugins/aper_phot_simple/aper_phot_simple.vue | 7 ++----- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/docs/cubeviz/export_data.rst b/docs/cubeviz/export_data.rst index 42144d38f2..fb860fd915 100644 --- a/docs/cubeviz/export_data.rst +++ b/docs/cubeviz/export_data.rst @@ -154,5 +154,5 @@ Cubeviz can export photometry output table like Imviz: In addition to the columns that :ref:`Imviz Aperture Photometry ` would provide, the table from Cubeviz has this extra column after ``data_label``: -* ``slice``: Wavelength value at the selected slice of the cube used for computation. +* ``slice_wave``: Wavelength value at the selected slice of the cube used for computation. If a 2D data (e.g., collapsed cube) is selected, the value would be NaN instead. diff --git a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py index 2ac9d2a9df..891b069cab 100644 --- a/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py +++ b/jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py @@ -19,7 +19,7 @@ def test_cubeviz_aperphot_cube_orig_flux(cubeviz_helper, image_cube_hdu_obj_micr plg = cubeviz_helper.plugins["Aperture Photometry"]._obj assert plg.dataset.labels == ["test[FLUX]", "test[ERR]"] - assert int(plg.cube_slice) == 4 + assert plg.cube_slice == "4.894e+00 um" plg.dataset_selected = "test[FLUX]" plg.aperture_selected = "Subset 1" @@ -35,7 +35,7 @@ def test_cubeviz_aperphot_cube_orig_flux(cubeviz_helper, image_cube_hdu_obj_micr assert_allclose(row["sum"], 75 * flux_unit) # 3 (w) x 5 (h) x 5 (v) assert_allclose(row["sum_aper_area"], 15 * (u.pix * u.pix)) # 3 (w) x 5 (h) assert_allclose(row["mean"], 5 * flux_unit) - assert_quantity_allclose(row["slice"], 4.894499866699333 * u.um) + assert_quantity_allclose(row["slice_wave"], 4.894499866699333 * u.um) # Move slider and make sure it recomputes for a new slice automatically. cube_slice_plg = cubeviz_helper.plugins["Slice"]._obj @@ -52,7 +52,7 @@ def test_cubeviz_aperphot_cube_orig_flux(cubeviz_helper, image_cube_hdu_obj_micr assert_allclose(row["sum"], 15 * flux_unit) # 3 (w) x 5 (h) x 1 (v) assert_allclose(row["sum_aper_area"], 15 * (u.pix * u.pix)) # 3 (w) x 5 (h) assert_allclose(row["mean"], 1 * flux_unit) - assert_quantity_allclose(row["slice"], 4.8904998665093435 * u.um) + assert_quantity_allclose(row["slice_wave"], 4.8904998665093435 * u.um) # We continue on with test_cubeviz_aperphot_generated_2d_collapse here # because we want to make sure the result would append properly between 3D and 2D. @@ -77,7 +77,7 @@ def test_cubeviz_aperphot_cube_orig_flux(cubeviz_helper, image_cube_hdu_obj_micr assert_allclose(row["sum"], 540 * flux_unit) # 3 (w) x 5 (h) x 36 (v) assert_allclose(row["sum_aper_area"], 15 * (u.pix * u.pix)) # 3 (w) x 5 (h) assert_allclose(row["mean"], 36 * flux_unit) - assert np.isnan(row["slice"]) + assert np.isnan(row["slice_wave"]) def test_cubeviz_aperphot_generated_2d_moment(cubeviz_helper, image_cube_hdu_obj_microns): @@ -108,7 +108,7 @@ def test_cubeviz_aperphot_generated_2d_moment(cubeviz_helper, image_cube_hdu_obj assert_allclose(row["sum"], 540 * flux_unit) # 3 (w) x 5 (h) x 36 (v) assert_allclose(row["sum_aper_area"], 15 * (u.pix * u.pix)) # 3 (w) x 5 (h) assert_allclose(row["mean"], 36 * flux_unit) - assert np.isnan(row["slice"]) + assert np.isnan(row["slice_wave"]) # Moment 1 has no compatible unit, so should not be available for photometry. moment_plg.n_moment = 1 @@ -150,7 +150,7 @@ def test_cubeviz_aperphot_generated_3d_gaussian_smooth(cubeviz_helper, image_cub assert_allclose(row["sum"], 48.54973 * flux_unit) # 3 (w) x 5 (h) x <5 (v) assert_allclose(row["sum_aper_area"], 15 * (u.pix * u.pix)) # 3 (w) x 5 (h) assert_allclose(row["mean"], 3.236648941040039 * flux_unit) - assert_quantity_allclose(row["slice"], 4.894499866699333 * u.um) + assert_quantity_allclose(row["slice_wave"], 4.894499866699333 * u.um) def test_cubeviz_aperphot_cube_orig_flux_mjysr(cubeviz_helper, spectrum1d_cube_custom_fluxunit): @@ -181,4 +181,4 @@ def test_cubeviz_aperphot_cube_orig_flux_mjysr(cubeviz_helper, spectrum1d_cube_c assert_allclose(row["pixarea_tot"], 2.350443053909789e-13 * u.sr) assert_allclose(row["aperture_sum_mag"], 23.72476627732448 * u.mag) assert_allclose(row["mean"], 5 * (u.MJy / u.sr)) - assert_quantity_allclose(row["slice"], 0.46236 * u.um) + assert_quantity_allclose(row["slice_wave"], 0.46236 * u.um) diff --git a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py index 307b31a8fd..8ccf244f2b 100644 --- a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py +++ b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py @@ -71,7 +71,7 @@ class SimpleAperturePhotometry(PluginTemplateMixin, ApertureSubsetSelectMixin, fit_results = List().tag(sync=True) # Cubeviz only - cube_slice = Any(0).tag(sync=True) + cube_slice = Unicode("").tag(sync=True) is_cube = Bool(False).tag(sync=True) icon_radialtocheck = Unicode(read_icon(os.path.join(ICON_DIR, 'radialtocheck.svg'), 'svg+xml')).tag(sync=True) # noqa @@ -140,8 +140,9 @@ def valid_cubeviz_datasets(data): def _on_slice_changed(self, msg): if self.config != "cubeviz": return - self.cube_slice = msg.slice + self.cube_slice = f"{msg.wavelength:.3e} {msg.wavelength_unit}" self._cube_wave = u.Quantity(msg.wavelength, msg.wavelength_unit) + self._cube_idx = int(msg.slice) @observe("dataset_selected") def _on_dataset_selected_changed(self, event={}): @@ -316,8 +317,7 @@ def _calc_background_median(self, reg, data=None): comp = data.get_component(data.main_components[0]) if self.config == "cubeviz" and data.ndim > 2: - cube_slice = int(self.cube_slice) - comp_data = comp.data[:, :, cube_slice].T # nx, ny --> ny, nx + comp_data = comp.data[:, :, self._cube_idx].T # nx, ny --> ny, nx # Similar to coords_info logic. if '_orig_spec' in getattr(data, 'meta', {}): w = data.meta['_orig_spec'].wcs.celestial @@ -438,8 +438,7 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None, raise ValueError('Missing or invalid background value') if self.config == "cubeviz" and data.ndim > 2: - cube_slice = int(self.cube_slice) - comp_data = comp.data[:, :, cube_slice].T # nx, ny --> ny, nx + comp_data = comp.data[:, :, self._cube_idx].T # nx, ny --> ny, nx # Similar to coords_info logic. if '_orig_spec' in getattr(data, 'meta', {}): w = data.meta['_orig_spec'].wcs @@ -460,7 +459,7 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None, ycenter = reg.center.y if data.coords is not None: if self.config == "cubeviz" and data.ndim > 2: - sky_center = w.pixel_to_world(cube_slice, ycenter, xcenter)[1] + sky_center = w.pixel_to_world(self._cube_idx, ycenter, xcenter)[1] else: # "imviz" sky_center = w.pixel_to_world(xcenter, ycenter) else: @@ -543,7 +542,7 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None, slice_val = self._cube_wave else: slice_val = u.Quantity(np.nan, self._cube_wave.unit) - phot_table.add_column(slice_val, name="slice", index=29) + phot_table.add_column(slice_val, name="slice_wave", index=29) if add_to_table: try: diff --git a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue index bbac067cd9..7d1185a63f 100644 --- a/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue +++ b/jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.vue @@ -36,14 +36,11 @@