Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix moment map when spectral units are in frequency #2803

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading