From 9ac060aeb01cbc759e6727b9d7dd7e314e81990b Mon Sep 17 00:00:00 2001 From: Ricky O'Steen Date: Tue, 20 Aug 2024 15:33:10 -0400 Subject: [PATCH] Debug moment 0 in flux when cube is in surface brightness --- .../plugins/moment_maps/moment_maps.py | 26 ++++++++++++------- .../imviz/plugins/coords_info/coords_info.py | 3 ++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py b/jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py index 56f0ec128f..b9ce1c35e3 100644 --- a/jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py +++ b/jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py @@ -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 @@ -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'] @@ -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: @@ -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) diff --git a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py index f5e87015c1..49bb902b29 100644 --- a/jdaviz/configs/imviz/plugins/coords_info/coords_info.py +++ b/jdaviz/configs/imviz/plugins/coords_info/coords_info.py @@ -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: