Skip to content

Commit

Permalink
Debug moment 0 in flux when cube is in surface brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen committed Aug 20, 2024
1 parent 163d657 commit 9ac060a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
26 changes: 16 additions & 10 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from pathlib import Path

import numpy as np
import specutils
from astropy import units as u
from astropy.nddata import CCDData
from astropy.utils import minversion
from traitlets import Bool, List, Unicode, observe
from specutils import manipulation, analysis, Spectrum1D

Expand All @@ -22,6 +20,7 @@
with_spinner)
from jdaviz.core.validunits import check_if_unit_is_per_solid_angle
from jdaviz.core.user_api import PluginUserApi
from jdaviz.utils import flux_conversion, _eqv_pixar_sr

__all__ = ['MomentMap']

Expand Down Expand Up @@ -332,12 +331,6 @@ def calculate_moment(self, add_data=True):
doppler_rest=ref_wavelength)
slab = Spectrum1D(slab.flux, slab_sa)

# Finally actually calculate the moment
self.moment = analysis.moment(slab, order=n_moment).T
# If n>1 and velocity is desired, need to take nth root of result
if n_moment > 0 and self.output_unit_selected.lower() == "velocity":
self.moment = np.power(self.moment, 1/self.n_moment)

# convert units for moment 0, which is the only currently supported
# moment for using converted units.
if n_moment == 0:
Expand All @@ -352,8 +345,21 @@ def calculate_moment(self, add_data=True):

# convert unit string to u.Unit so moment map data can be converted
flux_or_sb_display_unit = u.Unit(flux_sb_unit)
moment_new_unit = flux_or_sb_display_unit * self.spectrum_viewer.state.x_display_unit # noqa: E501
self.moment = self.moment.to(moment_new_unit)
if 'PIXAR_SR' in self.app.data_collection[0].meta:
converted_flux = flux_conversion(slab.flux.value, slab.flux.unit,
flux_or_sb_display_unit,
eqv=_eqv_pixar_sr(self.app.data_collection[0].meta['PIXAR_SR']), # noqa: E501
slice=1*u.um) << u.Unit(flux_or_sb_display_unit)
else:
converted_flux = slab.flux.to(flux_or_sb_display_unit)

slab = Spectrum1D(converted_flux, slab.spectral_axis)

# Finally actually calculate the moment
self.moment = analysis.moment(slab, order=n_moment).T
# If n>1 and velocity is desired, need to take nth root of result
if n_moment > 0 and self.output_unit_selected.lower() == "velocity":
self.moment = np.power(self.moment, 1/self.n_moment)

# Reattach the WCS so we can load the result
self.moment = CCDData(self.moment, wcs=data_wcs)
Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ def _image_viewer_update(self, viewer, x, y):
)

# We don't want to convert for things like moment maps
if str(u.Unit(unit).physical_type) not in ("spectral flux density", "surface brightness"):
if str(u.Unit(unit).physical_type) not in ("spectral flux density",
"surface brightness"):
skip_spectral_density_eqv = True

if self.image_unit is not None and not skip_spectral_density_eqv:
Expand Down

0 comments on commit 9ac060a

Please sign in to comment.