Skip to content

Commit

Permalink
custom logic for mapping y-limits on unit change
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Dec 3, 2024
1 parent b10bd58 commit 6411bf2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion jdaviz/core/freezable_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from echo import delay_callback, CallbackProperty
import numpy as np

from astropy import units as u
from glue.viewers.profile.state import ProfileViewerState
from glue_jupyter.bqplot.image.state import BqplotImageViewerState
from glue.viewers.matplotlib.state import DeferredDrawCallbackProperty as DDCProperty
from specutils import Spectrum1D

from jdaviz.utils import get_reference_image_data
from jdaviz.utils import get_reference_image_data, flux_conversion

__all__ = ['FreezableState', 'FreezableProfileViewerState', 'FreezableBqplotImageViewerState']

Expand Down Expand Up @@ -53,6 +55,27 @@ def _reset_x_limits(self, *event):
self.x_min = x_min
self.x_max = x_max

def _convert_units_y_limits(self, old_unit, new_unit):
# override glue's _convert_units_y_limits to account
# for equivalencies. This converts all four corners
# of the limits to set new limits that contain those
# same corners

if old_unit != new_unit:
if old_unit is None or new_unit is None:
self._reset_y_limits()
return

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])
spec = Spectrum1D(spectral_axis=x_corners * u.Unit(self.x_display_unit),
flux=y_corners * u.Unit(old_unit))
y_corners_new = flux_conversion(y_corners, old_unit, new_unit, spec)

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


class FreezableBqplotImageViewerState(BqplotImageViewerState, FreezableState):
linked_by_wcs = False
Expand Down

0 comments on commit 6411bf2

Please sign in to comment.