ComponentLink¶
-
class
glue.core.component_link.
ComponentLink
(comp_from, comp_to, using=None, inverse=None)[source]¶ Bases:
object
ComponentLinks represent transformation logic between ComponentIDs
ComponentLinks are be used to derive one
ComponentID
from another:Example:
def hours_to_minutes(hours): return hours * 60 d = Data(hour=[1, 2, 3]) hour = d.id['hour'] minute = ComponentID('minute') link = ComponentLink( [hour], minute, using=hours_to_minutes) link.compute(d) # array([ 60, 120, 180]) d.add_component_link(link) d['minute'] # array([ 60, 120, 180])
Parameters: - comp_from (
ComponentID
) – The input ComponentIDs - comp_to – The target component ID
Pram using: The translation function which maps data from comp_from to comp_to (optional)
The using function should satisfy:
using(data[comp_from[0]],...,data[comp_from[-1]]) = desired data
Parameters: inverse – The inverse translation function, if exists (optional) Raises: TypeError if input is invalid Note
Both
inverse
andusing
should accept and return numpy arraysMethods Summary
compute
(data[, view])For a given data set, compute the component comp_to given get_from_ids
()The list of input ComponentIDs get_inverse
()The inverse transformation, or None get_to_id
()The target ComponentID get_using
()The transformation function replace_ids
(old, new)Replace all references to an old ComponentID with references set_from_ids
(_from)set_to_id
(to)Methods Documentation
-
compute
(data, view=None)[source]¶ For a given data set, compute the component comp_to given the data associated with each comp_from and the
using
functionParameters: - data – The data set to use
- view – Optional view (e.g. slice) through the data to use
Returns:
The data associated with comp_to componentRaises:
InvalidAttribute, if the data set doesn’t have all the ComponentIDs needed for the transformation
- comp_from (