Skip to content

Commit

Permalink
Fix model fitting and aperture plugins and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javerbukh committed Mar 26, 2024
1 parent 9257b59 commit b94cc85
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions jdaviz/configs/cubeviz/plugins/slice/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions jdaviz/configs/cubeviz/plugins/slice/tests/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions jdaviz/configs/default/plugins/model_fitting/model_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]

Expand Down

0 comments on commit b94cc85

Please sign in to comment.