Skip to content

Commit

Permalink
expose surface brightness units in internal get_display_units method (#…
Browse files Browse the repository at this point in the history
…3112)

* expose surface brightness units in app._get_display_units
  • Loading branch information
kecnry authored Aug 2, 2024
1 parent ac16e60 commit b3bbd9f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from jdaviz.utils import (SnackbarQueue, alpha_index, data_has_valid_wcs, layer_is_table_data,
MultiMaskSubsetState, _wcs_only_label, flux_conversion,
spectral_axis_conversion)
from jdaviz.core.validunits import check_if_unit_is_per_solid_angle

__all__ = ['Application', 'ALL_JDAVIZ_CONFIGS', 'UnitConverterWithSpectral']

Expand Down Expand Up @@ -1249,14 +1250,29 @@ def _get_display_unit(self, axis):
if axis == 'spectral':
sv = self.get_viewer(self._jdaviz_helper._default_spectrum_viewer_reference_name)
return sv.data()[0].spectral_axis.unit
elif axis == 'flux':
elif axis in ('flux', 'sb', 'spectral_y'):
sv = self.get_viewer(self._jdaviz_helper._default_spectrum_viewer_reference_name)
return sv.data()[0].flux.unit
sv_y_unit = sv.data()[0].flux.unit
if axis == 'spectral_y':
return sv_y_unit
elif axis == 'flux':
if check_if_unit_is_per_solid_angle(sv_y_unit):
# TODO: this will need updating once solid-angle unit can be non-steradian
return sv_y_unit * u.sr
return sv_y_unit
else:
# surface_brightness
if check_if_unit_is_per_solid_angle(sv_y_unit):
return sv_y_unit
return sv_y_unit / u.sr
else:
raise ValueError(f"could not find units for axis='{axis}'")
uc = self._jdaviz_helper.plugins.get('Unit Conversion')._obj
if axis == 'spectral_y':
# translate options from uc.flux_or_sb to the prefix used in uc.??_unit_selected
axis = {'Surface Brightness': 'sb', 'Flux': 'flux'}[uc.flux_or_sb_selected]
try:
return getattr(self._jdaviz_helper.plugins.get('Unit Conversion')._obj,
f'{axis}_unit_selected')
return getattr(uc, f'{axis}_unit_selected')
except AttributeError:
raise ValueError(f"could not find display unit for axis='{axis}'")

Expand Down

0 comments on commit b3bbd9f

Please sign in to comment.