Skip to content

Commit

Permalink
Add new options to public API
Browse files Browse the repository at this point in the history
Don't need self here
  • Loading branch information
rosteen committed Dec 1, 2023
1 parent b3486dd commit ebc7a2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class MomentMap(PluginTemplateMixin, DatasetSelectMixin, SpectralSubsetSelectMix
* ``spectral_subset`` (:class:`~jdaviz.core.template_mixin.SubsetSelect`):
Subset to use for the line, or ``Entire Spectrum``.
* ``n_moment``
* ``output_unit``
Choice of "Wavelength" or "Velocity", applicable for n_moment >= 1.
* ``reference_wavelength``
Reference wavelength for conversion of output to velocity units.
* ``add_results`` (:class:`~jdaviz.core.template_mixin.AddResults`)
* :meth:`calculate_moment`
"""
Expand Down Expand Up @@ -95,6 +99,7 @@ def user_api(self):
# NOTE: leaving save_as_fits out for now - we may want a more general API to do that
# accross all plugins at some point
return PluginUserApi(self, expose=('dataset', 'spectral_subset', 'n_moment',
'output_unit', 'reference_wavelength',
'add_results', 'calculate_moment'))

@observe("dataset_selected", "dataset_items", "n_moment")
Expand Down Expand Up @@ -148,7 +153,10 @@ def calculate_moment(self, add_data=True):
if data_wcs:
data_wcs = data_wcs.swapaxes(0, 1) # We also transpose WCS to match.
self.moment = CCDData(analysis.moment(slab, order=n_moment).T, wcs=data_wcs)
if n_moment > 0 and self.output_unit == "Velocity":
if n_moment > 0 and self.output_unit_selected.lower() == "velocity":
# Catch this if called from API
if not self.reference_wavelength > 0.0:
raise ValueError("reference_wavelength must be set for output in velocity units.")
power_unit = f"{self.dataset_spectral_unit}{self.n_moment}"
self.moment = np.power(self.moment.convert_unit_to(power_unit), 1/self.n_moment)
self.moment = self.moment << u.Unit(self.dataset_spectral_unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ def test_moment_velocity_calculation(cubeviz_helper, spectrum1d_cube, tmpdir):
# Test moment 1 in velocity
mm.n_moment = 1
mm.add_results.viewer = "uncert-viewer"
mm._obj.reference_wavelength = 4.63e-7
assert mm._obj.results_label == 'moment 1'
mm._obj.output_unit = "Velocity"
mm.output_unit = "Velocity"

with pytest.raises(ValueError, match="reference_wavelength must be set"):
mm.calculate_moment()

mm.reference_wavelength = 4.63e-7
mm.calculate_moment()

# Make sure coordinate display works
Expand Down

0 comments on commit ebc7a2f

Please sign in to comment.