Geometry module

This module is a direct copy of the SENeC package PyNCulture. Therefore, in the examples below, you will have to import nngt instead of PyNCulture and replace pnc by nngt.geometry.


nngt.geometry.Shape alias of BackupShape
nngt.geometry.culture_from_file(filename[, ...]) Generate a culture from an SVG or DXF file.
nngt.geometry.plot_shape(shape[, axis, m, ...]) Plot a shape (set the axis aspect to 1 to respect the proportions).


Module dedicated to the description of the spatial boundaries of neuronal cultures. This allows for the generation of neuronal networks that are embedded in space.

The shapely library is used to generate and deal with the spatial environment of the neurons.


Basic features

The module provides a backup Shape object, which can be used with only the numpy and scipy libraries. It allows for the generation of simple rectangle, disk and ellipse shapes.

import matplotlib.pyplot as plt

import PyNCulture as pnc

fig, ax = plt.subplots()

''' Choose a shape (uncomment the desired line) '''
culture = pnc.Shape.rectangle(15, 20, (5, 0))
# culture = pnc.Shape.disk(20, (5, 0))
# culture = pnc.Shape.ellipse((20, 5), (5, 0))

''' Generate the neurons inside '''
pos = culture.seed_neurons(neurons=1000, xmax=0., ymax=0.)

''' Plot '''
pnc.plot_shape(culture, ax)
ax.scatter(pos[:, 0], pos[:, 1], s=2, zorder=2)

All these features are of course still available with the more advanced Shape object which inherits from shapely.geometry.Polygon.

Complex shapes from files

import matplotlib.pyplot as plt

import PyNCulture as pnc

''' Choose a file '''
culture_file = "culture_from_filled_polygons.svg"
# culture_file = "culture_with_holes.svg"
# culture_file = "culture.dxf"

shapes = None

if culture_file.endswith(".dxf"):
    shapes = pnc.shapes_from_dxf(culture_file)
    shapes = pnc.shapes_from_svg(culture_file)

''' Plot the shapes '''
fig, ax = plt.subplots()

for shape in shapes:
    pnc.plot_shape(shape, ax)

''' Make a culture '''
fig2, ax2 = plt.subplots()

culture = pnc.culture_from_file(culture_file)

pnc.plot_shape(culture, ax2)

''' Add neurons '''
fig3, ax3 = plt.subplots()
plt.title("culture with neurons")

culture_bis = pnc.culture_from_file(culture_file)
pos = culture_bis.seed_neurons(neurons=1000, xmax=0)

pnc.plot_shape(culture_bis, ax3)
ax3.scatter(pos[:, 0], pos[:, 1], s=2, zorder=3)



alias of BackupShape

nngt.geometry.plot_shape(shape, axis=None, m='', mc='#999999', fc='#8888ff', ec='#444444', alpha=0.5, **kwargs)[source]

Plot a shape (set the axis aspect to 1 to respect the proportions).

  • shape (Shape) – Shape to plot.
  • axis (matplotlib.axes.Axes instance, optional (default: None)) – Axis on which the shape should be plotted. By default, a new figure is created.
  • m (str, optional (default: invisible)) – Marker to plot the shape’s vertices, matplotlib syntax.
  • mc (str, optional (default: “#999999”)) – Color of the markers.
  • fc (str, optional (default: “#8888ff”)) – Color of the shape’s interior.
  • ec (str, optional (default: “#444444”)) – Color of the shape’s edges.
  • alpha (float, optional (default: 0.5)) – Opacity of the shape’s interior.
  • kwargs (keywords arguments for matplotlib.patches.PathPatch)