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

Fix unit conversion with spectral density and surface brightness equivalency at the same time #2890

Closed
Closed
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
3 changes: 3 additions & 0 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ def to_unit(self, data, cid, values, original_units, target_units):
else:
spectral_values = spec.spectral_axis

# By default include spectral density equivalency
eqv = u.spectral_density(spectral_values)

# Ensure a spectrum passed through Spectral Extraction plugin
if '_pixel_scale_factor' in spec.meta and len(values) != 2:

Expand Down
22 changes: 22 additions & 0 deletions jdaviz/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ def test_to_unit(cubeviz_helper):
# so test first value in array
assert np.allclose(value[0], 4.800000041882413e-08)

# Flux to surface brightness

original_units = u.MJy
target_units = u.MJy / u.sr

value = uc.to_unit(cubeviz_helper, data, cid, value, original_units, target_units)

assert np.allclose(value, 1)

# Change from Fnu to Flam (with values shape matching spectral axis)

values = np.ones(3001)
Expand Down Expand Up @@ -262,3 +271,16 @@ def test_to_unit(cubeviz_helper):
([1, 2] * original_units)
.to_value(target_units,
equivalencies=u.spectral_density(cube.spectral_axis[0])))

# Change from Fnu to Flam/sr (with values shape matching spectral axis)

values = np.ones(3001)
original_units = u.MJy
target_units = u.erg / u.cm**2 / u.s / u.AA / u.sr

new_values = uc.to_unit(cubeviz_helper, data, cid, values, original_units, target_units)

assert np.allclose(new_values,
(values * original_units)
.to_value(target_units,
equivalencies=u.spectral_density(cube.spectral_axis)))
Loading