Esempio n. 1
0
 def spatialneuron_attribute(neuron, x):
     '''
     Selects a subtree from `SpatialNeuron` neuron and returns a `SpatialSubgroup`.
     If it does not exist, returns the `Group` attribute.
     '''
     if x == 'main':  # Main segment, without the subtrees
         origin = neuron.morphology._origin
         return Subgroup(neuron, origin, origin + len(neuron.morphology.x))
     elif (x != 'morphology') and ((x in neuron.morphology._namedkid) or
                                   all([c in 'LR123456789' for c in x])):  # subtree
         morpho = neuron.morphology[x]
         return SpatialSubgroup(neuron, morpho._origin,
                                morpho._origin + len(morpho),
                                morphology=morpho)
     else:
         return Group.__getattr__(neuron, x)
Esempio n. 2
0
 def spatialneuron_attribute(neuron, x):
     '''
     Selects a subtree from `SpatialNeuron` neuron and returns a `SpatialSubgroup`.
     If it does not exist, returns the `Group` attribute.
     '''
     if x == 'main':  # Main segment, without the subtrees
         origin = neuron.morphology._origin
         return Subgroup(neuron, origin, origin + len(neuron.morphology.x))
     elif (x != 'morphology') and ((x in neuron.morphology._namedkid)
                                   or all([c in 'LR123456789'
                                           for c in x])):  # subtree
         morpho = neuron.morphology[x]
         return SpatialSubgroup(neuron,
                                morpho._origin,
                                morpho._origin + len(morpho),
                                morphology=morpho)
     else:
         return Group.__getattr__(neuron, x)
Esempio n. 3
0
 def spatialneuron_attribute(neuron, name):
     '''
     Selects a subtree from `SpatialNeuron` neuron and returns a `SpatialSubgroup`.
     If it does not exist, returns the `Group` attribute.
     '''
     if name == 'main':  # Main section, without the subtrees
         indices = neuron.morphology.indices[:]
         start, stop = indices[0], indices[-1]
         return SpatialSubgroup(neuron, start, stop + 1,
                                morphology=neuron.morphology)
     elif (name != 'morphology') and ((name in getattr(neuron.morphology, 'children', [])) or
                                   all([c in 'LR123456789' for c in name])):  # subtree
         morpho = neuron.morphology[name]
         start = morpho.indices[0]
         stop = SpatialNeuron._find_subtree_end(morpho)
         return SpatialSubgroup(neuron, start, stop + 1, morphology=morpho)
     else:
         return Group.__getattr__(neuron, name)
Esempio n. 4
0
 def spatialneuron_attribute(neuron, name):
     '''
     Selects a subtree from `SpatialNeuron` neuron and returns a `SpatialSubgroup`.
     If it does not exist, returns the `Group` attribute.
     '''
     if name == 'main':  # Main section, without the subtrees
         indices = neuron.morphology.indices[:]
         start, stop = indices[0], indices[-1]
         return SpatialSubgroup(neuron, start, stop + 1,
                                morphology=neuron.morphology)
     elif (name != 'morphology') and ((name in getattr(neuron.morphology, 'children', [])) or
                                   all([c in 'LR123456789' for c in name])):  # subtree
         morpho = neuron.morphology[name]
         start = morpho.indices[0]
         stop = SpatialNeuron._find_subtree_end(morpho)
         return SpatialSubgroup(neuron, start, stop + 1, morphology=morpho)
     else:
         return Group.__getattr__(neuron, name)
Esempio n. 5
0
 def __getattr__(self, item):
     # We do this because __setattr__ and __getattr__ are not active until
     # _group_attribute_access_active attribute is set, and if it is set,
     # then __getattr__ will not be called. Therefore, if getattr is called
     # with this name, it is because it hasn't been set yet and so this
     # method should raise an AttributeError to agree that it hasn't been
     # called yet.
     if item == '_group_attribute_access_active':
         raise AttributeError
     if not hasattr(self, '_group_attribute_access_active'):
         raise AttributeError
     if item in self.record_variables:
         unit = self.variables[item].unit
         return Quantity(self.variables['_recorded_'+item].get_value().T,
                         dim=unit.dim, copy=True)
     elif item.endswith('_') and item[:-1] in self.record_variables:
         return self.variables['_recorded_'+item[:-1]].get_value().T
     else:
         return Group.__getattr__(self, item)
Esempio n. 6
0
 def __getattr__(self, item):
     # We do this because __setattr__ and __getattr__ are not active until
     # _group_attribute_access_active attribute is set, and if it is set,
     # then __getattr__ will not be called. Therefore, if getattr is called
     # with this name, it is because it hasn't been set yet and so this
     # method should raise an AttributeError to agree that it hasn't been
     # called yet.
     if item == '_group_attribute_access_active':
         raise AttributeError
     if not hasattr(self, '_group_attribute_access_active'):
         raise AttributeError
     if item in self.record_variables:
         unit = self.variables[item].unit
         return Quantity(self.variables[item].get_value().T,
                         dim=unit.dim, copy=True)
     elif item.endswith('_') and item[:-1] in self.record_variables:
         return self.variables[item[:-1]].get_value().T
     else:
         return Group.__getattr__(self, item)