Skip to content

Commit

Permalink
change slice -> spectral_axis, checks for len and type
Browse files Browse the repository at this point in the history
  • Loading branch information
gibsongreen committed Dec 5, 2024
1 parent 1b80ede commit fa62ec7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions jdaviz/core/freezable_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def _convert_units_y_limits(self, old_unit, new_unit):

x_corners = np.array([self.x_min, self.x_min, self.x_max, self.x_max])
y_corners = np.array([self.y_min, self.y_max, self.y_min, self.y_max])
y_corners_new = flux_conversion(y_corners, old_unit, new_unit, slice=x_corners*u.Unit(self.x_display_unit)) # noqa
y_corners_new = flux_conversion(y_corners, old_unit, new_unit, spectral_axis=x_corners*u.Unit(self.x_display_unit)) # noqa

#with delay_callback(self, 'y_min', 'y_max'):
# with delay_callback(self, 'y_min', 'y_max'):
self.y_min = np.nanmin(y_corners_new)
self.y_max = np.nanmax(y_corners_new)

Expand Down
19 changes: 10 additions & 9 deletions jdaviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def indirect_units():
return units


def flux_conversion(values, original_units, target_units, spec=None, eqv=None, slice=None):
def flux_conversion(values, original_units, target_units, spec=None, eqv=None, spectral_axis=None):
"""
Convert flux or surface brightness values from original units to target units.
Expand All @@ -367,8 +367,8 @@ def flux_conversion(values, original_units, target_units, spec=None, eqv=None, s
eqv : list of :ref:`astropy:unit_equivalencies`, optional
A list of Astropy equivalencies necessary for complex unit conversions/translations.
slice : `astropy.units.Quantity`, optional
The current slice of a data cube, with units. Necessary for complex unit
spectral_axis : `astropy.units.Quantity`, optional
Provide spectral axis associated with values array. Necessary for simple and complex unit
conversions/translations that require spectral density equivalencies.
Returns
Expand Down Expand Up @@ -398,12 +398,13 @@ def flux_conversion(values, original_units, target_units, spec=None, eqv=None, s
eqv = u.spectral_density(spectral_values)
else:
eqv = u.spectral_density(spec.spectral_axis[0])
elif slice is not None and eqv:
image_data = True
# Need this to convert Flux to Flux for complex conversions/translations of cube image data
eqv += u.spectral_density(slice)
elif slice is not None:
eqv = u.spectral_density(slice)
elif spectral_axis and isinstance(spectral_axis, u.Quantity):
if eqv:
image_data = True
# Needed to convert Flux to Flux for complex conversion/translation of cube image data
eqv += u.spectral_density(spectral_axis)
elif len(values) == len(spectral_axis):
eqv = u.spectral_density(spectral_axis)

orig_units = u.Unit(original_units)
targ_units = u.Unit(target_units)
Expand Down

0 comments on commit fa62ec7

Please sign in to comment.