Skip to content

Commit

Permalink
Attempt to fix the conversion between Fnu and Flam while also convert…
Browse files Browse the repository at this point in the history
…ing from surface brightness to flux
  • Loading branch information
astrofrog committed May 22, 2024
1 parent 1f60685 commit 761e956
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
23 changes: 11 additions & 12 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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:

Expand All @@ -128,21 +131,17 @@ def to_unit(self, data, cid, values, original_units, target_units):
if (u.sr in u.Unit(original_units).bases) and \
(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)]
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):
# Flux -> Surface Brightness
eqv = [(u.MJy,
u.MJy / u.sr,
lambda x: (x / spec.meta['_pixel_scale_factor']),
lambda x: x)]
else:
eqv = u.spectral_density(spectral_values)
else:
eqv = u.spectral_density(spectral_values)
eqv += [(u.MJy,
u.MJy / u.sr,
lambda x: (x / spec.meta['_pixel_scale_factor']),
lambda x: x)]

else: # spectral axis
eqv = u.spectral() + u.pixel_scale(1*u.pix)
Expand Down
13 changes: 13 additions & 0 deletions jdaviz/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,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)))

0 comments on commit 761e956

Please sign in to comment.