neuron_morphology.feature_extractor.marked_feature module

class neuron_morphology.feature_extractor.marked_feature.MarkedFeature(marks: Set[Type[neuron_morphology.feature_extractor.mark.Mark]], feature: Union[Callable[[neuron_morphology.feature_extractor.data.Data], Any], neuron_morphology.feature_extractor.marked_feature.MarkedFeature], name: Optional[str] = None, preserve_marks: bool = True)[source]

Bases: object

Attributes:
feature
marks
name

Methods

__call__(self, \*args, \*\*kwargs) Execute the underlying feature, passing along all arguments
add_mark(self, mark) Assign an additional mark to this feature
deepcopy(self, \*\*kwargs) Make a deep copy of this marked feature
ensure(feature) If a function is not a MarkedFeature, convert it.
partial(self, \*args, \*\*kwargs) Fix one or more parameters on this feature’s callable
specialize(self, option) Apply a specialization option to this feature.
add_mark(self, mark: Type[neuron_morphology.feature_extractor.mark.Mark])[source]

Assign an additional mark to this feature

deepcopy(self, **kwargs)[source]

Make a deep copy of this marked feature

classmethod ensure(feature: 'Feature') → ~M[source]

If a function is not a MarkedFeature, convert it.

Parameters:
feature : the feature to be converted
Returns:
Either a marked feature generated from the input, or the input

marked feature.

feature
marks
name
partial(self, *args, **kwargs)[source]

Fix one or more parameters on this feature’s callable

specialize(self, option: Type[neuron_morphology.feature_extractor.feature_specialization.FeatureSpecialization])[source]

Apply a specialization option to this feature. This binds parameters on the feature’s __call__ method, sets 0 or more additional marks, and namespaces the feature’s name.

Parameters:
option : The specialization option with which to specialize this

feature.

Returns:
a deep copy of this feature with updated callable, marks and name
neuron_morphology.feature_extractor.marked_feature.marked(mark: Type[neuron_morphology.feature_extractor.mark.Mark])[source]

Decorator for adding a mark to a function.

Parameters:
mark : the mark to be applied

Examples

@marked(RequiresA) @marked(RequiresB) def some_feature_requiring_a_and_b(…):

neuron_morphology.feature_extractor.marked_feature.nested_specialize(feature: Union[Callable[[neuron_morphology.feature_extractor.data.Data], Any], neuron_morphology.feature_extractor.marked_feature.MarkedFeature], specialization_sets: List[Set[Type[neuron_morphology.feature_extractor.feature_specialization.FeatureSpecialization]]]) → Dict[str, neuron_morphology.feature_extractor.marked_feature.MarkedFeature][source]

Apply specializations hierarchically to a base feature. Generating a new collection of specialized features.

Parameters:
feature : will be used as a basis for specialization
specialization_sets : each element describes a set of specialization

options. The output will have one specialization for each element of the cartesian product of these sets.

Returns:
A dictionary mapping namespaced feature names to specialized features.

Notes

Specializations are applied from the start of the specialization_sets to the end. This means that the generated names are structures like:

“last_spec.middle_spec.first_spec.base_feature_name”
neuron_morphology.feature_extractor.marked_feature.specialize(feature: Union[Callable[[neuron_morphology.feature_extractor.data.Data], Any], neuron_morphology.feature_extractor.marked_feature.MarkedFeature], specialization_set: Set[Type[neuron_morphology.feature_extractor.feature_specialization.FeatureSpecialization]]) → Dict[str, neuron_morphology.feature_extractor.marked_feature.MarkedFeature][source]

Bind some of a feature’s keyword arguments, using provided specialization options.

Parameters:
feature : will be used as a basis for specialization
specialization_set : each element defines a particular specialization (i.e

a set of keyword argument values and marks) to be applied to the feature

Returns:
A dictionary mapping (namespaced) feature names to specialized features.
Note that names are formatted as “specialization_name.base_feature_name”