diff --git a/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py b/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py index c9ac3599af..62a7229f14 100644 --- a/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py +++ b/jdaviz/configs/cubeviz/plugins/moment_maps/tests/test_moment_maps.py @@ -147,7 +147,6 @@ def test_moment_velocity_calculation(cubeviz_helper, spectrum1d_cube): uncert_viewer.state._set_axes_aspect_ratio(1) mm = cubeviz_helper.plugins["Moment Maps"] - print(mm._obj.dataset_selected) mm._obj.dataset_selected = 'test[FLUX]' # Test moment 1 in velocity @@ -170,6 +169,13 @@ def test_moment_velocity_calculation(cubeviz_helper, spectrum1d_cube): "World 13h39m59.9731s +27d00m00.3600s (ICRS)", "204.9998877673 27.0001000000 (deg)") + # Add test for unit conversion + assert mm._obj.output_radio_items[0]['unit_str'] == 'm' + uc_plugin = cubeviz_helper.plugins['Unit Conversion']._obj + uc_plugin.spectral_unit.selected = 'Angstrom' + assert mm._obj.output_radio_items[0]['unit_str'] == 'Angstrom' + uc_plugin.spectral_unit.selected = 'm' + # Test moment 2 in velocity mm.n_moment = 2 mm.calculate_moment() diff --git a/jdaviz/configs/cubeviz/plugins/slice/slice.py b/jdaviz/configs/cubeviz/plugins/slice/slice.py index 6e67584ac8..fdc254d46c 100644 --- a/jdaviz/configs/cubeviz/plugins/slice/slice.py +++ b/jdaviz/configs/cubeviz/plugins/slice/slice.py @@ -160,6 +160,10 @@ def _update_data(self, x_all): # leave in the pre-init state and don't update the value/slice return + if self._app._get_display_unit('spectral') == '': + self._update_slice(x_all) + + def _update_slice(self, x_all): # Also update unit when data is updated self.value_unit = x_all.unit.to_string() @@ -199,6 +203,7 @@ def _on_global_display_unit_changed(self, msg): if self._x_all is None or prev_unit in ('deg', ''): return self._update_data((self._x_all * u.Unit(prev_unit)).to(msg.unit, u.spectral())) + self._update_slice((self._x_all * u.Unit(prev_unit)).to(msg.unit, u.spectral())) @observe('value') def _on_value_updated(self, event): diff --git a/jdaviz/configs/cubeviz/plugins/slice/tests/test_slice.py b/jdaviz/configs/cubeviz/plugins/slice/tests/test_slice.py index 8f133ac7e9..dc8d811c9b 100644 --- a/jdaviz/configs/cubeviz/plugins/slice/tests/test_slice.py +++ b/jdaviz/configs/cubeviz/plugins/slice/tests/test_slice.py @@ -75,6 +75,13 @@ def test_slice(cubeviz_helper, spectrum1d_cube): cubeviz_helper.select_wavelength(4.62360028e-07) assert sl.slice == 1 + # Add test for unit conversion + uc_plugin = cubeviz_helper.plugins['Unit Conversion']._obj + uc_plugin.spectral_unit.selected = 'Angstrom' + assert sl.value_unit == 'Angstrom' + cubeviz_helper.select_wavelength(4623.60028) + assert sl.slice == 1 + # Test player buttons API sl.vue_goto_first() diff --git a/jdaviz/configs/default/plugins/model_fitting/model_fitting.py b/jdaviz/configs/default/plugins/model_fitting/model_fitting.py index bdce1639db..bc6ca1ec77 100644 --- a/jdaviz/configs/default/plugins/model_fitting/model_fitting.py +++ b/jdaviz/configs/default/plugins/model_fitting/model_fitting.py @@ -315,7 +315,8 @@ def _warn_if_no_equation(self): def _get_1d_spectrum(self): # retrieves the 1d spectrum (accounting for spatial subset for cubeviz, if necessary) - return self.dataset.selected_spectrum_for_spatial_subset(self.spatial_subset_selected) # noqa + return self.dataset.selected_spectrum_for_spatial_subset(self.spatial_subset_selected, + use_display_units=True) # noqa @observe("dataset_selected", "spatial_subset_selected") def _dataset_selected_changed(self, event=None): @@ -343,7 +344,6 @@ def _dataset_selected_changed(self, event=None): # Replace NaNs from collapsed Spectrum1D in Cubeviz # (won't affect calculations because these locations are masked) selected_spec.flux[np.isnan(selected_spec.flux)] = 0.0 - # TODO: can we simplify this logic? self._units["x"] = str( selected_spec.spectral_axis.unit) @@ -518,6 +518,7 @@ def _initialize_model_component(self, model_comp, comp_label, poly_order=None): return new_model def _check_model_component_compat(self, axes=['x', 'y'], display_units=None): + print(display_units, self._units) if display_units is None: display_units = [u.Unit(self._units[ax]) for ax in axes]