Skip to content

Commit

Permalink
Fix cube fit toggle with spectral subset selected (spacetelescope#3123)
Browse files Browse the repository at this point in the history
* Avoid checking selected_obj before it's available

* Changelog

* Added a test that fails on main
  • Loading branch information
rosteen authored Jul 31, 2024
1 parent 5a74cd6 commit 09c3cc6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ Other Changes and Additions
Bug Fixes
---------

- Fixed the data menu in Model Fitting not being populated if Cube Fit was toggled
while a spectral subset was selected. [#3123]

Cubeviz
^^^^^^^

Expand Down
13 changes: 13 additions & 0 deletions jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ def test_fit_cube_no_wcs(cubeviz_helper):
assert fitted_data.shape == output_cube.shape


def test_toggle_cube_fit_subset(cubeviz_helper):
sp = Spectrum1D(flux=np.ones((7, 8, 9)) * u.nJy) # ny, nx, nz
cubeviz_helper.load_data(sp, data_label="test_cube")
mf = cubeviz_helper.plugins['Model Fitting']

sv = cubeviz_helper.app.get_viewer('spectrum-viewer')
sv.apply_roi(XRangeROI(7.5, 8))

mf.spectral_subset = 'Subset 1'
mf.cube_fit = True


def test_refit_plot_options(specviz_helper, spectrum1d):
specviz_helper.load_data(spectrum1d)
modelfit_plugin = specviz_helper.plugins['Model Fitting']
Expand Down Expand Up @@ -284,6 +296,7 @@ def test_reestimate_parameters(specviz_helper, spectrum1d):
sv.apply_roi(XRangeROI(7500, 8000))

mf.spectral_subset = 'Subset 1'

mf.reestimate_model_parameters()
mc = mf.get_model_component('G')

Expand Down
2 changes: 1 addition & 1 deletion jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,7 @@ class DatasetSpectralSubsetValidMixin(VuetifyTemplate, HubListener):

@observe("dataset_selected", "spectral_subset_selected")
def _check_dataset_spectral_subset_valid(self, event={}, return_ranges=False):
if not hasattr(self, 'dataset'):
if not hasattr(self, 'dataset') or self.dataset.selected_obj is None:
# plugin not fully initialized
return
if self.spectral_subset_selected == "Entire Spectrum":
Expand Down

0 comments on commit 09c3cc6

Please sign in to comment.