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)[source]¶ Bases:
object
ComponentLinks 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_from
tocomp_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
using
function. 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
using
function. This is used e.g. in the link editor.
- comp_fromlist of
Notes
Both
inverse
andusing
should 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
(self, data[, view])For a given data set, compute the component comp_to given the data associated with each comp_from and the
using
functionget_from_ids
(self)The list of input ComponentIDs
get_inverse
(self)The inverse transformation, or None
get_to_id
(self)The target ComponentID
get_to_ids
(self)get_using
(self)The transformation function
replace_ids
(self, old, new)Replace all references to an old ComponentID with references to new
set_from_ids
(self, _from)set_to_id
(self, to)to_html
(self)Attributes Documentation
Methods Documentation
-
compute
(self, 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
functionThis raises an
glue.core.exceptions.IncompatibleAttribute
if the data set doesn’t have all the ComponentIDs needed for the transformation- Parameters
- data~glue.core.data.Data
The data set to use
- viewNone or slice or tuple
Optional view (e.g. slice) through the data to use
- Returns
- result
The data associated with comp_to component