courseshub.world · Ecoacoustics · Module 12 — Interactive

Python Laboratory

Four interactive labs running entirely in your browser via Pyodide — no installation, no server, no Python required on your machine.

ecoacoustics — Pyodide REPLimport numpy as npfrom scipy.signal import spectrogramf, t, Sxx = spectrogram(audio, fs=44100)# Acoustic Complexity Indexaci = sum(abs(diff(Sxx, axis=1)) / sum(Sxx, axis=1))>>> ACI = 0.847>>> Pyodide 0.25.1 · NumPy · SciPy · Matplotlib ready

The Python lab section runs entirely in your browser using Pyodide(Python 3.11 compiled to WebAssembly). NumPy, SciPy and Matplotlib are available out of the box; you can modify the code, re-run it, and see plots immediately. The status indicator below shows when the runtime is ready — usually a few seconds on first load, then cached for subsequent visits.

Loading Pyodide + NumPy + SciPy + Matplotlib…
Experiment 1 — Acoustic Complexity Index (ACI)Signal Processing
Simulate a spectrogram with biotic and abiotic components, compute ACI, and visualise how index values respond to signal complexity. Modify n_species or noise_level to explore.
Try: change n_species or noise_level
Experiment 2 — Dawn Acoustic Duct & Active SpaceAtmospheric Acoustics
Model sound propagation at dawn (temperature inversion → acoustic duct) vs midday. Compute and plot active space radius as a function of ambient noise.
Try: change source_dB or the inversion gradient
Experiment 3 — Dawn Chorus Species Sequence & Niche OverlapCommunity Ecology
Model staggered species onset times, their spectral niches, and compute pairwise acoustic niche overlap O_ij. Visualise community structure.
Try: shift onset times or f_center values
Experiment 4 — Optimal Transport & Acoustic Restoration (W₂)Mathematical Physics
Compute the Wasserstein-2 distance between degraded and reference acoustic spectral distributions. Model the restoration trajectory and entropy production rate.
Direct connection to Villani T₂ / HWI framework

The four labs at a glance

Lab 1 — Spectrogram of a synthesised dawn chorus

Build a multi-species chorus by adding sinusoids of different frequencies and time envelopes, compute its short-time Fourier transform, and visualise the resulting spectrogram. Compare it to a real bird recording (provided as a small embedded WAV). The lab introduces SciPy's scipy.signal.spectrogramand the trade-off between time and frequency resolution governed by the window length.

Lab 2 — Acoustic indices from scratch

Implement the ACI (Acoustic Complexity Index), BI (Bioacoustic Index) and NDSI (Normalised Difference Soundscape Index) directly from their definitions in NumPy. Apply them to a set of test spectrograms with known soundscape composition and verify that the indices respond as expected. This lab is a good entry point to the technical literature on soundscape ecology.

Lab 3 — Niche-partitioning model

Simulate N species as bivariate Gaussian distributions in frequency-time space; compute pairwise acoustic-niche overlaps Oij; and investigate how community-level overlap evolves under a Lotka-Volterra-like competition dynamic where high-overlap pairs penalise each other. Plot the resulting partition and verify Krause's prediction of evolved non-overlap.

Lab 4 — Optimal-transport restoration

Take a degraded soundscape and a healthy reference; compute the W2 Wasserstein distance between their spectral measures; and find the optimal transport plan that maps one onto the other. This is the mathematical content of Module 11 made concrete with the POT (Python Optimal Transport) library. The lab illustrates how acoustic restoration can be quantified, not just described.

What you need

  • A modern browser (Chrome, Firefox, Safari, Edge — Pyodide works on all four).
  • ~100 MB of free memory for the Pyodide runtime.
  • ~30 s of patience for Pyodide's first download — the runtime is cached for subsequent visits.
Tip
Labs are independent: you can jump straight to Lab 4 if you have the prerequisites, or work through them in order to build up the workflow. All four labs persist their cell state in browser local storage, so you can leave and come back without losing work.
Share:XRedditLinkedIn