Skip to content

Commit

Permalink
Merge pull request #1160 from astrofrog/fix-session-loading
Browse files Browse the repository at this point in the history
Fix various issues with session loading
  • Loading branch information
astrofrog authored Nov 1, 2016
2 parents 6cc0ec4 + e3625db commit 6ef5cce
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ v0.10.0 (unreleased)
v0.9.1 (unreleased)
-------------------

* Fixed loading of session files made with earlier versions of glue that
contained selections made in 3D viewers. [#1160]

* Fixed plotting of fit on spectrum to make sure that the two are properly
aligned. [#1158]

Expand Down
2 changes: 1 addition & 1 deletion glue/core/component_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from glue.core.subset import InequalitySubsetState


__all__ = ['PixelComponentID', 'ComponentID', 'ComponentIDDict']
__all__ = ['PixelComponentID', 'ComponentID', 'PixelComponentID', 'ComponentIDDict']

# access to ComponentIDs via .item[name]

Expand Down
22 changes: 20 additions & 2 deletions glue/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def load(rec, context)

import os
import json
import uuid
import types
import logging
from io import BytesIO
Expand All @@ -70,7 +71,7 @@ def load(rec, context)
from glue.external import six
from glue import core
from glue.core.data import Data
from glue.core.component_id import ComponentID
from glue.core.component_id import ComponentID, PixelComponentID
from glue.core.component import (Component, CategoricalComponent,
DerivedComponent, CoordinateComponent)
from glue.core.subset import (OPSYM, SYMOP, CompositeSubsetState,
Expand Down Expand Up @@ -733,7 +734,10 @@ def load_cid_tuple(cids):
return tuple(context.object(cid) for cid in cids)
result._key_joins = dict((context.object(k), (load_cid_tuple(v0), load_cid_tuple(v1)))
for k, v0, v1 in rec['_key_joins'])
result.uuid = rec['uuid']
if 'uuid' in rec and rec['uuid'] is not None:
result.uuid = rec['uuid']
else:
result.uuid = str(uuid.uuid4())


@saver(ComponentID)
Expand All @@ -746,6 +750,20 @@ def _load_component_id(rec, context):
return ComponentID(rec['label'], rec['hidden'])


@saver(PixelComponentID)
def _save_component_id(cid, context):
return dict(axis=cid.axis, label=cid.label, hidden=cid.hidden)


@loader(PixelComponentID)
def _load_component_id(rec, context):
if 'axis' in rec:
axis = rec['axis']
else: # backward-compatibility
axis = int(rec['label'].split()[2])
return PixelComponentID(axis, rec['label'], rec['hidden'])


@saver(Component)
def _save_component(component, context):

Expand Down
1 change: 1 addition & 0 deletions glue/core/state_path_patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ glue.qt.widgets.scatter_widget.ScatterWidget -> glue.viewers.scatter.qt.ScatterW
glue.qt.widgets.image_widget.ImageWidget -> glue.viewers.image.qt.ImageWidget
glue.qt.widgets.histogram_widget.HistogramWidget -> glue.viewers.histogram.qt.HistogramWidget
glue.qt.glue_application.GlueApplication -> glue.app.qt.application.GlueApplication
glue_vispy_viewers.common.toolbar.PatchedElementSubsetState -> glue.core.subset.ElementSubsetState
16 changes: 11 additions & 5 deletions glue/core/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,6 @@ def to_mask(self, data, view=None):
x = data[self.xatt, view]
y = data[self.yatt, view]

# We do the import here to avoid circular imports
from glue.core.component_id import PixelComponentID

if (x.ndim == data.ndim and
self.xatt in data.pixel_component_ids and
self.yatt in data.pixel_component_ids):
Expand Down Expand Up @@ -893,7 +890,13 @@ def to_mask(self, data, view=None):
# XXX this is inefficient for views
result = np.zeros(data.shape, dtype=bool)
if self._indices is not None:
result.flat[self._indices] = True
try:
result.flat[self._indices] = True
except IndexError:
if self._data_uuid is None:
raise IncompatibleAttribute()
else:
raise
if view is not None:
result = result[view]
return result
Expand All @@ -912,7 +915,10 @@ def __gluestate__(self, context):
@classmethod
def __setgluestate__(cls, rec, context):
state = cls(indices=context.object(rec['indices']))
state._data_uuid = rec['data_uuid']
try:
state._data_uuid = rec['data_uuid']
except KeyError: # BACKCOMPAT
pass
return state


Expand Down

0 comments on commit 6ef5cce

Please sign in to comment.