def saveUVDistanceForPost(filename, name, p_index, c_index):
    """ Saves connection length data but for incoming connections of a given
    post-synaptic neuron,
    name and p_index therefore also refer to the post-synaptic layer """
    object = bpy.data.objects[name]
    uvs = getUVs(object, p_index)
    
    distances = []
    axon_lengths = []
    number_particles = len(object.particle_systems[p_index].particles)
    for i, p in enumerate(object.particle_systems[p_index].particles):
        logger.info('%i / %i' % (i, number_particles))
        pre_neurons, synapses = model.getPreIndicesOfPostIndex(c_index, i)
        distance = []
        axon_length = []
        for j in range(len(pre_neurons)):
            distance.append(model.CONNECTION_RESULTS[c_index]['d'][pre_neurons[j]][synapses[j]])
            axon_length.append(pam.computeDistance_PreToSynapse(c_index, pre_neurons[j], [synapses[j]])[0])
            
        distances.append(np.mean(distance))
        axon_lengths.append(np.mean(axon_length))
        
    f = open(filename, 'w')
    writer = csv.writer(
        f,
        delimiter=";",
        quoting=csv.QUOTE_NONNUMERIC
    )
    
    for i, uv in enumerate(uvs):
        #for d in distances[i]:
        writer.writerow([uv[0], uv[1], distances[i], axon_lengths[i]])
        
    f.close()        
Example #2
0
def saveUVDistanceForPost(filename, name, p_index, c_index):
    """ Saves connection length data but for incoming connections of a given
    post-synaptic neuron,
    name and p_index therefore also refer to the post-synaptic layer """
    object = bpy.data.objects[name]
    uvs = getUVs(object, p_index)

    distances = []
    axon_lengths = []
    number_particles = len(object.particle_systems[p_index].particles)
    for i, p in enumerate(object.particle_systems[p_index].particles):
        logger.info('%i / %i' % (i, number_particles))
        pre_neurons, synapses = model.getPreIndicesOfPostIndex(c_index, i)
        distance = []
        axon_length = []
        for j in range(len(pre_neurons)):
            distance.append(model.CONNECTION_RESULTS[c_index]['d'][
                pre_neurons[j]][synapses[j]])
            axon_length.append(
                pam.computeDistance_PreToSynapse(c_index, pre_neurons[j],
                                                 [synapses[j]])[0])

        distances.append(np.mean(distance))
        axon_lengths.append(np.mean(axon_length))

    f = open(filename, 'w')
    writer = csv.writer(f, delimiter=";", quoting=csv.QUOTE_NONNUMERIC)

    for i, uv in enumerate(uvs):
        #for d in distances[i]:
        writer.writerow([uv[0], uv[1], distances[i], axon_lengths[i]])

    f.close()
Example #3
0
def colorizeMapping(mapping_id):
    """ Colorizes pre layer for a given mapping """

    pre = model.CONNECTIONS[mapping_id][0][0]
    post = model.CONNECTIONS[mapping_id][0][-1]
    #neuron = bpy.data.objects['Neuron_Sphere']

    distances_pre = getDistancesPerParticle(
        model.CONNECTION_RESULTS[mapping_id]['d'])
    pre_indices = getParticleIndicesForVertices(pre, 0)

    for i, p_ind in enumerate(pre_indices):
        if distances_pre[p_ind] == 0:
            pv.visualizePoint(
                pre.particle_systems[0].particles[p_ind].location)

    distances_post = []
    post_indices = getParticleIndicesForVertices(post, 0)

    for i, p in enumerate(post.particle_systems[0].particles):
        pre_neurons, synapses = model.getPreIndicesOfPostIndex(mapping_id, i)
        distance = []
        for j in range(len(pre_neurons)):
            distance.append(model.CONNECTION_RESULTS[mapping_id]['d'][
                pre_neurons[j]][synapses[j]])

        mean = np.mean(distance)
        if np.isnan(mean):
            distances_post.append(0)
        else:
            distances_post.append(mean)

    for i, p_ind in enumerate(post_indices):
        if distances_post[p_ind] == 0:
            pv.visualizePoint(
                post.particle_systems[0].particles[p_ind].location)

    print(distances_post)
    print(type(distances_pre))
    print(type(distances_post))
    mean_d = np.mean(list(distances_pre) + distances_post)
    min_percent = np.min(list(distances_pre) + distances_post) / mean_d
    max_percent = np.max(list(distances_pre) + distances_post) / mean_d
    distances_pre = distances_pre / mean_d
    distances_post = np.array(distances_post) / mean_d

    colorizeLayer(pre, np.take(distances_pre, pre_indices),
                  [min_percent, max_percent])
    colorizeLayer(post, np.take(distances_post, post_indices),
                  [min_percent, max_percent])
def colorizeMapping(mapping_id):
    """ Colorizes pre layer for a given mapping """
    
    pre = model.CONNECTIONS[mapping_id][0][0]
    post = model.CONNECTIONS[mapping_id][0][-1]
    #neuron = bpy.data.objects['Neuron_Sphere']

    distances_pre = getDistancesPerParticle(model.CONNECTION_RESULTS[mapping_id]['d'])
    pre_indices = getParticleIndicesForVertices(pre, 0)

    for i, p_ind in enumerate(pre_indices):
        if distances_pre[p_ind] == 0:
            pv.visualizePoint(pre.particle_systems[0].particles[p_ind].location)

    
    
    distances_post = []
    post_indices = getParticleIndicesForVertices(post, 0)
    
    for i, p in enumerate(post.particle_systems[0].particles):
        pre_neurons, synapses = model.getPreIndicesOfPostIndex(mapping_id, i)
        distance = []
        for j in range(len(pre_neurons)):
            distance.append(model.CONNECTION_RESULTS[mapping_id]['d'][pre_neurons[j]][synapses[j]])
            
        mean = np.mean(distance)
        if np.isnan(mean):
            distances_post.append(0)
        else:
            distances_post.append(mean)
    
    for i, p_ind in enumerate(post_indices):
        if distances_post[p_ind] == 0:
            pv.visualizePoint(post.particle_systems[0].particles[p_ind].location)

    print(distances_post)
    print(type(distances_pre))
    print(type(distances_post))
    mean_d = np.mean(list(distances_pre) + distances_post)
    min_percent = np.min(list(distances_pre) + distances_post) / mean_d
    max_percent = np.max(list(distances_pre) + distances_post) / mean_d
    distances_pre = distances_pre / mean_d
    distances_post = np.array(distances_post) / mean_d    
    
    colorizeLayer(pre, np.take(distances_pre, pre_indices), [min_percent, max_percent])
    colorizeLayer(post, np.take(distances_post, post_indices), [min_percent, max_percent])