Skip to content

Commit

Permalink
reintroduce Quantity, add scale factor handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Dec 10, 2024
1 parent b1e3657 commit 81f6b97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions jdaviz/core/freezable_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ 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])
spectral_axis = x_corners * u.Unit(self.x_display_unit)

for layer in self.layers:
if layer.layer.meta.get('_pixel_scale_factor'):
spectral_axis.info.meta = {'_pixel_scale_factor',
layer.layer.meta.get('_pixel_scale_factor')}

y_corners_new = flux_conversion(y_corners, old_unit, new_unit, spectral_axis=spectral_axis) # noqa

self.y_min = np.nanmin(y_corners_new)
Expand Down
12 changes: 10 additions & 2 deletions jdaviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ def flux_conversion(values, original_units, target_units, spec=None, eqv=None, s
solid_angle_in_targ = check_if_unit_is_per_solid_angle(targ_units, return_unit=True)

# Ensure a spectrum passed through Spectral Extraction plugin
if (((spec and ('_pixel_scale_factor' in spec.meta))) and
if ((((spec and ('_pixel_scale_factor' in spec.meta))) or
(spectral_axis is not None and ('_pixel_scale_factor' in spectral_axis.info.meta)))
and
(((solid_angle_in_orig) and (not solid_angle_in_targ)) or
((not solid_angle_in_orig) and (solid_angle_in_targ)))):
# Data item in data collection does not update from conversion/translation.
Expand All @@ -427,7 +429,13 @@ def flux_conversion(values, original_units, target_units, spec=None, eqv=None, s
n_values = len(values)

# Make sure they are float (can be Quantity).
fac = spec.meta['_pixel_scale_factor']
if spec:
fac = spec.meta['_pixel_scale_factor']
elif spectral_axis is not None:
# Quantity.info.meta gets casted to set
fac = next((item for item in spectral_axis.info.meta if isinstance(item, float)), None)
spec_unit = orig_units

if isinstance(fac, Quantity):
fac = fac.value

Expand Down

0 comments on commit 81f6b97

Please sign in to comment.