Skip to content

Commit

Permalink
Reflect whenunit change in the conversion plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
haticekaratay committed Jul 23, 2024
1 parent 143cd8d commit fcede25
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions jdaviz/configs/specviz/plugins/line_analysis/line_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -287,14 +287,15 @@ 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)
else:
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
Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit fcede25

Please sign in to comment.