Skip to content

Commit

Permalink
Merge pull request #2259 from Carifio24/polar-serialization
Browse files Browse the repository at this point in the history
Fix polar scatter serialization issue
  • Loading branch information
astrofrog authored Jan 26, 2022
2 parents b99a746 + 6eba0b5 commit efe0aac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ v1.2.3 (unreleased)
* Remove bottleneck dependency as it is no longer maintained. Certain
array operations may be slower as a result. [#2258]

* Fixed a bug which prevented serialization for polar plots in degree
mode. [#2259]

v1.2.2 (2021-09-16)
-------------------

Expand Down
23 changes: 23 additions & 0 deletions glue/core/roi_pretransforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,26 @@ def __setgluestate__(cls, rec, context):
state = context.object(rec['state'])
return cls(state['projection'], state['x_lim'], state['y_lim'],
state['x_scale'], state['y_scale'])


class RadianTransform(object):
# We define 'next_transform' so that this pre-transform can
# be chained together with another transformation, if desired
def __init__(self, next_transform=None):
self._next_transform = next_transform
self._state = {"next_transform": next_transform}

def __call__(self, x, y):
x = np.deg2rad(x)
if self._next_transform is not None:
return self._next_transform(x, y)
else:
return x, y

def __gluestate__(self, context):
return dict(state=context.do(self._state))

@classmethod
def __setgluestate__(cls, rec, context):
state = context.object(rec['state'])
return cls(state['next_transform'])
11 changes: 2 additions & 9 deletions glue/viewers/scatter/viewer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from glue.core.subset import roi_to_subset_state
from glue.core.util import update_ticks
from glue.core.roi_pretransforms import ProjectionMplTransform
from glue.core.roi_pretransforms import ProjectionMplTransform, RadianTransform

from glue.utils import mpl_to_datetime64
from glue.viewers.scatter.compat import update_scatter_viewer_state
from glue.viewers.matplotlib.mpl_axes import init_mpl

import numpy as np
from functools import partial

__all__ = ['MatplotlibScatterMixin']

Expand Down Expand Up @@ -113,11 +111,6 @@ def update_y_axislabel(self, *event):
labelpad=labelpad)
self.redraw()

@staticmethod
def _radian_pretransform(x, y, transform):
x = np.deg2rad(x)
return transform(x, y)

def apply_roi(self, roi, override_mode=None):

# Force redraw to get rid of ROI. We do this because applying the
Expand Down Expand Up @@ -151,7 +144,7 @@ def apply_roi(self, roi, override_mode=None):

# If we're using degrees, we need to staple on the degrees -> radians conversion beforehand
if self.using_polar() and self.state.angle_unit == 'degrees':
transform = partial(MatplotlibScatterMixin._radian_pretransform, transform=transform)
transform = RadianTransform(next_transform=transform)
subset_state.pretransform = transform

self.apply_subset_state(subset_state, override_mode=override_mode)
Expand Down

0 comments on commit efe0aac

Please sign in to comment.