Create an unplaced population

Simple example showing how to create an unplaced axon population with NRV and plot an histogram of the diameters values. In this example population are either created:

See also

Users’ guide

from nrv.utils import geom
from nrv.nmod._axon_population import axon_population

import matplotlib.pyplot as plt
import numpy as np
from pandas import DataFrame

Generate population from data

n_ax = 10
# Randomly generate axon types and diameters
ax_type = np.random.randint(0,2,n_ax)
ax_diameters = np.random.random(n_ax)*20

When data are in a tupple

pop_tup = axon_population()
pop_tup.create_population_from_data((ax_type, ax_diameters))
pop_tup.axon_pop
types diameters
0 1 13.051298
1 0 7.272594
2 0 13.462742
3 0 3.767784
4 1 17.031086
5 0 1.866819
6 0 9.854876
7 1 18.509694
8 1 11.154534
9 1 3.687734


When data are in a np.ndarray

data = np.vstack((ax_type, ax_diameters))
pop_np = axon_population()
pop_np.create_population_from_data(data)
pop_np.axon_pop
types diameters
0 1.0 13.051298
1 0.0 7.272594
2 0.0 13.462742
3 0.0 3.767784
4 1.0 17.031086
5 0.0 1.866819
6 0.0 9.854876
7 1.0 18.509694
8 1.0 11.154534
9 1.0 3.687734


When data are in a dict

data = {"types":ax_type, "diameters":ax_diameters, "other_key":0}
pop_dict = axon_population()
pop_dict.create_population_from_data(data)
pop_dict.axon_pop
types diameters
0 1 13.051298
1 0 7.272594
2 0 13.462742
3 0 3.767784
4 1 17.031086
5 0 1.866819
6 0 9.854876
7 1 18.509694
8 1 11.154534
9 1 3.687734


When data are in a dataframe

data = DataFrame({"types":ax_type, "diameters":ax_diameters, "other_key":np.random.rand(len(ax_type))})
pop_df = axon_population()
pop_df.create_population_from_data(data)
pop_df.axon_pop
types diameters
0 1 13.051298
1 0 7.272594
2 0 13.462742
3 0 3.767784
4 1 17.031086
5 0 1.866819
6 0 9.854876
7 1 18.509694
8 1 11.154534
9 1 3.687734


Generate population from data

Small 20-axons population

n_ax = 20

pop_stat = axon_population()
pop_stat.create_population_from_stat(n_ax=n_ax)
pop_stat.axon_pop
types diameters
0 1.0 2.599198
1 0.0 2.401403
2 0.0 2.070140
3 0.0 1.756313
4 1.0 2.789579
5 0.0 0.588176
6 0.0 0.524248
7 0.0 0.512625
8 0.0 1.698196
9 0.0 2.325852
10 0.0 1.959719
11 0.0 2.046894
12 0.0 2.767535
13 1.0 2.484970
14 1.0 2.675351
15 1.0 3.513026
16 1.0 3.398798
17 0.0 1.669138
18 0.0 2.197996
19 0.0 2.227054


Histograms

fig, axs = plt.subplots(2, 2,  layout="constrained")
for _i, n_ax in enumerate([20, 200, 2000, 20000]):
    ax = axs[_i%2, _i//2]
    pop_stat = axon_population()
    pop_stat.create_population_from_stat(n_ax=n_ax)
    pop_stat.hist(axes=ax, unmyel_color=("r",.4), myel_color=("b",.4), bins=50)
    ax.set_title(f"{n_ax} axons population")
    ax.set_xlabel("diameter")
    ax.set_ylabel("axons number")

plt.show()
20 axons population, 2000 axons population, 200 axons population, 20000 axons population

Total running time of the script: (0 minutes 1.299 seconds)