Skip to main content

3D Idealized Couzin Model Fish Schooling Simulator with Oceanic Entropy Metrics

Project description

dewi-kadita: A Python Library for 3D Idealized Couzin Model Fish Schooling Simulation

Python 3.8+ PyPI version License: MIT Code style: black DOI

NumPy SciPy Matplotlib Pandas netCDF4 Numba Pillow tqdm

Named after Kanjeng Ratu Kidul, the legendary Queen of the Southern Sea in Javanese mythology

A Python library for simulating fish schooling behavior using the 3D Couzin model with Numba JIT acceleration and comprehensive oceanic entropy metrics designed specifically for marine collective motion analysis.

Animation

Model

The Couzin model (2002) describes collective animal motion through three concentric behavioral zones around each individual:

Zone-Based Behavior

Each fish $i$ responds to neighbors based on their distance:

Zone of Repulsion (ZOR) — radius $r_r$: Collision avoidance takes priority $$\mathbf{d}i^{(r)} = -\sum{j \in ZOR} \frac{\mathbf{r}{ij}}{|\mathbf{r}{ij}|}$$

Zone of Orientation (ZOO) — radius $r_o > r_r$: Align with neighbors' headings $$\mathbf{d}i^{(o)} = \sum{j \in ZOO} \hat{\mathbf{v}}_j$$

Zone of Attraction (ZOA) — radius $r_a > r_o$: Move toward distant neighbors $$\mathbf{d}i^{(a)} = \sum{j \in ZOA} \frac{\mathbf{r}{ij}}{|\mathbf{r}{ij}|}$$

Update Rules

The desired direction combines zone responses with priority to repulsion:

$$\mathbf{d}_i = \begin{cases} \mathbf{d}_i^{(r)} & \text{if } |\mathbf{d}_i^{(r)}| > 0 \ \mathbf{d}_i^{(o)} + \mathbf{d}_i^{(a)} & \text{otherwise} \end{cases}$$

Velocity updates with angular noise and turning rate constraint $\theta_{max}$:

$$\mathbf{v}_i(t + \Delta t) = v_0 \cdot \text{rotate}(\hat{\mathbf{v}}_i, \mathbf{d}i, \theta{max}, \sigma)$$

Position updates with periodic boundaries:

$$\mathbf{r}_i(t + \Delta t) = \mathbf{r}_i(t) + \mathbf{v}_i(t + \Delta t) \cdot \Delta t$$

Key Parameters

Parameter Symbol Description Typical Range
N $N$ Number of fish 50-1000
L $L$ Tank/ocean volume size 10-100
v0 $v_0$ Swimming speed 0.5-3.0
r_r $r_r$ Repulsion zone radius 0.5-2.0
r_o $r_o$ Orientation zone radius 2.0-10.0
r_a $r_a$ Attraction zone radius 5.0-20.0
θ_max $\theta_{max}$ Maximum turning angle 0.1-0.8 rad
σ $\sigma$ Angular noise 0.0-0.5 rad
blind_angle $\alpha$ Rear blind angle 0-90°

Collective States

The Couzin model produces four distinct collective states:

State Description Characteristics
Swarm Disordered aggregation Low polarization, high density
Torus Rotating mill Circular motion, medium polarization
Dynamic Parallel Aligned but fluctuating High polarization, direction changes
Highly Parallel Stable aligned motion Very high polarization, stable direction

Order Parameters

Polarization (alignment measure): $$P = \frac{1}{N} \left| \sum_{i=1}^{N} \hat{\mathbf{v}}_i \right|$$

Rotation (milling measure): $$M = \frac{1}{N} \left| \sum_{i=1}^{N} \hat{\mathbf{v}}_i \times \hat{\mathbf{r}}_i^c \right|$$

where $\hat{\mathbf{r}}_i^c$ is the unit vector from fish $i$ to the group centroid.

Oceanic Entropy Metrics

This library implements specialized information-theoretic measures designed for marine collective behavior:

Metric Description Ecological Relevance
School Cohesion Entropy Nearest-neighbor distance distribution Predator defense efficiency
Polarization Entropy Angular distribution of headings Migration coordination
Depth Stratification Entropy Vertical position distribution Thermocline tracking
Angular Momentum Entropy Rotation state distribution Milling behavior detection
Nearest Neighbor Entropy k-NN distance variability Social network structure
Velocity Correlation Entropy Spatial velocity autocorrelation Information transfer
School Shape Entropy Principal component ratios Morphological adaptation
Oceanic Schooling Index Composite weighted metric Overall school health

Oceanic Schooling Index (OSI)

The composite metric specifically designed for fish school analysis:

$$\text{OSI} = w_1 H_{cohesion} + w_2 H_{polar} + w_3 H_{depth} + w_4 H_{angular} + w_5 H_{nn} + w_6 (1 - H_{vel}) + w_7 H_{shape}$$

where weights are optimized for marine schooling behavior assessment.

Installation

From PyPI:

pip install dewi-kadita

From source:

git clone https://github.com/sandyherho/dewi-kadita.git
cd dewi-kadita
pip install .

Development installation with Poetry:

git clone https://github.com/sandyherho/dewi-kadita.git
cd dewi-kadita
poetry install

Quick Start

CLI:

dewi-kadita case1          # Run swarm phase scenario
dewi-kadita case2          # Run torus/milling scenario
dewi-kadita case3          # Run dynamic parallel scenario
dewi-kadita case4          # Run highly parallel scenario
dewi-kadita --all          # Run all test cases
dewi-kadita case1 --no-entropy  # Skip entropy computation

Python API:

from dewi_kadita import CouzinSystem, CouzinSolver
from dewi_kadita import compute_metrics_timeseries

# Create system with 150 fish
system = CouzinSystem(
    n_fish=150,
    box_size=25.0,
    speed=1.0,
    r_repulsion=1.0,
    r_orientation=5.0,
    r_attraction=10.0,
    max_turn=0.3,
    noise=0.1,
    blind_angle=30.0
)

# Initialize solver with Numba acceleration
solver = CouzinSolver(dt=0.1, use_numba=True)

# Run simulation for 1000 steps
result = solver.solve(system, n_steps=1000)

# Compute oceanic entropy metrics
metrics = compute_metrics_timeseries(
    result['positions'],
    result['velocities'],
    result['time'],
    system.box_size
)

print(f"Final polarization: {result['final_polarization']:.4f}")
print(f"Final rotation: {result['final_rotation']:.4f}")
print(f"Final OSI: {metrics['oceanic_schooling_index_final']:.4f}")

Features

  • High-performance: Numba JIT compilation for 10-100x speedup
  • 3D simulation: Full three-dimensional fish schooling dynamics
  • Couzin zones: Proper implementation of repulsion, orientation, attraction zones
  • Blind angle: Realistic rear visual field limitation
  • Maximum turning rate: Biologically realistic angular velocity constraint
  • Oceanic entropy metrics: Specialized measures for marine collective behavior
  • Multiple output formats: CSV, NetCDF (CF-compliant), PNG, GIF
  • Stunning oceanic visualization: Deep sea aesthetic with bioluminescent effects
  • Configurable scenarios: Text-based configuration files

Output Files

The library generates:

  • CSV files:
    • *_order_parameters.csv - Polarization and rotation time series
    • *_entropy_timeseries.csv - All oceanic entropy measures over time
    • *_entropy_summary.csv - Statistics (mean, std, min, max, final)
    • *_final_state.csv - Final fish positions and velocities
  • NetCDF: Full trajectory data with all metrics and CF-compliant metadata
  • PNG: Static summary plots with oceanic entropy visualization
  • GIF: Animated 3D visualization with underwater aesthetic

Dependencies

  • numpy >= 1.20.0
  • scipy >= 1.7.0
  • matplotlib >= 3.3.0
  • pandas >= 1.3.0
  • netCDF4 >= 1.5.0
  • numba >= 0.53.0
  • Pillow >= 8.0.0
  • tqdm >= 4.60.0

License

MIT 2026 © Sandy H. S. Herho, Iwan P. Anwar, Faruq Khadami, Alfita P. Handayani, Karina A. Sujatmiko, Kamaluddin Kasim, Rusmawan Suwarman, and Dasapta E. Irawan

Citation

@software{herhoEtAl2026_dewi_kadita,
  title   = {{\texttt{dewi-kadita}: A Python library for 3D idealized Couzin model fish schooling simulation}},
  author  = {Herho, Sandy H. S. and Anwar, Iwan P. and Khadami, Faruq and Handayani, Alfita P. and Sujatmiko, Karina A. and Kasim, Kamaluddin and Suwarman, Rusmawan and Irawan, Dasapta E.},
  year    = {2026},
  url     = {https://github.com/sandyherho/dewi-kadita}
}

Project details


Download files

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

Source Distribution

dewi_kadita-0.0.4.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dewi_kadita-0.0.4-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file dewi_kadita-0.0.4.tar.gz.

File metadata

  • Download URL: dewi_kadita-0.0.4.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.2 Linux/6.11.9-100.fc39.x86_64

File hashes

Hashes for dewi_kadita-0.0.4.tar.gz
Algorithm Hash digest
SHA256 a1b765e03881f204a008a7b441484fb72598bd91e32651a0327c53f1313ab530
MD5 ff6a5c0cc573f256a1a63f4753af89b7
BLAKE2b-256 7e4b1958f579aa929525a6d47c619c38fdafcc206392ce171ca75d8c18e2b54a

See more details on using hashes here.

File details

Details for the file dewi_kadita-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: dewi_kadita-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.2 Linux/6.11.9-100.fc39.x86_64

File hashes

Hashes for dewi_kadita-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f4009ae02b54ae57e5c4c0d254c31056ef1624ffe488e3342520be18b66f7c3f
MD5 315359e30b945d1519ea8cddc76da7af
BLAKE2b-256 e2c98c949e2be588087809297d409816b7167c4c4ccbe27215548d4ed2de482a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page