You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spectrogram plotter for annotated audio files. Takes a single audio file + CSV annotations and creates a multi-row spectrogram grid, grouping by any column(s) in the CSV and showing all annotations with frequency boxes.
Quick Start
# Basic usage - group by individual and age, sorted by age
python3 sp.py ZF.wav --csv ZFVocalizations.csv --group-by individual,age --sort-by age
# Output to specific file
python3 sp.py ZF.wav --csv annotations.csv --group-by individual,age -o my_plot.png
Example Files Used
The script was developed and tested with:
Audio: ZF.wav - Zebra finch vocalizations (~820 seconds of audio at 44.1kHz)
Annotations: ZFVocalizations.csv - CSV with columns:
onset, offset - time in seconds
minFrequency, maxFrequency - frequency bounds in Hz
individual - bird ID (e.g., R3277, R3406)
age - days post-hatch (e.g., 38, 99, 108)
category - Adults/Juveniles
clustername - vocalization type (e.g., "call")
Parameters
Grouping & Sorting
Parameter
Default
Description
--group-by
None
Column(s) to group by, comma-separated (e.g., individual,age)
--sort-by
None
Column to sort groups by (e.g., age, onset, individual)
--sort-desc
False
Sort descending instead of ascending
--label-format
Auto
Custom label format (e.g., "{individual} - {age} days")
CSV Column Names
Parameter
Default
Description
--onset-col
onset
Column name for onset time (seconds)
--offset-col
offset
Column name for offset time (seconds)
--min-freq-col
minFrequency
Column name for minimum frequency (Hz)
--max-freq-col
maxFrequency
Column name for maximum frequency (Hz)
--filename-col
filename
Column name for audio filename
Time & Display
Parameter
Default
Description
--max-duration
2.0
Maximum duration per row (seconds)
--padding
0.1
Padding around annotations (seconds)
Spectrogram
Parameter
Default
Description
--n-fft
512
FFT window size
--hop-length
64
Hop length for STFT
--target-sr
None
Resample to this sample rate
--fmin
0.0
Minimum frequency (Hz)
--fmax
None
Maximum frequency (Hz), defaults to 20kHz or Nyquist
--db-floor
-80.0
dB floor for colormap
--db-ceil
0.0
dB ceiling for colormap
Annotation Display
Parameter
Default
Description
--no-boxes
False
Hide frequency boxes
--box-color
white
Frequency box color
--box-linewidth
0.5
Box line width
--box-linestyle
--
Box line style
--no-highlight
False
Hide highlight bars above annotations
--highlight-color
green
Highlight bar color
--highlight-linewidth
3.0
Highlight line width
--show-vlines
False
Show vertical lines at onset/offset
--vline-color
white
Vertical line color
Titles
Parameter
Default
Description
--no-titles
False
Hide row titles
--title-color
white
Title text color
--title-bg
black
Title background color
--title-fontsize
11
Title font size
Figure
Parameter
Default
Description
--row-height
2.5
Height per row (inches)
--fig-width
12.0
Figure width (inches)
--scalebar-sec
0.5
Scale bar length (seconds), 0 to hide
--scalebar-pos
right
Scale bar position (left or right)
--no-colorbar
False
Hide colorbar
Style
Parameter
Default
Description
--cmap
CET_L20
Colormap (matplotlib, colorcet, or cmocean)
--gap-color
white
Background color
Output
Parameter
Default
Description
--output, -o
Auto
Output file path
--format
png
Output format (png, svg, pdf)
--dpi
150
Output DPI
--transparent
False
Transparent background
Usage Examples
Group by individual + age (zebra finch style)
python3 sp.py ZF.wav --csv ZFVocalizations.csv \
--group-by individual,age --sort-by age
Output: Rows labeled "R3277 (99 dph)", "R3280 (38 dph)", etc.