Skip to content

Commit

Permalink
Fix unit conversion from flux to surface brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog authored and gibsongreen committed May 30, 2024
1 parent e4fdd5b commit 05d2b99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ def to_unit(self, data, cid, values, original_units, target_units):
# target_units dictate the conversion to take place.

if (u.sr in u.Unit(original_units).bases) and \
(u.sr not in u.Unit(target_units).bases):
(u.sr not in u.Unit(target_units).bases):
# Surface Brightness -> Flux
eqv = [(u.MJy / u.sr,
u.MJy,
lambda x: (x * spec.meta['_pixel_scale_factor']),
lambda x: x)]
elif (u.sr not in u.Unit(original_units).bases) and \
(u.sr in u.Unit(target_units).bases):
(u.sr in u.Unit(target_units).bases):
# Flux -> Surface Brightness
eqv = [(u.MJy,
u.MJy / u.sr,
Expand Down
8 changes: 5 additions & 3 deletions jdaviz/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ def test_to_unit(cubeviz_helper):

cid = cubeviz_helper.app.data_collection[0].data.find_component_id('flux')
data = cubeviz_helper.app.data_collection[-1].data
values = 1

# Surface brightness to flux

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

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

assert np.allclose(value, 4.7945742429049767e-11)

Expand All @@ -240,4 +240,6 @@ def test_to_unit(cubeviz_helper):
original_units = u.MJy
target_units = u.MJy / u.sr

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

assert np.allclose(value, 1)

0 comments on commit 05d2b99

Please sign in to comment.