From fcede25c3235f769f9875f516339f95f39fda9a9 Mon Sep 17 00:00:00 2001 From: Hatice Karatay Date: Mon, 22 Jul 2024 12:57:38 -0400 Subject: [PATCH] Reflect whenunit change in the conversion plugin --- .../plugins/line_analysis/line_analysis.py | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/jdaviz/configs/specviz/plugins/line_analysis/line_analysis.py b/jdaviz/configs/specviz/plugins/line_analysis/line_analysis.py index 6704a388a1..a5dbd0c049 100644 --- a/jdaviz/configs/specviz/plugins/line_analysis/line_analysis.py +++ b/jdaviz/configs/specviz/plugins/line_analysis/line_analysis.py @@ -271,7 +271,7 @@ def _uncertainty(result): if getattr(result, 'uncertainty', None) is not None: # we'll keep the uncertainty and result in the same unit (so # we only have to show the unit at the end) - if np.isnan(result.uncertainty.value) or np.isinf(result.uncertainty.value): + if np.any(np.isnan(result.uncertainty.value)) or np.any(np.isinf(result.uncertainty.value)): return '' return str(result.uncertainty.to_value(result.unit)) else: @@ -287,7 +287,7 @@ def _uncertainty(result): # TODO: update specutils to allow ALL analysis to take regions and continuum so we # don't need these if statements if function == "Line Flux": - flux_unit = spec_subtracted.flux.unit + flux_unit = self.app._get_display_unit('flux') if flux_unit == u.dimensionless_unscaled: add_flux = True flux_unit = u.Unit(self.spectrum_viewer.state.y_display_unit) @@ -295,6 +295,7 @@ def _uncertainty(result): add_flux = False # If the flux unit is equivalent to Jy, or Jy per spaxel for Cubeviz, # enforce integration in frequency space + flux_unit = u.Unit(flux_unit) if (flux_unit.is_equivalent(u.Jy) or flux_unit.is_equivalent(u.Jy/u.sr)): # Perform integration in frequency space @@ -319,16 +320,10 @@ def _uncertainty(result): self.update_results(None) return - # When flux is equivalent to Jy, lineflux result should be shown in W/m2 - if flux_unit.is_equivalent(u.Jy/u.sr): - final_unit = u.Unit('W/(m2 sr)') - else: - final_unit = u.Unit('W/m2') - - temp_result = raw_result.to(final_unit) + final_unit = flux_unit + temp_result = raw_result.to(final_unit, equivalencies= u.spectral_density(freq_spec.spectral_axis)) if getattr(raw_result, 'uncertainty', None) is not None: - temp_result.uncertainty = raw_result.uncertainty.to(final_unit) - + temp_result.uncertainty = raw_result.uncertainty.to(final_unit, equivalencies= u.spectral_density(freq_spec.spectral_axis)) # If the flux unit is instead equivalent to power density # (Jy, but defined in wavelength), enforce integration in wavelength space elif (flux_unit.is_equivalent(u.Unit('W/(m2 m)')) or @@ -353,15 +348,11 @@ def _uncertainty(result): color="warning")) self.update_results(None) return - # When flux is equivalent to Jy, lineflux result should be shown in W/m2 - if flux_unit.is_equivalent(u.Unit('W/(m2 m)'/u.sr)): - final_unit = u.Unit('W/(m2 sr)') - else: - final_unit = u.Unit('W/m2') - temp_result = raw_result.to(final_unit) + final_unit = flux_unit + temp_result = raw_result.to(final_unit, equivalencies= u.spectral_density(wave_spec.spectral_axis)) if getattr(raw_result, 'uncertainty', None) is not None: - temp_result.uncertainty = raw_result.uncertainty.to(final_unit) + temp_result.uncertainty = raw_result.uncertainty.to(final_unit, equivalencies= u.spectral_density(wave_spec.spectral_axis)) # Otherwise, just rely on the default specutils line_flux result else: