ComponentLink#
- class glue.core.component_link.ComponentLink(comp_from, comp_to, using=None, inverse=None, inverse_component_link=None, description=None, input_names=None, output_name=None)#
Bases:
objectComponentLinks represent transformation logic between ComponentIDs
- Parameters:
- comp_fromlist of
ComponentID The input ComponentIDs
- comp_to
ComponentID The target component ID
- usingfunc, optional
The translation function which maps data from
comp_fromtocomp_to. The using function should satisfyusing(data[comp_from[0]],...,data[comp_from[-1]]) = desired data. If not specifies, this defaults to an identity function.- inversefunc, optional
The inverse translation function, if exists
- descriptionstr
A short description for the link. This is used e.g. in the link editor.
- input_nameslist of str, optional
The names to use for the inputs to the
usingfunction. By default this is determined by inspecting the function signature. This is used e.g. in the link editor.- output_namestr, optional
The name to use for the output of the
usingfunction. This is used e.g. in the link editor.
- comp_fromlist of
Notes
Both
inverseandusingshould accept and return numpy arrays.Examples
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])
Attributes Summary
Methods Summary
compute(data[, view])For a given data set, compute the component comp_to given the data associated with each comp_from and the
usingfunctionThe list of input ComponentIDs
The inverse transformation, or None
The target ComponentID
The transformation function
replace_ids(old, new)Replace all references to an old ComponentID with references to new.
set_from_ids(_from)set_to_id(to)to_html()Attributes Documentation
- inverse#
Methods Documentation
- compute(data, view=None)#
For a given data set, compute the component comp_to given the data associated with each comp_from and the
usingfunctionThis raises an
glue.core.exceptions.IncompatibleAttributeif the data set doesn’t have all the ComponentIDs needed for the transformation- Parameters:
- data~glue.core.data.Data
The data set to use.
- viewslice or tuple, optional
Optional view (e.g. slice) through the data to use.
- Returns:
- result
The data associated with comp_to component
- get_from_ids()#
The list of input ComponentIDs
- get_inverse()#
The inverse transformation, or None
- get_to_id()#
The target ComponentID
- get_to_ids()#
- get_using()#
The transformation function
- replace_ids(old, new)#
Replace all references to an old ComponentID with references to new.
- Parameters:
- old
ComponentID ComponentID to replace.
- new
ComponentID ComponentID to replace with.
- old
- set_from_ids(_from)#
- set_to_id(to)#
- to_html()#