High-performance Python implementation of ARTwarp for bioacoustic signal categorization
Project description
ARTwarp-py
A high-performance Python implementation of ARTwarp for automated categorization of tonal animal sounds.
Overview
ARTwarp-py is a complete rewrite of the original MATLAB ARTwarp software, combining Dynamic Time Warping (DTW) for contour similarity with an Adaptive Resonance Theory (ART) neural network for unsupervised clustering, with performance improvements while staying mathematically equivalent to the original algorithm.
Contents
- Features
- Installation
- Quick Start
- Documentation
- Architecture
- Algorithm Details
- MATLAB Compatibility
- Testing
- Citation
- License & Authors
Features
| Area | Description |
|---|---|
| Performance | Optimized algorithms using NumPy, with optional Numba JIT compilation |
| Input formats | .ctr (MATLAB), .csv, .txt; load MATLAB categorization (.mat) via load_mat_categorization() |
| Visualization | Publication-worthy plots and reports |
| CLI | Command-line interface for training, plotting, and batch workflows |
| Quality | Type hints, tests, coverage, and documentation |
| Future | Parallel processing and batch pipelines (TODO) |
Installation
Requirements: Python 3.8+, NumPy ≥1.20, SciPy ≥1.7, pandas ≥1.3, matplotlib ≥3.4, and optionally Numba ≥0.54 for JIT.
> pip install -e .
For environment setup and virtualenv details, see user/INSTALLATION.md (end-user) and dev/ENVIRONMENT_SETUP.md (developers) within docs/.
Quick Start
See docs/user/QUICK_REFERENCE.md for a condensed cheat sheet.
Command line
Activate your virtual environment first (e.g. source venv/bin/activate or, in Fish, source venv/bin/activate.fish), then:
Interactive launcher (configure all options via prompts):
> ./run.sh
This opens a menu for Train, Plot, Predict, or Export, then prompts for every parameter (paths, vigilance, learning rate, resampling, etc.) with defaults and validation. You can also call the CLI directly through the script: ./run.sh train -i ./contours -o results.pkl.
Basic commands:
# train on a directory of contour files
> artwarp-py train --input-dir ./contours --output results.pkl \
--vigilance 85 --learning-rate 0.1 --max-iterations 50
# export reference contours and category assignments
> artwarp-py train --input-dir ./contours --output results.pkl --export-refs --export-categories
Resample with sample interval (seconds) [default = 0.02s]:
# resample contours to uniform temporal resolution (like MATLAB resample option)
> artwarp-py train --input-dir ./contours --output results.pkl --resample --sample-interval 0.02
Altogether (resampling & exporting reference contours / category assignments):
# full command
> artwarp-py train --input-dir ./contours --output results.pkl --resample --sample-interval 0.02 --vigilance 85 --learning-rate 0.1 --max-iterations 50 --export-refs --export-categories
Gener visualizations:
# generate visualizations from Pickle (.pkl) file
> artwarp-py plot --results results.pkl --input-dir ./contours --output-dir ./report
Python API
from artwarp import ARTwarp, load_contours
# load contour data
contours, names = load_contours('path/to/contour/directory', file_format='csv')
# init network
network = ARTwarp(
vigilance=85.0,
learning_rate=0.1,
bias=0.0,
max_categories=50,
max_iterations=50,
warp_factor_level=3
)
# train
results = network.fit(contours, contour_names=names)
# get category assignments
categories = results.categories
reference_contours = results.weight_matrix
# visualize results
from artwarp.visualization import plot_training_summary
plot_training_summary(results)
Documentation
| Document | Description |
|---|---|
| docs/user/QUICK_REFERENCE.md | (User Guide) Short reference for CLI and common tasks |
| docs/user/INSTALLATION.md | (User Guide) Install and environment setup |
| docs/user/API.md | (User Guide) Public API (loaders, exporters, options) |
| docs/user/ARCHITECTURE.md | (User Guide) Code layout and design |
| docs/user/VISUALIZATION.md | (User Guide) Plotting and report generation |
| CHANGELOG.md | Version history |
| docs/README.md | Docs index and overview |
| docs/dev/ENVIRONMENT_SETUP.md | (Developers) Detailed environment and tooling |
| docs/dev/PROJECT_SUMMARY.md | (Developers) Project summary and goals |
| docs/dev/PERFORMANCE_OPTIMIZATIONS.md | (Developers) Performance notes and benchmarks |
| docs/dev/TEST_RESULTS.md | (Developers) CI, test matrix, and coverage |
Architecture
artwarp/
├── core/
│ ├── dtw.py # Dynamic Time Warping
│ ├── art.py # ART neural network
│ ├── network.py # Main ARTwarp algorithm
│ └── weights.py # Weight update and management
├── io/
│ ├── loaders.py # Data loading (.ctr, .csv, .txt, .mat)
│ └── exporters.py # Results export
├── visualization/
│ └── plotting.py # Plotting and reports
├── utils/
│ ├── validation.py # Input validation
│ ├── resample.py # Contour resampling (MATLAB-aligned)
│ └── numba_check.py # Numba availability + optional install prompt
└── cli/
└── main.py # Command-line interface
Algorithm Details
Dynamic Time Warping
- Optimized DP with Itakura parallelogram constraints
- Vectorized similarity matrix and efficient path backtracing
- Optional Numba JIT for speed
ART neural network
- Bottom-up activation (similarity-based) and top-down matching (vigilance)
- Dynamic category creation and incremental weight updates
MATLAB compatibility
- Load MATLAB results:
from artwarp.io import load_mat_categorization
data = load_mat_categorization("ARTwarp85FINAL.mat")
→weight_matrix,num_categories, and optionallycontours/categories/contour_names. - Export for MATLAB: Use
one_based_categories=Trueorone_based_filenames=True(see API.md).
Testing
Run the test suite (use the venv’s Python so dependencies are found):
> python -m pytest tests/ -v
With coverage (CI requires ≥80%):
> python -m pytest tests/ --cov=artwarp --cov-report=html --cov-fail-under=80
CI: GitHub Actions runs tests (Python 3.9–3.12), coverage gate, and lint (Black, isort, Flake8, Mypy). See docs/dev/TEST_RESULTS.md for details.
Citation
If you use this software in your research, please cite:
- This implementation: [DOI to be assigned]
- Buck, J. R. & Tyack, P. L. (1993). A quantitative measure of similarity for Tursiops truncatus signature whistles. J. Acoust. Soc. Am. 94, 2497–2506. https://doi.org/10.1121/1.407385
- Deecke, V. B., Ford, J. K. B. & Spong, P. (1999). Quantifying complex patterns of bioacoustic variation: Use of a neural network to compare killer whale (Orcinus orca) dialects. J. Acoust. Soc. Am. 105, 2499–2507. https://doi.org/10.1121/1.426853
- Deecke, V. B. & Janik, V. M. (2006). Automated categorization of bioacoustic signals: Avoiding perceptual pitfalls. J. Acoust. Soc. Am. 119, 645–653. https://doi.org/10.1121/1.2139067
License & Authors
ARTwarp is distributed under the GNU Lesser General Public License v3. See LICENSE or https://www.gnu.org/licenses/lgpl.
- Python implementation: Pedro Gronda Garrigues (2026)
- Original MATLAB: Volker Deecke & Vincent Janik (2006)
- Original MATLAB repo: https://github.com/dolphin-acoustics-vip/artwarp
ARTwarp is distributed under the terms of the GNU Lesser General Public License, version 3, as published by the Free Software Foundation. For details, please refer to the LICENSE file in the root directory of the ARTwarp distribution or see https://www.gnu.org/licenses/lgpl.
Original MATLAB Implementation
This is a complete rewrite of the original ARTwarp MATLAB software available at: https://github.com/dolphin-acoustics-vip/artwarp
Publishing (PyPI/pip): Python packaging tutorial · Stack Overflow: publishing to PyPI
The following are steps (specific to @PedroGGBM) to upload the PyPI package:
# to generate distribution archives (build/)
> conda activate sig-process # or your corresponding venv (e.g., conda, venv, uv, etc)
> cd <base_directory>
> python -m pip install --upgrade setuptools wheel build # ensure latest version of PyPA's build installed
> python -m build
# to upload distribution archive
> python -m pip install --upgrade twine
> python -m twine upload --repository testpypi dist/* # this is to test it
> python -m pip install --index-url https://test.pypi.org/simple/ --no-deps example-package-YOUR-USERNAME-HERE # to test install on test server for PyPI
### !!! Once registered in PyPI and own official API key
> python -m twine upload dist/* # this is to upload it
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file artwarp_py-1.0.0.tar.gz.
File metadata
- Download URL: artwarp_py-1.0.0.tar.gz
- Upload date:
- Size: 74.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04f82197ca7b0b90e22a713bd7fd1e15ccc3dba779b19f33495a4483c14cdd27
|
|
| MD5 |
808189639da3b01817ec0ef3a4bd5207
|
|
| BLAKE2b-256 |
d2d77fa941eea63265fc03ffba175e1d597cff31209fd86c4026b46239acb5dc
|
File details
Details for the file artwarp_py-1.0.0-py3-none-any.whl.
File metadata
- Download URL: artwarp_py-1.0.0-py3-none-any.whl
- Upload date:
- Size: 53.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
496592484ede384242e1f7a56e1c41fa49a030ad3442c80342a42d52b4889a72
|
|
| MD5 |
4fa50849c200a047db883e5379c58121
|
|
| BLAKE2b-256 |
794b1d4854ddb65d37a59501ced37d4ce230009a1236a2be9b143034363eedc8
|