def extend_front(front, seed, constellation): # new_pos =front.xyz + np.array([L_NORM,0,2.0]) # new_front = prepare_next_front(front,new_pos,set_radius=1.0) # return [new_front] # repelled by a different neuron, get information other_entities = get_entity("cell_type_1", constellation) target = np.array([200, 30, 200]) if not len(other_entities) == 0: dir_to_entity = gradient_to(front, other_entities, strength=10.0, decay_factor=0.15, cutoff=2.5, what="nearest") if np.allclose(dir_to_entity, np.array([0.0, 0.0, 0.0])): new_pos = front.xyz + \ normalize_length(target-front.xyz,L_NORM ) + \ normalize_length(unit_sample_on_sphere(),L_NORM/1.0 ) # was 10 new_front = prepare_next_front(front, new_pos, set_radius=1.0) print("[debug] To_left.py:: still far") else: new_pos = front.xyz + normalize_length( -1 * dir_to_entity + unit_sample_on_sphere(), L_NORM) new_front = prepare_next_front(front, new_pos, set_radius=1.0) print("[debug] To_left.py:: potential intercept avoided") else: # during the first extension cycle, no distal info is known locally new_pos = front.xyz + normalize_length(target - front.xyz, L_NORM) new_front = prepare_next_front(front, new_pos, set_radius=1.0) return [new_front]
def extend_front(front,seed,constellation) : # new_pos =front.xyz + np.array([L_NORM,0,2.0]) # new_front = prepare_next_front(front,new_pos,set_radius=1.0) # return [new_front] # repelled by a different neuron, get information other_entities = get_entity("cell_type_1",constellation) target = np.array([200,30,200]) if not len(other_entities) == 0: dir_to_entity = gradient_to(front,other_entities,strength=10.0,decay_factor=0.15,cutoff=2.5,what="nearest") if np.allclose(dir_to_entity,np.array([0.0,0.0,0.0])): new_pos = front.xyz + \ normalize_length(target-front.xyz,L_NORM ) + \ normalize_length(unit_sample_on_sphere(),L_NORM/1.0 ) # was 10 new_front = prepare_next_front(front,new_pos,set_radius=1.0) print "[debug] To_left.py:: still far" else: new_pos = front.xyz + normalize_length(-1*dir_to_entity + unit_sample_on_sphere(),L_NORM) new_front = prepare_next_front(front,new_pos,set_radius=1.0) print "[debug] To_left.py:: potential intercept avoided" else: # during the first extension cycle, no distal info is known locally new_pos =front.xyz + normalize_length(target-front.xyz,L_NORM ) new_front = prepare_next_front(front,new_pos,set_radius=1.0) return [new_front]
def extend_front(front,seed,constellation) : if front.order == 0 : # soma new_fronts = [] for i in range(3): rnd_dir = unit_sample_on_sphere() rnd_dir[2] = np.abs(rnd_dir[2]) new_pos = normalize_length(rnd_dir,15) new_pos = front.xyz + new_pos new_front = prepare_next_front(front,new_pos,set_radius=3.0,add_order=1) new_fronts.append(new_front) return new_fronts else : if np.random.random() < 0.1 : new_fronts = [] other_entities = get_entity("pia",constellation) for i in range(2): rnd_dir = unit_sample_on_sphere() if len(other_entities) == 0: rnd_dir = unit_sample_on_sphere() rnd_dir[2] = np.abs(rnd_dir[2]) new_pos = normalize_length(rnd_dir,15) new_pos = front.xyz + new_pos new_front = prepare_next_front(front,new_pos,set_radius=3.0,add_order=1) new_fronts.append(new_front) else: dir_to_pia = direction_to(front,other_entities,what="nearest") dir_to_pia = normalize_length(dir_to_pia,2.0) + rnd_dir new_pos = front.xyz + normalize_length(dir_to_pia,10) new_front = prepare_next_front(front,new_pos,radius_factor=0.5,add_order=True) new_fronts.append(new_front) return new_fronts else : rnd_dir = unit_sample_on_sphere() other_entities = get_entity("pia",constellation) gradient_to_pia = gradient_to(front,other_entities,1.0,0.0001,what='nearest') # or go directly to the pia # gradient_to_pia = direction_to(front,other_entities,what='nearest') pia_interaction = gradient_to_pia + rnd_dir new_dir = normalize_length(pia_interaction,1.5) #+ rnd_dir new_pos = front.xyz + normalize_length(new_dir,10) new_front = prepare_next_front(front,new_pos,radius_factor=0.95) if new_pos[2] > 190 : return None else: return [new_front]
def extend_front(front,seed,constellation) : """ follow gradient to a_point Attractor. The stronger the attraction becomes, the straighter the path to the attractor """ other_entities = get_entity("a_point",constellation) rnd_dir = unit_sample_on_sphere() dir_to_entity = gradient_to(front,other_entities,1.7,0.01,what="nearest") dir_to_entity = dir_to_entity + 0.5*rnd_dir new_pos = front.xyz + normalize_length(dir_to_entity,L_NORM) new_front = prepare_next_front(front,new_pos,set_radius=1.0) return [new_front]
def extend_basal_front(front, constellation): bif_prob = 0.78 / (2.0 * front.order + 1.0) # was2.5 and 0.8 bif_prob = bif_prob if front.order < 6 else bif_prob / 1.8 bif_prob = 0.0 if front.order >= 6 else bif_prob if front.order >= 2 and np.random.random() < 0.07: # wa 00.6 front.no_branch = True if np.random.random() > bif_prob or \ front.no_branch: rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz soma_dir = -1.0 * normalize_length( direction_to(front, [front.soma_pos], what="nearest"), 0.8) eigen_entities = get_eigen_entity(front, constellation) eigen_dir = np.array([0, 0, 0]) eigen_dir = -1.0 * gradient_to(front, eigen_entities, 5.0 / (front.order), 0.05, what="nearest", cutoff=0.2) new_dir = normalize_length(heading, 1.0) + soma_dir + normalize_length( rnd_dir, 1.2) + eigen_dir new_pos = front.xyz + normalize_length(new_dir, L_NORM) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=False) term_prob = 0.015 * front.order if front.order <= 6 else 0.3 if np.random.random() < term_prob: return [] return [new_front] else: new_fronts = [] for i in range(2): rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(heading, 1.5) + rnd_dir new_pos = front.xyz + normalize_length(new_dir, L_NORM) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=True) new_fronts.append(new_front) return new_fronts
def extend_apical_front(front, constellation): pia = get_entity("pia", constellation) dir_to_pia = direction_to(front, pia, what="nearest") grad_to_pia = gradient_to(front, pia, 5.0, 0.015, cutoff=0.3, what="nearest") if np.sqrt(sum((grad_to_pia)**2)) >= 3.0: print "too close to pia!!! +++++++++++++++++++" #time.sleep(1) return [] if (front.layer == 4 or front.layer == 5) and not front.oblique: # make an oblique dendrite with some probability (and extend the main branch) oblique_prob = 0.3 if front.layer == 4 else 0.12 # maybe L5 -> 0.0 if front.order >= 15: oblique_prob = 0.0 if np.random.random() < oblique_prob: new_fronts = [] # orthogonal direction to parent branch: HOWTO? rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(heading,0.5) + \ normalize_length(rnd_dir,1.0) new_pos = front.xyz + normalize_length(new_dir, APICAL_NORM) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=True) new_front.oblique = True #new_front.swc_type=8 new_front.oblique_start = front # for directional information # if front.layer == 4 and np.random.random() < 0.005: # new_front.oblique=False # and extend rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(dir_to_pia,1.5) + \ normalize_length(heading,0.) + \ normalize_length(rnd_dir,.5) new_pos = front.xyz + normalize_length(new_dir, APICAL_MAIN) new_front2 = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=True) #new_front2.swc_type = 4 if front.layer == 5 else 5 return [new_front, new_front2] else: # only extend rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(dir_to_pia,1.5) + \ normalize_length(heading,0.) + \ normalize_length(rnd_dir,.5) new_pos = front.xyz + normalize_length(new_dir, APICAL_MAIN) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=False) #new_front.swc_type = 4 if front.layer == 5 else 5 return [new_front] if front.oblique: # extend or terminate the oblique if front.path_length - front.oblique_start.path_length > 100 and np.random.random( ) < 0.1: return [] else: rnd_dir = unit_sample_on_sphere() eigen_entities = get_eigen_entity(front, constellation) eigen_dir = np.array([0, 0, 0]) # fairly strong self-repulsion, away from the main trunk... eigen_dir = -1.5 * gradient_to( front, eigen_entities, 5.0, 0.03, what="nearest", cutoff=0.2) # or away from the trunk, front.oblique_start dir_from_trunk = -1.0 * (front.oblique_start.xyz - front.xyz) dir_from_trunk = normalize_length(dir_from_trunk, 1.0) heading = front.xyz - front.parent.xyz new_dir = normalize_length(heading,1.0) + \ normalize_length(rnd_dir,0.5) + \ dir_from_trunk #normalize_length(dir_to_pia,0.1) #eigen_dir # + \ # normalize_length(dir_to_pia,0.4) if front.layer == 3: new_dir = new_dir + -1.0 * normalize_length(dir_to_pia, 0.5) # if front.layer == 5 : # new_dir = new_dir + normalize_length(dir_to_pia,0.5) new_pos = front.xyz + normalize_length(new_dir, APICAL_NORM) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=False) #new_front.swc_type=8 # make "normal, not oblique" return [new_front] if front.layer >= 3: #== 3: # keep track of the order to limit the number of bifurcations in this layer if not hasattr(front, 'start_order_L3') and front.layer == 3: # this is the first time, store the current order front.start_order_L3 = front.order # bifurcate or extend bif_prob = 0.08 if front.order - front.start_order_L3 >= 3: bif_prob = 0 if np.random.random() < bif_prob: #bifurcate new_fronts = [] first_vec = None attempts = 0 for i in range(2): rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(dir_to_pia,0.5) + \ normalize_length(heading,0.5) + \ normalize_length(rnd_dir,1.0) new_pos = front.xyz + normalize_length(new_dir, APICAL_NORM) # make sure the bif amplitude reaches a minimum... if first_vec == None: first_vec = normalize_length(new_dir, APICAL_NORM) else: angle_amp = _amp_angle( first_vec, normalize_length(new_dir, APICAL_NORM)) while angle_amp <= MIN_AMP_ANGLE and attempts <= MAX_ANGLE_ATTEMPTS: attempts = attempts + 1 rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(dir_to_pia,0.5) + \ normalize_length(heading,0.5) + \ normalize_length(rnd_dir,1.0) new_pos = front.xyz + normalize_length( new_dir, APICAL_NORM) angle_amp = _amp_angle( first_vec, normalize_length(new_dir, APICAL_NORM)) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=True) new_front.tufted = True # new_front.swc_type = 5 new_fronts.append(new_front) return new_fronts else: # simply extend rnd_dir = unit_sample_on_sphere() eigen_entities = get_eigen_entity(front, constellation) eigen_dir = np.array([0, 0, 0]) eigen_dir = -1.0 * gradient_to(front, eigen_entities, front.repulsion_l3, 0.015, what="nearest", cutoff=0.2) gradient_from_pia = -1.0 * gradient_to( front, pia, 5 * 0.7, 0.01, what="nearest", cutoff=0.2) heading = front.xyz - front.parent.xyz new_dir = normalize_length(heading,1.0) + \ normalize_length(rnd_dir,0.3) + \ eigen_dir + \ normalize_length(dir_to_pia,1.)+ \ gradient_from_pia new_pos = front.xyz + normalize_length(new_dir, APICAL_NORM) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=False) # new_front.swc_type = 6 # some probability to terminate if front.layer == 3 and np.random.random( ) < 0.01 and front.order - front.start_order_L3 >= 3: return [] else: return [new_front] #return [new_front] if front.layer == 2: # keep track of the order to limit the number of bifurcations in this layer if not hasattr(front, 'start_order_L2'): # this is the first time, store the current order front.start_order_L2 = front.order # bifurcate or extend bif_prob = 0.1 if front.order - front.start_order_L3 <= 2: bif_prob = 0.4 rrr = np.random.random() if rrr <= 0.5: if front.order - front.start_order_L2 >= 3: bif_prob = 0 else: if front.order - front.start_order_L2 >= 4: bif_prob = 0 if np.random.random() < bif_prob: #bifurcate new_fronts = [] first_vec = None attempts = 0 for i in range(2): rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(dir_to_pia,0.5) + \ normalize_length(heading,0.5) + \ normalize_length(rnd_dir,1.0) new_pos = front.xyz + normalize_length(new_dir, APICAL_NORM) # make sure the bif amplitude reaches a minimum... if first_vec == None: first_vec = normalize_length(new_dir, APICAL_NORM) else: angle_amp = _amp_angle( first_vec, normalize_length(new_dir, APICAL_NORM)) while angle_amp <= MIN_AMP_ANGLE and attempts <= MAX_ANGLE_ATTEMPTS: attempts = attempts + 1 rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(dir_to_pia,0.5) + \ normalize_length(heading,0.5) + \ normalize_length(rnd_dir,1.0) new_pos = front.xyz + normalize_length( new_dir, APICAL_NORM) angle_amp = _amp_angle( first_vec, normalize_length(new_dir, APICAL_NORM)) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=True) new_front.tufted = True # new_front.swc_type = 7 new_fronts.append(new_front) return new_fronts else: # simply extend rnd_dir = unit_sample_on_sphere() eigen_entities = get_eigen_entity(front, constellation) eigen_dir = np.array([0, 0, 0]) eigen_dir = -1.0 * gradient_to(front, eigen_entities, front.repulsion_l2, 0.015, what="nearest", cutoff=0.2) gradient_from_pia = -1.0 * gradient_to( front, pia, 4.0 * 0.7, 0.01, what="nearest", cutoff=0.2) heading = front.xyz - front.parent.xyz new_dir = normalize_length(heading,1.0) + \ normalize_length(rnd_dir,0.3) + \ eigen_dir + \ normalize_length(dir_to_pia,1.)+ \ gradient_from_pia new_pos = front.xyz + normalize_length(new_dir, APICAL_NORM) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=False) # front.swc_type = 7 # some probability to terminate if np.random.random( ) < 0.03: #* (front.order - front.start_order_L2): return [] else: return [new_front] if front.layer == 1: # keep track of the order to limit the number of bifurcations in this layer if not hasattr(front, 'start_order_L1'): # this is the first time, store the current order front.start_order_L1 = front.order # bifurcate or extend bif_prob = 0.08 if front.order - front.start_order_L3 <= 4: bif_prob = 0.3 if front.order - front.start_order_L1 >= 1: bif_prob = 0 if np.random.random() < bif_prob: #bifurcate new_fronts = [] first_vec = None attempts = 0 for i in range(2): rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(dir_to_pia,0.5) + \ normalize_length(heading,0.5) + \ normalize_length(rnd_dir,1.0) new_pos = front.xyz + normalize_length(new_dir, APICAL_NORM) # make sure the bif amplitude reaches a minimum... if first_vec == None: print "first_vec == None, new_dir: ", new_dir first_vec = normalize_length(new_dir, APICAL_NORM) else: print "first_vec: ", first_vec, " , other: ", normalize_length( new_dir, APICAL_NORM) angle_amp = _amp_angle( first_vec, normalize_length(new_dir, APICAL_NORM)) while angle_amp <= MIN_AMP_ANGLE and attempts <= MAX_ANGLE_ATTEMPTS: attempts = attempts + 1 rnd_dir = unit_sample_on_sphere() heading = front.xyz - front.parent.xyz new_dir = normalize_length(dir_to_pia,0.5) + \ normalize_length(heading,0.5) + \ normalize_length(rnd_dir,1.0) new_pos = front.xyz + normalize_length( new_dir, APICAL_NORM) angle_amp = _amp_angle( first_vec, normalize_length(new_dir, APICAL_NORM)) print "angle_amp=", angle_amp, ", attemps: ", attempts new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=True) new_front.tufted = True #new_front.swc_type = 8 new_fronts.append(new_front) return new_fronts else: # simply extend rnd_dir = unit_sample_on_sphere() eigen_entities = get_eigen_entity(front, constellation) eigen_dir = np.array([0, 0, 0]) eigen_dir = -1.0 * gradient_to(front, eigen_entities, front.repulsion_l1, 0.015, what="nearest", cutoff=0.2) gradient_from_pia = 0 * gradient_to( front, pia, 3.0 * 0.7, 0.01, what="nearest", cutoff=0.2) # 2014-05-12 heading = front.xyz - front.parent.xyz new_dir = normalize_length(heading,1.0) + \ normalize_length(rnd_dir,0.3) + \ eigen_dir + \ normalize_length(dir_to_pia,1.)+ \ gradient_from_pia new_pos = front.xyz + normalize_length(new_dir, APICAL_NORM) new_front = prepare_next_front(front, new_pos, radius_factor=0.98, add_order=False) #new_front.swc_type = 8 if np.random.random() < 0.06: return [] else: return [new_front] return [new_front]
def extend_front(front, seed, constellation): if front.order == 0: # soma new_fronts = [] for i in range(3): rnd_dir = unit_sample_on_sphere() rnd_dir[2] = np.abs(rnd_dir[2]) new_pos = normalize_length(rnd_dir, 15) new_pos = front.xyz + new_pos new_front = prepare_next_front(front, new_pos, set_radius=3.0, add_order=1) new_fronts.append(new_front) return new_fronts else: if np.random.random() < 0.1: new_fronts = [] other_entities = get_entity("pia", constellation) for i in range(2): rnd_dir = unit_sample_on_sphere() if len(other_entities) == 0: rnd_dir = unit_sample_on_sphere() rnd_dir[2] = np.abs(rnd_dir[2]) new_pos = normalize_length(rnd_dir, 15) new_pos = front.xyz + new_pos new_front = prepare_next_front(front, new_pos, set_radius=3.0, add_order=1) new_fronts.append(new_front) else: dir_to_pia = direction_to(front, other_entities, what="nearest") dir_to_pia = normalize_length(dir_to_pia, 2.0) + rnd_dir new_pos = front.xyz + normalize_length(dir_to_pia, 10) new_front = prepare_next_front(front, new_pos, radius_factor=0.5, add_order=True) new_fronts.append(new_front) return new_fronts else: rnd_dir = unit_sample_on_sphere() other_entities = get_entity("pia", constellation) gradient_to_pia = gradient_to(front, other_entities, 1.0, 0.0001, what='nearest') # or go directly to the pia # gradient_to_pia = direction_to(front,other_entities,what='nearest') pia_interaction = gradient_to_pia + rnd_dir new_dir = normalize_length(pia_interaction, 1.5) #+ rnd_dir new_pos = front.xyz + normalize_length(new_dir, 10) new_front = prepare_next_front(front, new_pos, radius_factor=0.95) if new_pos[2] > 190: return None else: return [new_front]