Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Sep 6, 2024
1 parent 09b684f commit 2ec83b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion jdaviz/core/validunits.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from astropy import units as u
import itertools

__all__ = ['units_to_strings', 'create_spectral_equivalencies_list',
__all__ = ['supported_sq_angle_units', 'units_to_strings', 'create_spectral_equivalencies_list',
'create_flux_equivalencies_list', 'check_if_unit_is_per_solid_angle']

def supported_sq_angle_units():
return [u.pix*u.pix, u.sr]

def units_to_strings(unit_list):
"""Convert equivalencies into readable versions of the units.
Expand Down
12 changes: 8 additions & 4 deletions jdaviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,19 @@ def _indirect_conversion(values, orig_units, targ_units, eqv,

# make these an input parameter since they're already determined
# here for now until i make sure this function isn't called elsewhere
solid_angle_in_orig = check_if_unit_is_per_solid_angle(orig_units)
solid_angle_in_targ = check_if_unit_is_per_solid_angle(targ_units)
solid_angle_in_orig = check_if_unit_is_per_solid_angle(orig_units, return_unit=True)
solid_angle_in_targ = check_if_unit_is_per_solid_angle(targ_units, return_unit=True)
solid_angle_in_spec = check_if_unit_is_per_solid_angle(spec_unit, return_unit=True)

# indirect units cannot be directly converted, and require
# additional conversions to reach the desired end unit.
if (spec_unit and spec_unit in [orig_units, targ_units]
and not check_if_unit_is_per_solid_angle(spec_unit)):
if u.Unit(targ_units) in indirect_units():
temp_targ = targ_units * solid_angle_in_targ
print('temp_targ', temp_targ)
print('solid angle in targ', solid_angle_in_targ)
print('orig_units', orig_units)
values = (values * orig_units).to_value(temp_targ, equivalencies=eqv)
orig_units = u.Unit(temp_targ)
return values, orig_units, 'orig'
Expand All @@ -491,9 +495,9 @@ def _indirect_conversion(values, orig_units, targ_units, eqv,

return values, targ_units, 'targ'

elif image_data or (spec_unit and check_if_unit_is_per_solid_angle(spec_unit)):
elif image_data or (spec_unit and solid_angle_in_spec):
if not solid_angle_in_targ:
targ_units /= solid_angle_in_targ
targ_units /= solid_angle_in_spec
if ((u.Unit(targ_units) in indirect_units()) or
(u.Unit(orig_units) in indirect_units())):
# SB -> Flux -> Flux -> SB
Expand Down

0 comments on commit 2ec83b1

Please sign in to comment.