def get_locations_at_distance_away_from_dummy(cls, morphology, distance, section_predicate=None): dist_to_section_distal = SectionVistorFactory.dict_section_distal_dist_from_soma(morph=morphology)() # Section predicates: allows us to generate only on a path, region, etc section_predicate = section_predicate if section_predicate else lambda s:True locations = [] for section in morphology: if not section_predicate(section): continue if section.is_a_root_section(): if distance < dist_to_section_distal[section]: #assert False, 'Not implemented' locations.append(MorphLocation(section=section, sectionpos=distance/dist_to_section_distal[section]) ) else: pass else: proximal_dist = dist_to_section_distal[section.parent] distal_dist = dist_to_section_distal[section] # Does a distance fall on this section: if proximal_dist < distance < distal_dist: prop = (distance - proximal_dist) / (distal_dist - proximal_dist) assert 0.0 <= prop <= 1.0 locations.append(MorphLocation(section=section, sectionpos=prop)) else: pass dummy = MorphLocation(morphology.get_dummy_section().children[0], 0.0) # Some sanity checking: for loc in locations: p = MorphPath(loc, dummy) assert np.fabs(p.get_length() - distance) < 0.01 return locations
def distance_to_soma(self): morphology_path = MorphPath(self.cell.soma, self.cell_location.morphlocation) return morphology_path.get_length()