def _showSimple(): max_interpol_pts = 10 def interpolate_section(section): sec_start = section.get_distal_npa4() sec_end = section.get_proximal_npa4() length = section.get_length() rad = min(section.d_r, section.p_r) n = min(max(int(lToRRatio * length / rad), 1), max_interpol_pts) j_vec_steps = (sec_end - sec_start) / n int_pts = [sec_start + k * j_vec_steps for k in range(0, n)] return int_pts lbs = [] for morph in self.morphs: lb = SeqUtils.flatten(ListBuilderSectionVisitor(functor=interpolate_section, morph=morph) ()) lbs.extend(lb) pts = numpy.array(lbs) x = pts[:, 0] y = pts[:, 1] z = pts[:, 2] s = pts[:, 3] mlab.points3d(x, y, z, s, colormap=self.colormap, scale_factor=self.scale_factor) mlab.outline()
def check_tree(self): if not self.morph.is_dummy_section_set(): return dummy_section = self.morph.get_dummy_section() self.check_dummy_section(dummy_section) # Check nothing changed in the tree: morphmd5 = _get_md5_of_morphology(self.morph) if self.morphmd5cache: if morphmd5 != self.morphmd5cache: raise Exception('MD5 of tree has changed!') else: return self.morphmd5cache = morphmd5 # Check the tree is sensible: self.check_section(self.morph._dummysection, self.morph, dummysection=True, recurse=True) # Check that there are not duplications of idTags in the tree: idtags = SeqUtils.flatten([section.idtag for section in self.morph if section.idtag]) #print idtags assert len(idtags) == len(list(set(idtags))) # Check the regions for rgn in self.morph.get_regions(): self.check_region(rgn, self.morph)
def get_region(self, name): """ Returns a Region object relevant to this tree, given a filename""" assert self.ensure_consistency() return SeqUtils.filter_expect_single(self.get_regions(), lambda r: r.name == name)
def check_tree(self): if not self.morph.is_dummy_section_set(): return dummy_section = self.morph.get_dummy_section() self.check_dummy_section(dummy_section) # Check nothing changed in the tree: morphmd5 = _get_md5_of_morphology(self.morph) if self.morphmd5cache: if morphmd5 != self.morphmd5cache: raise Exception('MD5 of tree has changed!') else: return self.morphmd5cache = morphmd5 # Check the tree is sensible: self.check_section(self.morph._dummysection, self.morph, dummysection=True, recurse=True) # Check that there are not duplications of idTags in the tree: idtags = SeqUtils.flatten( [section.idtag for section in self.morph if section.idtag]) #print idtags assert len(idtags) == len(list(set(idtags))) # Check the regions for rgn in self.morph.get_regions(): self.check_region(rgn, self.morph)
def get_channel(self, name): try: return SeqUtils.filter_expect_single( self.get_all_mechanisms_applied_to_cell(), lambda chl: chl.name == name) except: print 'Options: ', [ chl.name for chl in self.get_all_mechanisms_applied_to_cell() ] raise
def get_passives_for_section(self, section): sectionptas = [pta for pta in self.appliedpassives if pta.targetter.does_target_section(section)] passivemechs = {} for passiveproperty in PassiveProperty.all: section_property_ptas = [spta for spta in sectionptas if spta.passiveproperty == passiveproperty] highest_prority_mech = SeqUtils.max_with_unique_check(section_property_ptas, key=lambda pta: pta.targetter.get_priority()) passivemechs[passiveproperty] = highest_prority_mech return passivemechs
def check_region(self, region, morph): check_cstyle_varname(region.name) # Check no-other region has this name: # print "Checking region:", region.name # print "All Regions:", ",".join([r.name for r in self.morph.get_regions()]) assert SeqUtils.filter_expect_single(self.morph.get_regions(), lambda rgn: rgn.name == region.name) == region assert region.morph == morph for section in region.sections: assert region == section.region
def __call__(self, morph=None): self.morph = SeqUtils.filter_expect_single( [morph, self.morph], lambda s: s is not None) if not self.alreadycalled: self.pretraversefunctor() self.visit_section_internal(self.morph.get_dummy_section()) self.posttraversefunctor() self.alreadycalled = True return self.returnfunctor()
def check_region(self, region, morph): check_cstyle_varname(region.name) # Check no-other region has this name: # print "Checking region:", region.name # print "All Regions:", ",".join([r.name for r in self.morph.get_regions()]) assert SeqUtils.filter_expect_single( self.morph.get_regions(), lambda rgn: rgn.name == region.name) == region assert region.morph == morph for section in region.sections: assert region == section.region
def get_resolved_mtas_for_section(self, section): # TODO: Some basic error checking here: we should ensure that if we specialise a region/section, then we also # cover the Everywhere. This should help us catch errors in ehich the user creates 2 mechanisms of the same thing, and # and so applies the same channel twice accidentally. # All the mechanisms targetting a certain region: mtas_targetting_section = [mta for mta in self.appliedmechanisms if mta.targetter.does_target_section(section)] mechs_targetting_section = set([ mta.mechanism for mta in self.appliedmechanisms]) resolved_mechs = [] for mech in mechs_targetting_section: mtas_with_mech = [mta for mta in mtas_targetting_section if mta.mechanism is mech] highest_prority_mech = SeqUtils.max_with_unique_check(mtas_with_mech, key=lambda pta: pta.targetter.get_priority()) resolved_mechs.append(highest_prority_mech) return resolved_mechs
def get_passives_for_section(self, section): sectionptas = [ pta for pta in self.appliedpassives if pta.targetter.does_target_section(section) ] passivemechs = {} for passiveproperty in PassiveProperty.all: section_property_ptas = [ spta for spta in sectionptas if spta.passiveproperty == passiveproperty ] highest_prority_mech = SeqUtils.max_with_unique_check( section_property_ptas, key=lambda pta: pta.targetter.get_priority()) passivemechs[passiveproperty] = highest_prority_mech return passivemechs
def get_resolved_mtas_for_section(self, section): # TODO: Some basic error checking here: we should ensure that if we specialise a region/section, then we also # cover the Everywhere. This should help us catch errors in ehich the user creates 2 mechanisms of the same thing, and # and so applies the same channel twice accidentally. # All the mechanisms targetting a certain region: mtas_targetting_section = [ mta for mta in self.appliedmechanisms if mta.targetter.does_target_section(section) ] mechs_targetting_section = set( [mta.mechanism for mta in self.appliedmechanisms]) resolved_mechs = [] for mech in mechs_targetting_section: mtas_with_mech = [ mta for mta in mtas_targetting_section if mta.mechanism is mech ] highest_prority_mech = SeqUtils.max_with_unique_check( mtas_with_mech, key=lambda pta: pta.targetter.get_priority()) resolved_mechs.append(highest_prority_mech) return resolved_mechs
def _showSimple(): max_interpol_pts = 10 def interpolate_section(section): sec_start = section.get_distal_npa4() sec_end = section.get_proximal_npa4() length = section.get_length() rad = min(section.d_r, section.p_r) n = min(max(int(lToRRatio * length / rad), 1), max_interpol_pts) j_vec_steps = (sec_end - sec_start) / n int_pts = [sec_start + k * j_vec_steps for k in range(0, n)] return int_pts lbs = [] for morph in self.morphs: lb = SeqUtils.flatten( ListBuilderSectionVisitor(functor=interpolate_section, morph=morph)()) lbs.extend(lb) pts = numpy.array(lbs) x = pts[:, 0] y = pts[:, 1] z = pts[:, 2] s = pts[:, 3] mlab.points3d(x, y, z, s, colormap=self.colormap, scale_factor=self.scale_factor) mlab.outline()
def get_channel(self, name): try: return SeqUtils.filter_expect_single(self.get_all_mechanisms_applied_to_cell(), lambda chl: chl.name==name) except: print 'Options: ', [ chl.name for chl in self.get_all_mechanisms_applied_to_cell() ] raise
def get_section(self, idtag): """ Returns a Section object with a given id""" #assert self.ensure_consistency() return SeqUtils.filter_expect_single(self, lambda s: s.idtag == idtag)
def get_location_at_distance_away_from_dummy(cls, cell, distance, section_predicate=None): """Utility Function""" return SeqUtils.expect_single(cls.get_locations_at_distance_away_from_dummy(cell=cell, distance=distance, section_predicate=section_predicate))