Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

update y axis label based on unit type #2703

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ Mosviz
Specviz
^^^^^^^

- Check unit type (e.g., flux density, surface brightness, counts, etc) for generating
display label for the y axis in spectral viewer. Previously it was hard coded
to always display ``flux density`` no matter the input unit. [#2703]

Specviz2d
^^^^^^^^^

Expand Down
20 changes: 18 additions & 2 deletions jdaviz/configs/specviz/plugins/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,24 @@ def _plot_uncertainties(self):
self.figure.marks = list(self.figure.marks) + [error_line_mark]

def set_plot_axes(self):
# Set axes labels for the spectrum viewer
flux_unit_type = "Flux density"
# Set y axes labels for the spectrum viewer
y_display_unit = self.state.y_display_unit
y_unit = u.Unit(y_display_unit) if y_display_unit else u.dimensionless_unscaled
cshanahan1 marked this conversation as resolved.
Show resolved Hide resolved

if y_unit.is_equivalent(u.Jy / u.sr):
flux_unit_type = "Surface brightness"
elif y_unit.is_equivalent(u.erg / (u.s * u.cm**2)):
flux_unit_type = 'Flux'
elif y_unit.is_equivalent(u.electron / u.s) or y_unit.physical_type == 'dimensionless':
# electron / s or 'dimensionless_unscaled' should be labeled counts
flux_unit_type = "Counts"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"counts" is very ambiguous by STScI standard. I don't think this is correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that the unit is also in the label, I think this is probably ok?

elif y_unit.is_equivalent(u.W):
flux_unit_type = "Luminosity"
else:
# default to Flux Density for flux density or uncaught types
flux_unit_type = "Flux density"

# Set x axes labels for the spectrum viewer
x_disp_unit = self.state.x_display_unit
x_unit = u.Unit(x_disp_unit) if x_disp_unit else u.dimensionless_unscaled
if x_unit.is_equivalent(u.m):
Expand Down
26 changes: 26 additions & 0 deletions jdaviz/configs/specviz/tests/test_viewers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import astropy.units as u
import numpy as np
import pytest
from specutils import Spectrum1D


@pytest.mark.parametrize(
('input_unit', 'y_axis_label'),
[(u.MJy, 'Flux density'),
(u.MJy / u.sr, 'Surface brightness'),
(u.electron / u.s, 'Counts'),
cshanahan1 marked this conversation as resolved.
Show resolved Hide resolved
(u.dimensionless_unscaled, 'Counts'),
(u.erg / (u.s * u.cm ** 2), 'Flux'),
(u.erg / u.s, 'Luminosity')])
def test_spectrum_viewer_axis_labels(specviz_helper, input_unit, y_axis_label):

flux = np.arange(1, 10) * input_unit
spectral_axis = np.arange(1, 10) * u.um

spec = Spectrum1D(flux, spectral_axis)

specviz_helper.load_data(spec)

label = specviz_helper.app.get_viewer_by_id('specviz-0').figure.axes[1].label

assert (y_axis_label in label)
Loading