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.

Overview#

nngt.geometry.Shape alias of nngt.geometry.backup_shape.BackupShape
nngt.geometry.culture_from_file(*args, **kwargs)
nngt.geometry.plot_shape(shape[, axis, m, …]) Plot a shape (set the axis aspect to 1 to respect the proportions).
nngt.geometry.pop_largest(shapes) Returns the largest shape, removing it from the list.
nngt.geometry.shapes_from_file(*args, **kwargs)

Principle#

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.

Examples

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 nc


fig, ax = plt.subplots()

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

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

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

plt.show()

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 nc


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

shapes = nc.shapes_from_file(culture_file, min_x=-5000., max_x=5000.)

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

for p in shapes:
    nc.plot_shape(p, ax, show=False)

plt.show()

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

culture = nc.culture_from_file(culture_file, min_x=-5000., max_x=5000.)

nc.plot_shape(culture, ax2)

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

culture_bis = nc.culture_from_file(culture_file, min_x=-5000., max_x=5000.)
pos = culture_bis.seed_neurons(neurons=1000, xmax=0)

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

plt.show()

Content#

nngt.geometry.Shape#

alias of nngt.geometry.backup_shape.BackupShape

nngt.geometry.culture_from_file(*args, **kwargs)[source]#
nngt.geometry.pop_largest(shapes)[source]#

Returns the largest shape, removing it from the list. If shapes is a shapely.geometry.MultiPolygon, returns the largest shapely.geometry.Polygon without modifying the object.

New in version 0.3.

Parameters:shapes (list of Shape objects or MultiPolygon.)
nngt.geometry.shapes_from_file(*args, **kwargs)[source]#
nngt.geometry.plot_shape(shape, axis=None, m='', mc='#999999', fc='#8888ff', ec='#444444', alpha=0.5, brightness='height', show=True, **kwargs)[source]#

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

Parameters:
  • 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.
  • brightness (str, optional (default: height)) – Show how different other areas are from the ‘default_area’ (lower values are darker, higher values are lighter). Difference can concern the ‘height’, or any of the properties of the Area objects.
  • kwargs (keywords arguments for matplotlib.patches.PathPatch)