Skip to content

Commit

Permalink
Fix moment map when spectral units are in frequency (#2803)
Browse files Browse the repository at this point in the history
* Fix moment map when spectral units are in frequency

* Update changelog
  • Loading branch information
javerbukh authored Apr 17, 2024
1 parent a9c475c commit b0ec4c1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ New Features
Cubeviz
^^^^^^^

- Enable spectral unit conversion in cubeviz. [#2758]
- Enable spectral unit conversion in cubeviz. [#2758, #2803]

Imviz
^^^^^
Expand Down
10 changes: 10 additions & 0 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def user_api(self):
'output_unit', 'reference_wavelength',
'add_results', 'calculate_moment'))

@property
def slice_display_unit_name(self):
return 'spectral'

@observe('is_active')
def _is_active_changed(self, msg):
for pos, mark in self.continuum_marks.items():
Expand Down Expand Up @@ -239,6 +243,12 @@ def calculate_moment(self, add_data=True):
# slice out desired region
# TODO: should we add a warning for a composite spectral subset?
spec_min, spec_max = self.spectral_subset.selected_min_max(cube)
display_spectral_axis_unit = self.app._get_display_unit(self.slice_display_unit_name)

# Convert units of min and max if necessary
if display_spectral_axis_unit and display_spectral_axis_unit != str(spec_min.unit):
spec_min = spec_min.to(display_spectral_axis_unit, equivalencies=u.spectral())
spec_max = spec_max.to(display_spectral_axis_unit, equivalencies=u.spectral())
slab = manipulation.spectral_slab(cube, spec_min, spec_max)

# Calculate the moment and convert to CCDData to add to the viewers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from astropy.nddata import CCDData
from astropy.wcs import WCS
from astroquery.mast import Observations
import numpy as np
from numpy.testing import assert_allclose
from glue.core.roi import XRangeROI


def test_user_api(cubeviz_helper, spectrum1d_cube):
Expand Down Expand Up @@ -188,6 +190,27 @@ def test_moment_velocity_calculation(cubeviz_helper, spectrum1d_cube):
"204.9997755344 27.0001999998 (deg)")


def test_moment_frequency_unit_conversion(cubeviz_helper, spectrum1d_cube_larger):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="No observer defined on WCS.*")
cubeviz_helper.load_data(spectrum1d_cube_larger, data_label='test')

uc = cubeviz_helper.plugins['Unit Conversion']
mm = cubeviz_helper.plugins['Moment Maps']
viewer = cubeviz_helper.app.get_viewer('spectrum-viewer')
viewer.apply_roi(XRangeROI(4.624e-07, 4.627e-07))

uc.spectral_unit = 'Hz'
mm.spectral_subset = 'Subset 1'
mm.continuum = 'Surrounding'
mm.n_moment = 1
mm.output_unit = 'Spectral Unit'
moment_1_data = mm.calculate_moment()

# Check to make sure there are no nans
assert len(np.where(moment_1_data.data > 0)[0]) == 8


def test_write_momentmap(cubeviz_helper, spectrum1d_cube, tmp_path):
''' Test writing a moment map out to a FITS file on disk '''

Expand Down

0 comments on commit b0ec4c1

Please sign in to comment.