Example #1
0
def test_functions():
    '''
    Run each of the main functions.
    '''
    ds.reset_kernel()
    ds.set_kernel_status('environment_required', False)

    m = ds.generate_model('constant', 'memory-based', 'run-and-tumble')
    dp = ds.get_default_properties(m)
    e = ds.get_environment()
    ks = ds.get_kernel_status()
    ms = ds.get_models()

    pp = {"growth_cone_model": m, "position": (0., 0.) * um}
    gn = ds.create_neurons(params=pp, num_neurites=2)

    n = ds.get_neurons()
    ns = ds.get_object_properties(n)
    ns = ds.get_object_properties(n, level="neurite")
    ns = ds.get_object_properties(n, level="growth_cone")
    ns = ds.get_object_state(n)
    assert ds.get_object_state(n, "num_growth_cones") == 2
    ns = ds.get_object_state(n, level="dendrite_1")
    si = ds.get_simulation_id()

    ds.simulate(20 * hour)

    ni = ds.get_neurons()
def run_dense(neuron_params, axes, letter, single=False):

    # neuron_params["rw_memory_tau"]: 4.,
    # neuron_params["rw_delta_corr"]: 1.8,
    ds.set_kernel_status(kernel, simulation_id="random_walk_axons")
    neuron_params["position"] = np.zeros((num_neurons, 2)) * um
    simulated_neurons = num_neurons
    if single:
        simulated_neurons = 1.
        neuron_params["position"] = np.array([0, 0]) * um
    gids = ds.create_neurons(n=simulated_neurons,
                             params=neuron_params,
                             num_neurites=1,
                             position=[])

    step(1000 * second, 1, os.path.join(os.getcwd(), "primo"), plot=False)
    neurons = ds.get_neurons()
    structure = ds.morphology.NeuronStructure(neurons)
    population = ds.Population.from_structure(structure)
    axons = population.axon_all_points()
    from matplotlib.colors import LogNorm
    import matplotlib
    import copy
    axes.text(0.03,
              1.2,
              letter,
              horizontalalignment='center',
              verticalalignment='center',
              weight='bold',
              fontsize=12,
              transform=axes.transAxes)
    if not single:
        my_cmap = copy.copy(
            matplotlib.cm.get_cmap('viridis'))  # copy the default cmap
        my_cmap.set_bad((0, 0, 0))
        axes.hist2d(axons[:, 0],
                    axons[:, 1],
                    bins=100,
                    range=[[0, 400], [-200, 200]],
                    norm=LogNorm(),
                    cmap=my_cmap)
        axes.set_xlabel("X")
        axes.set_ylabel("Y")
        axes.set_title("path density for\n {}".format(
            neuron_params["growth_cone_model"]))
    else:
        axes.plot(axons[:, 0], axons[:, 1], c='r')
    ds.reset_kernel()
def run_dense(neuron_params,letter,length_simulation,single=False):

    # neuron_params["rw_memory_tau"]: 4.,
    # neuron_params["rw_delta_corr"]: 1.8,
    ds.set_kernel_status(kernel, simulation_id="random_walk_axons")
    neuron_params["position"]=np.zeros((num_neurons,2))
    simulated_neurons = num_neurons
    gids = ds.create_neurons(n=simulated_neurons,
                                   params=neuron_params,
                                   num_neurites=1,
                                   position=[]
                                   )

    step(length_simulation, 1, False ,plot=False)
    neurons    = ds.get_neurons()
    structure  = ds.morphology.NeuronStructure(neurons)
    population = ds.Population.from_structure(structure)
    ens =  ds.EnsembleRW(population)
    ens.characterizeRW("axon")
    ens.name = neuron_params["growth_cone_model"]
    fits = ens.fit()
    # import pdb; pdb.set_trace()  # XXX BREAKPOINT
    ds.reset_kernel()
    return ens
Example #4
0
    # print(swc_file)
    return swc_file


if __name__ == '__main__':
    num_omp = 1
    kernel = {
        "seeds": np.random.randint(0, 10000, num_omp).tolist(),
        "num_local_threads": num_omp,
        "environment_required": False
    }
    swc_file = lateral_branching(neuron_params)

    ds.plot_neurons(show=True)

    pop = ds.get_neurons()
    n = pop[0]

    tree = n.axon.get_tree()
    tree.show_dendrogram()

    # ~ import neurom
    # ~ from neurom import viewer
    # ~ asym = []
    # ~ num_tips = []
    # ~ for n in pop:
    # ~ tree = n.axon.get_tree()
    # ~ num_tips.append(len(tree.tips))
    # ~ nrn = tree.neurom_tree()
    # ~ asym.append(np.average(neurom.fst.get("partition_asymmetry", nrn)))
Example #5
0
def test_delete_neurons():
    '''
    Neurons deletion
    '''
    ds.reset_kernel()

    num_neurons = 50
    simtime     = 2.*minute

    initial_state = np.random.get_state()

    ds.set_kernel_status("environment_required", False)

    # create and delete
    nparams = {
        "position": np.random.uniform(-1000, 1000, (num_neurons, 2))*um,
        "growth_cone_model": "res_po_rt"
    }
    neurons = ds.create_neurons(num_neurons, params=nparams,
                                num_neurites=2)

    ds.delete_neurons(3)
    ds.delete_neurons(neurons[8])

    # check neurons have been deleted
    neurons_got = ds.get_neurons()
    n_to_ints   = [int(n) for n in neurons_got]
    n_to_ints  += ds.get_neurons(True)

    assert len(n_to_ints) == 2*(num_neurons - 2), \
        "Failed with state " + str(initial_state)
    assert 3 not in n_to_ints, \
        "Failed with state " + str(initial_state)
    assert 8 not in n_to_ints, \
        "Failed with state " + str(initial_state)

    # simulate then delete
    ds.simulate(simtime)
    ds.delete_neurons([5, 7])
    ds.delete_neurons(neurons[40:45])

    # recreate neurons and resimulate
    nparams = {
        "position": np.random.uniform(-1000, 1000, (num_neurons, 2))*um,
        "growth_cone_model": "res_po_rt"
    }
    _ = ds.create_neurons(num_neurons, params=nparams, num_neurites=2)
    ds.simulate(simtime)

    neurons_got = ds.get_neurons()
    n_to_ints   = [int(n) for n in neurons_got]
    n_to_ints  += ds.get_neurons(True)

    assert len(n_to_ints) == 2*(2*num_neurons - 4 - len(neurons[40:45])), \
        "Failed with state " + str(initial_state)
    assert 5 not in n_to_ints, \
        "Failed with state " + str(initial_state)
    assert 7 not in n_to_ints, \
        "Failed with state " + str(initial_state)
    for n in neurons[40:45]:
        assert int(n) not in n_to_ints, \
            "Failed with state " + str(initial_state)

    # delete all neurons
    ds.delete_neurons()

    # check no neurons are left
    assert not ds.get_neurons(), \
        "Failed with state " + str(initial_state)