Skip to content

Commit

Permalink
don't crash if line analysis fails in specutils
Browse files Browse the repository at this point in the history
* mosviz.test_parsers was failing with an interpolation error on initial load
  • Loading branch information
kecnry committed Jul 14, 2023
1 parent c8e25e8 commit 4e0bdcd
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions jdaviz/configs/specviz/plugins/line_analysis/line_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
SpectralMarksChangedMessage,
LineIdentifyMessage,
RedshiftMessage,
GlobalDisplayUnitChanged)
GlobalDisplayUnitChanged,
SnackbarMessage)
from jdaviz.core.marks import (LineAnalysisContinuum,
LineAnalysisContinuumCenter,
LineAnalysisContinuumLeft,
Expand Down Expand Up @@ -457,10 +458,20 @@ def _uncertainty(result):
flux=spec_subtracted.flux,
uncertainty=spec_subtracted.uncertainty)

raw_result = analysis.line_flux(freq_spec)
try:
raw_result = analysis.line_flux(freq_spec)
except ValueError as e:
# can happen if interpolation out-of-bounds or any error from specutils
# let's avoid the whole app crashing and instead expose the error to the
# user
self.hub.broadcast(SnackbarMessage(
f"failed to calculate line analysis statistics: {e}", sender=self,
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.Jy/u.sr):

final_unit = u.Unit('W/(m2 sr)')
else:
final_unit = u.Unit('W/m2')
Expand All @@ -479,7 +490,17 @@ def _uncertainty(result):
equivalencies=u.spectral()),
flux=spec_subtracted.flux,
uncertainty=spec_subtracted.uncertainty)
raw_result = analysis.line_flux(wave_spec)
try:
raw_result = analysis.line_flux(wave_spec)
except ValueError as e:
# can happen if interpolation out-of-bounds or any error from specutils
# let's avoid the whole app crashing and instead expose the error to the
# user
self.hub.broadcast(SnackbarMessage(
f"failed to calculate line analysis statistics: {e}", sender=self,
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)')
Expand Down

0 comments on commit 4e0bdcd

Please sign in to comment.