Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Surface brightness -> solid angle conversion updates #3111

Merged
merged 12 commits into from
Aug 1, 2024
Merged
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ New Features
------------

- Added flux/surface brightness translation and surface brightness
unit conversion in Cubeviz and Specviz. [#2781, #2940, #3088, #3113]
unit conversion in Cubeviz and Specviz. [#2781, #2940, #3088, #3111, #3113]

- Plugin tray is now open by default. [#2892]

Expand Down
4 changes: 3 additions & 1 deletion jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def _set_data_units(self, event={}):
"Velocity": "km/s",
"Velocity^N": f"km{self.n_moment}/s{self.n_moment}"}

sb_or_flux_label = None

if self.dataset_selected != "":
# Spectral axis is first in this list
data = self.app.data_collection[self.dataset_selected]
Expand Down Expand Up @@ -217,7 +219,7 @@ def _set_data_units(self, event={}):
# Update units in selection item dictionary
for item in self.output_unit_items:
item["unit_str"] = unit_dict[item["label"]]
if item["label"] in ["Flux", "Surface Brightness"]:
if item["label"] in ["Flux", "Surface Brightness"] and sb_or_flux_label:
# change unit label to reflect if unit is flux or SB
item["label"] = sb_or_flux_label

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def test_correct_output_flux_or_sb_units(cubeviz_helper, spectrum1d_cube_custom_

# now change surface brightness units in the unit conversion plugin

uc.sb_unit = 'Jy / sr'
uc.flux_unit = 'Jy'
gibsongreen marked this conversation as resolved.
Show resolved Hide resolved

# and make sure this change is propogated
output_unit_moment_0 = mm.output_unit_items[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ def test_unit_gaussian_mixed_units_per_steradian(specviz_helper):
'''
# unit-flux gaussian in wavelength space, mixed units, per steradian
lam_a = np.arange(1, 2, 0.001)*u.Angstrom
flx_wave = _gauss_with_unity_area(lam_a.value, mn, sig)*1E3*u.erg/u.s/u.cm**2/u.Angstrom/u.sr
# test changed from Surface Brightness to Flux,
# u.erg/u.s/u.cm**2/u.Angstrom/u.sr in untranslatable units (check unit_conversion.py)
flx_wave = _gauss_with_unity_area(lam_a.value, mn, sig)*1E3*u.erg/u.s/u.cm**2/u.Angstrom
fl_wave = Spectrum1D(spectral_axis=lam_a, flux=flx_wave)

specviz_helper.load_data(fl_wave)
lineflux_result = _calculate_line_flux(specviz_helper)
assert_quantity_allclose(float(lineflux_result['result']) * u.Unit(lineflux_result['unit']),
1*u.Unit('W/(m2sr)'))
1*u.Unit('W/(m2)'))
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,18 @@ def test_conv_wave_flux(specviz_helper, spectrum1d, uncert):
def test_conv_no_data(specviz_helper, spectrum1d):
"""plugin unit selections won't have valid choices yet, preventing
attempting to set display units."""
plg = specviz_helper.plugins["Unit Conversion"]
# spectrum not load is in Flux units, sb_unit and flux_unit
# should be enabled, flux_or_sb should not be
assert hasattr(plg, 'sb_unit')
assert hasattr(plg, 'flux_unit')
assert not hasattr(plg, 'flux_or_sb')
plg = specviz_helper.plugins["Unit Conversion"]
with pytest.raises(ValueError, match="no valid unit choices"):
plg.spectral_unit = "micron"
assert len(specviz_helper.app.data_collection) == 0

specviz_helper.load_data(spectrum1d, data_label="Test 1D Spectrum")
plg = specviz_helper.plugins["Unit Conversion"]

# spectrum loaded in Flux units, make sure sb_units don't
# display in the API and exposed translation isn't possible
# make sure we don't expose translations in Specviz
assert hasattr(plg, 'flux_unit')
assert not hasattr(plg, 'sb_unit')
assert hasattr(plg, 'angle_unit')
assert not hasattr(plg, 'flux_or_sb')


Expand Down Expand Up @@ -198,7 +193,7 @@ def test_sb_unit_conversion(cubeviz_helper):
uc_plg.flux_or_sb.selected = 'Surface Brightness'

# Surface Brightness conversion
uc_plg.sb_unit = 'Jy / sr'
uc_plg.flux_unit = 'Jy'
y_display_unit = u.Unit(viewer_1d.state.y_display_unit)
assert y_display_unit == u.Jy / u.sr
label_mouseover = cubeviz_helper.app.session.application._tools["g-coords-info"]
Expand All @@ -214,7 +209,7 @@ def test_sb_unit_conversion(cubeviz_helper):
"204.9987654313 27.0008999946 (deg)")

# Try a second conversion
uc_plg.sb_unit = 'W / Hz sr m2'
uc_plg.flux_unit = 'W / Hz m2'
y_display_unit = u.Unit(viewer_1d.state.y_display_unit)
assert y_display_unit == u.Unit("W / (Hz sr m2)")

Expand All @@ -230,7 +225,7 @@ def test_sb_unit_conversion(cubeviz_helper):
# really a translation test, test_unit_translation loads a Flux
# cube, this test load a Surface Brightness Cube, this ensures
# two-way translation
uc_plg.sb_unit = 'MJy / sr'
uc_plg.flux_unit = 'MJy'
y_display_unit = u.Unit(viewer_1d.state.y_display_unit)
label_mouseover._viewer_mouse_event(
flux_viewer, {"event": "mousemove", "domain": {"x": 10, "y": 8}}
Expand All @@ -241,10 +236,10 @@ def test_sb_unit_conversion(cubeviz_helper):
"204.9987654313 27.0008999946 (deg)")

uc_plg._obj.flux_or_sb_selected = 'Flux'
uc_plg.flux_unit = 'MJy'
uc_plg.flux_unit = 'Jy'
y_display_unit = u.Unit(viewer_1d.state.y_display_unit)

assert y_display_unit == u.MJy
assert y_display_unit == u.Jy

la = cubeviz_helper.plugins['Line Analysis']._obj
assert la.dataset.get_selected_spectrum(use_display_units=True)
Loading