Axon Population Placement

Simple example to help using axon_population placement methods.

This example shows how to:
  • Create axon populations for different shapes (circle, ellipse, polygon)

  • Place axons using both direct data and the placer

  • Use and highlight various placer arguments (delta, delta_trace, delta_in, method, fit_to_size, n_iter)

See also

Users’ guide

import matplotlib.pyplot as plt
import numpy as np
from nrv.utils import geom
from nrv.nmod._axon_population import axon_population

Quick placement

Note

fill_geometry() both create and place the geometry

center = (0, 0)
radius = 20
n_ax=10

pop_circle = axon_population()
pop_circle.set_geometry(center=center, radius=radius)

pop_circle.fill_geometry(n_ax=n_ax)
pop_circle.axon_pop
Placing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
types diameters y z is_placed node_shift
0 0.0 0.890381 3.347250 -10.694279 True 0.000000
1 0.0 2.227054 -7.271317 -11.799994 True 0.000000
2 1.0 4.617234 6.216501 -13.584122 True 0.478578
3 1.0 2.332665 10.876761 0.459076 True 0.144543
4 0.0 1.355311 -11.074509 15.003376 True 0.000000
5 0.0 0.646293 -13.579210 -6.061319 True 0.000000
6 0.0 1.012425 12.295311 5.516537 True 0.000000
7 0.0 1.878357 -4.748079 17.140103 True 0.000000
8 0.0 1.721443 -11.977582 7.371899 True 0.000000
9 1.0 3.208417 -9.327028 -6.300269 True 0.115094


Tunable parameters

Placement in a Circle using the placer

center = (0, 0)
radius = 100
n_ax = 625

pop_circle = axon_population()
pop_circle.set_geometry(center=center, radius=radius)
pop_circle.create_population_from_stat(n_ax=n_ax)
pop_circle.place_population(delta=2)  # default placer
pop_circle.get_ppop_info(verbose=True)
Placing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00

Placement in an Ellipse using the placer with custom delta

center_ellipse = (200, 0)
r_ellipse = (120, 60)
angle = np.pi/6

pop_ellipse = axon_population()
pop_ellipse.set_geometry(center=center_ellipse, radius=r_ellipse, rot=angle)
pop_ellipse.create_population_from_stat(n_ax=n_ax)
pop_ellipse.place_population(delta=2)
pop_ellipse.get_ppop_info(verbose=True)
Placing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00

Placement in a Polygon using the placer and differen deltas_in/delta_trace

vertices = [(-100, 100), (0, 200), (100, 100), (60, 0), (0, -100), (-60, 0)]
pop_polygon = axon_population()
poly = geom.Polygon(vertices=vertices)
pop_polygon.set_geometry(geometry=poly)
pop_polygon.create_population_from_stat(n_ax=n_ax)
pop_polygon.place_population(delta_in=2, delta_trace=20)
pop_polygon.get_ppop_info(verbose=True)
Placing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:12

Placement from data (direct y/z)

Generate mesh grid position inside the circle bounding box

x = np.linspace(-radius, radius, int(n_ax**0.5))
xv, yv = np.meshgrid(x, x)
xv = xv.reshape((n_ax,))
yv = yv.reshape((n_ax,))
types = np.random.randint(0, 2, n_ax)
n_mye = types.sum()
diameters = np.zeros(n_ax)
diameters[types.astype(bool)] = np.random.uniform(2, 11, n_mye)
diameters[~types.astype(bool)] = np.random.uniform(.1,4, n_ax-n_mye)

pop_data = axon_population()
pop_data.set_geometry(center=center, radius=radius)
pop_data.create_population_from_data((types, diameters, xv, yv))
pop_data.get_ppop_info(verbose=True)

Placement using the “packing” method

pop_packing = axon_population()
pop_packing.set_geometry(center=center, radius=radius)
pop_packing.create_population_from_stat(n_ax=n_ax)
pop_packing.place_population(method="packing", delta=2, fit_to_size=True, n_iter=16000)
pop_packing.get_ppop_info(verbose=True)
Packing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:01:02

All in one using generate()

pop_fvf = axon_population()
pop_fvf.generate(center=center, radius=radius, n_ax=n_ax, delta_in=5)
pop_fvf.get_ppop_info(verbose=True)
Placing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:08

Plotting

def plot_pop(axes:plt.Axes, pop:axon_population, title:str):
    """
    Plot an axon population in `axes`
    """
    pop.plot(axes)
    axes.set_title(title)
    axes.set_aspect('equal', adjustable='box')
    axes.set_xlabel('Y-axis')
    axes.set_ylabel('Z-axis')

fig, axs = plt.subplots(2, 3, figsize=(15, 10))
plot_pop(axs[0, 0], pop_circle, "Circle - placer (delta=2)")
plot_pop(axs[0, 1], pop_ellipse, "Ellipse - placer (delta=2, n_iter=2000)")
plot_pop(axs[0, 2], pop_polygon, "Polygon - placer (delta_in=2, delta_trace=10)")
plot_pop(axs[1, 0], pop_data, "Circle - from data (direct y/z)")
plot_pop(axs[1, 1], pop_packing, "Circle - packing (fit_to_size=True, n_iter=17000)")
plot_pop(axs[1, 2], pop_fvf, "Circle - generate")

plt.show()
Circle - placer (delta=2), Ellipse - placer (delta=2, n_iter=2000), Polygon - placer (delta_in=2, delta_trace=10), Circle - from data (direct y/z), Circle - packing (fit_to_size=True, n_iter=17000), Circle - generate

Total running time of the script: (1 minutes 27.575 seconds)