Skip to content

Commit

Permalink
Merge pull request #1533 from astrofrog/refactor-data-links
Browse files Browse the repository at this point in the history
Refactor link handling
  • Loading branch information
astrofrog authored Feb 26, 2018
2 parents dc3d02b + 0e8b582 commit d36c1d9
Show file tree
Hide file tree
Showing 26 changed files with 780 additions and 474 deletions.
9 changes: 0 additions & 9 deletions glue/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ def units(self, value):
else:
self._units = str(value)

@property
def hidden(self):
"""Whether the Component is hidden by default"""
return False

@property
def data(self):
""" The underlying :class:`numpy.ndarray` """
Expand Down Expand Up @@ -250,10 +245,6 @@ def set_parent(self, data):
""" Reassign the Data object that this DerivedComponent operates on """
self._data = data

@property
def hidden(self):
return self._link.hidden

@property
def data(self):
""" Return the numerical data as a numpy array """
Expand Down
23 changes: 8 additions & 15 deletions glue/core/component_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ class ComponentID(object):
component_id = data.id[name]
data[component_id] -> numpy array
Parameters
----------
label : str
Name for the component ID
"""

def __init__(self, label, hidden=False, parent=None):
""":param label: Name for the ID
:type label: str"""
def __init__(self, label, parent=None):
self._label = str(label)
self._hidden = hidden
self.parent = parent
# We assign a UUID which can then be used for example in equations
# for derived components - the idea is that this doesn't change over
Expand Down Expand Up @@ -84,15 +86,6 @@ def label(self, value):
msg = DataRenameComponentMessage(self.parent, self)
self.parent.hub.broadcast(msg)

@property
def hidden(self):
"""Whether to hide the component by default"""
return self._hidden

@hidden.setter
def hidden(self, value):
self._hidden = value

def __str__(self):
return str(self._label)

Expand Down Expand Up @@ -176,6 +169,6 @@ class PixelComponentID(ComponentID):
dimensions.
"""

def __init__(self, axis, label, hidden=False, parent=None):
def __init__(self, axis, label, parent=None):
self.axis = axis
super(PixelComponentID, self).__init__(label, hidden=hidden, parent=parent)
super(PixelComponentID, self).__init__(label, parent=parent)
31 changes: 23 additions & 8 deletions glue/core/component_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
def identity(x):
return x


def null(*args):
return None


OPSYM = {operator.add: '+', operator.sub: '-',
operator.truediv: '/', operator.mul: '*',
operator.pow: '**'}
Expand Down Expand Up @@ -93,7 +98,6 @@ def __init__(self, comp_from, comp_to, using=None, inverse=None, inverse_compone
self._using = using
self._inverse = inverse

self.hidden = False # show in widgets?
self.identity = self._using is identity

if not isinstance(comp_from, list):
Expand Down Expand Up @@ -317,7 +321,6 @@ def __init__(self, comp_from, comp_to, coords, index, pixel2world=True):
comp_from = [comp_from[i] for i in self.from_needed]
super(CoordinateComponentLink, self).__init__(
comp_from, comp_to, self.using)
self.hidden = True

def using(self, *args):

Expand Down Expand Up @@ -382,7 +385,6 @@ def __init__(self, left, right, op):
right)

to = ComponentID("")
null = lambda *args: None
super(BinaryComponentLink, self).__init__(from_, to, null)

def replace_ids(self, old, new):
Expand All @@ -397,13 +399,26 @@ def replace_ids(self, old, new):
self._right.replace_ids(old, new)

def compute(self, data, view=None):
l = self._left
r = self._right
left = self._left
right = self._right
if not isinstance(self._left, numbers.Number):
l = data[self._left, view]
left = data[self._left, view]
if not isinstance(self._right, numbers.Number):
r = data[self._right, view]
return self._op(l, r)
right = data[self._right, view]
return self._op(left, right)

def __gluestate__(self, context):
left = context.id(self._left)
right = context.id(self._right)
operator = context.do(self._op)
return dict(left=left, right=right, operator=operator)

@classmethod
def __setgluestate__(cls, rec, context):
left = context.object(rec['left'])
right = context.object(rec['right'])
operator = context.object(rec['operator'])
return cls(left, right, operator)

def __str__(self):
sym = OPSYM.get(self._op, self._op.__name__)
Expand Down
Loading

0 comments on commit d36c1d9

Please sign in to comment.