Skip to content

Commit

Permalink
Fix table GUI for slice wavelength
Browse files Browse the repository at this point in the history
and display slice wavelength instead of index in read-only text field.
  • Loading branch information
pllim committed Jan 30, 2024
1 parent 1f84b21 commit c7d10df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/cubeviz/export_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ Cubeviz can export photometry output table like Imviz:
In addition to the columns that :ref:`Imviz Aperture Photometry <imviz_export_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.
14 changes: 7 additions & 7 deletions jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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={}):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@
<v-row class="row-no-outside-padding row-min-bottom-padding">
<v-col>
<v-text-field
v-model.number="cube_slice"
:readonly="true"
:value="cube_slice"
class="mt-0 pt-0"
type="number"
label="Slice (for cube)"
label="Slice wavelength"
hint="Extracts photometry from currently selected cube slice"
disabled

></v-text-field>
</v-col>
</v-row>
Expand Down

0 comments on commit c7d10df

Please sign in to comment.