MagPy Bioacoustics
Project description
MagPy
A Python bioacoustics analysis application.
Features
-
Sound Visualization
- Waveform display with amplitude vs. time
- Configurable spectrograms with multiple window functions (Blackman, Hamming, Hann, Kaiser, Rectangular, Triangular)
- Eight colormap options for spectrogram display
- Synchronized view navigation between waveform and spectrogram
-
Comprehensive Acoustic Measurements
- Time-domain: Begin/End Time, Duration, energy percentiles (5%, 25%, 50%, 75%, 95%)
- Frequency: Low/High Frequency, Bandwidth, Center Frequency, Peak Frequency
- Peak Frequency Contour tracking with slope analysis
- Power measurements: RMS, Peak, Average Power, Leq, SEL
- Entropy measurements for tonal vs. noise characterization
-
Selection and Annotation
- Time-frequency selection boxes
- Selection tables with customizable annotation columns
- Keyboard shortcuts for rapid annotation
- Export to tab-delimited format (TSV/CSV)
-
Audio Playback
- Play, pause, stop controls
- Variable playback speed (0.25x to 2x)
- Loop mode
- Position seeking
-
File Format Support
- Input: WAV, AIFF, FLAC, MP3
- Export: WAV, AIFF
- Selection tables: TSV, CSV
Installation
# Clone the repository
git clone https://github.com/jmcmeen/magpy.git
cd magpy
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install with dependencies
pip install -e ".[dev]"
Usage
GUI Application
# Launch the GUI
magpy-gui
# Open a file directly
magpy-gui recording.wav
Command Line
# Show version
magpy --version
# Compute spectrogram and save as image
magpy recording.wav --headless --compute-spectrogram output.png
# Compute measurements for selections
magpy recording.wav --headless --measure selections.txt
Python API
from magpy.core import AudioFile, SpectrogramGenerator, MeasurementCalculator
from magpy.core.measurements import SelectionBounds
# Load audio
audio = AudioFile("recording.wav")
print(f"Duration: {audio.duration:.2f}s")
print(f"Sample rate: {audio.sample_rate} Hz")
# Generate spectrogram
generator = SpectrogramGenerator()
result = generator.compute(audio.data, audio.sample_rate)
# Compute measurements for a selection
calc = MeasurementCalculator()
bounds = SelectionBounds(start_time=1.0, end_time=2.0, low_freq=500, high_freq=5000)
measurements = calc.compute_all(audio.data, audio.sample_rate, bounds)
print(f"Peak frequency: {measurements.frequency.peak_freq:.1f} Hz")
print(f"RMS amplitude: {measurements.amplitude.rms_amplitude:.4f}")
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=magpy
# Run only core tests
pytest tests/core/
# Run only UI tests (requires display)
pytest tests/ui/
Project Structure
magpy/
├── src/
│ └── magpy/
│ ├── core/ # Core analysis modules
│ │ ├── audio.py # Audio file handling
│ │ ├── spectrogram.py # Spectrogram generation
│ │ ├── measurements.py # Acoustic measurements
│ │ └── selection.py # Selection and annotation
│ ├── ui/ # User interface
│ │ ├── main_window.py # Main application window
│ │ └── widgets/ # Custom widgets
│ ├── app.py # GUI entry point
│ └── cli.py # CLI entry point
└── tests/
├── core/ # Core module tests
└── ui/ # UI tests
Dependencies
- Core: numpy, scipy, librosa, soundfile, pandas
- UI: PyQt6, pyqtgraph, matplotlib
- Audio: sounddevice
License
MIT License - see LICENSE file for details.
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
magpy_gui-0.1.1.tar.gz
(80.7 kB
view details)
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
magpy_gui-0.1.1-py3-none-any.whl
(70.4 kB
view details)
File details
Details for the file magpy_gui-0.1.1.tar.gz.
File metadata
- Download URL: magpy_gui-0.1.1.tar.gz
- Upload date:
- Size: 80.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4849d8516438fe87f430dee040abc4373bfcd7029545068badfaf63e0f2abfb7
|
|
| MD5 |
73d93a58d495ab6936448673bd3d2a90
|
|
| BLAKE2b-256 |
55dc655d0a366647e3942c680ccf5e503b66bd0ab19cfa154ab9b4e4d2db30a8
|
File details
Details for the file magpy_gui-0.1.1-py3-none-any.whl.
File metadata
- Download URL: magpy_gui-0.1.1-py3-none-any.whl
- Upload date:
- Size: 70.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1870e1bb84d8024ff087a9a3b4e725599da46706f2427a0bee98c86b8a2d2d8e
|
|
| MD5 |
2490677e107b097ee46eafc24407a7d1
|
|
| BLAKE2b-256 |
676f114e97e1509bed0a2877f599c1bb096c016d90134f67481f6f4c35cb25d5
|