Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Simulating fish swarming behavior with the model by Iain Couzin et al.

Project description

Simulate fish swarming behavior with the model by Iain Couzin et al. Use with caution as I can’t seem to replicate some behavior (e.g. the torus swarming).


from couzinswarm import Swarm

swarm = Swarm()
r, v = swarm.simulate(1000)


pip install couzinswarm

Elaborate example

import numpy as np
import matplotlib.pyplot as pl
from mpl_toolkits.mplot3d import Axes3D
from couzinswarm import Swarm

# note: the dimension of space is measure in fish length,
# such that r = 1 means a length of one fish

swarm = Swarm(
             # this angle is given in radians
             # up to np.pi (not 360 degrees as in
             # the paper)
             # radians per unit of time
             # fish lengths per unit of time
             # in units of fish length
             # geometry of box
             # boundary conditions
             reflect_at_boundary = [True, True, True],

fig = pl.figure()
ax = fig.add_subplot(111, projection='3d')

N_t = 1000

t = np.arange(N_t+1)

# Note that r.shape = v.shape = ( N_fish, N_t+1, 3 )
positions, directions = swarm.simulate(N_t)
r, v = positions, directions

for i in range(swarm.number_of_fish):
    ax.plot(r[i,:,0], r[i,:,1], r[i,:,2])

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for couzinswarm, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size couzinswarm-0.0.3.tar.gz (7.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page