scikit-maad developer on retainer: alpha_indices() receives dB spectrogram instead of linear power — acoustic entropy NaN for 60 % of recordings — 48 monitoring sites marked sensor malfunction — field teams dispatched unnecessarily — 4 weeks — scikit-maad developer on monthly retainer
maad 1.4.0 • Python 3.10; maad.features.alpha_indices() expects linear power Sxx; developer applies maad.sound.power2dB(Sxx) before calling alpha_indices(); negative dB values cause np.log(negative) = NaN in acoustic entropy; NaN propagates to all 20+ alpha indices • Southfield Maad Ltd. (ecoacoustics monitoring; 80 field sites; 2,000 recordings/month; 60% of recordings yield all-NaN biodiversity scores; 48 sites marked sensor malfunction; field teams dispatched; 4 weeks; fix: remove power2dB() before alpha_indices(); 2.0h retainer engagement)
Southfield Maad Ltd. built a passive acoustic monitoring service for conservation organisations, processing 2,000 soundscape recordings per month from 80 field monitoring sites distributed across protected wetlands and forest reserves. Each site recorded 25 one-minute WAV files per month during the dawn chorus window (05:00–07:00 local time), and the pipeline computed a full suite of alpha diversity indices — acoustic complexity index (ACI), acoustic entropy (Hf and Ht), normalised difference soundscape index (NDSI), bioacoustic index, and 15 additional indices — from each recording using scikit-maad (maad 1.4.0). Monthly biodiversity reports aggregated per-site index scores and flagged sites where indices fell below species-specific thresholds as requiring field investigation. After a pipeline refactor that added a visual spectrogram display layer, 48 of 80 monitoring sites began showing all-NaN biodiversity scores in the monthly report. The conservation operations team, seeing only NaN values with no other error messages, interpreted the data gap as sensor hardware failure and dispatched field technicians to inspect and replace passive acoustic monitoring units at 48 sites.
The refactor had introduced a single additional line: Sxx_dB = maad.sound.power2dB(Sxx) for use in a visual display function, followed by passing Sxx_dB (instead of the original Sxx) to maad.features.alpha_indices(Sxx_dB, tn, fn, extent). maad.sound.spectrogram(s, fs) returns Sxx as a 2-D numpy array of linear power values — all values non-negative by definition. maad.sound.power2dB(Sxx) converts to decibels via 10 * np.log10(Sxx); for frequency bins with very small power (quiet upper-frequency bands, silent nighttime intervals), this produces large negative dB values: 10 × log 10(10−10) = −100 dB. The resulting Sxx_dB array spans roughly −120 dB to 0 dBFS and contains many negative values. When alpha_indices() receives this dB array, its acoustic entropy computation normalises the spectrogram as a probability distribution — p = Sxx / Sxx.sum() — producing a mixture of negative and positive probability values, then computes -sum(p * np.log(p)). np.log() of a negative number returns nan with a RuntimeWarning: invalid value encountered in log. NumPy’s default warning filter prints this warning once per process lifetime and then suppresses it; the production server had already exhausted the warning quota from an unrelated upstream log step. NaN propagated silently through all 20+ alpha index calculations. For 60% of recordings — those with any frequency bin below 0 dBFS in Sxx_dB — every index in the returned DataFrame was NaN.
The annotated buggy and fixed pipeline, with spectrogram unit validation and NaN guards:
# Southfield Maad Ltd. — maad 1.4.0 dB vs linear power fix
# maad 1.4.0; Python 3.10
# Ecoacoustics monitoring; 80 field sites; 2,000 soundscape recordings/month
#
# Problem: maad.features.alpha_indices() expects linear power Sxx (non-negative)
# developer calls power2dB(Sxx) for visual display then passes Sxx_dB
# to alpha_indices(); negative dB values → p = Sxx_dB/Sxx_dB.sum()
# has negative entries → np.log(negative p) = NaN
# NaN propagates to all 20+ alpha index columns
# 60% of recordings yield all-NaN; 48 of 80 sites marked malfunction
# Fix: always pass linear power Sxx to feature extraction
# keep Sxx_dB only for display; add non-negative assertion guard
import numpy as np
import maad
# ── BUGGY pipeline ────────────────────────────────────────────────────────────
def compute_indices_buggy(wav_path: str) -> dict:
"""Compute alpha diversity indices — BUGGY: dB spectrogram passed to alpha_indices."""
s, fs = maad.sound.load(wav_path)
Sxx, tn, fn, extent = maad.sound.spectrogram(s, fs)
# Visual display: convert to dB for plotting
Sxx_dB = maad.sound.power2dB(Sxx)
# BUG: Sxx_dB passed to alpha_indices() instead of Sxx
# alpha_indices() expects linear power (non-negative)
# Sxx_dB contains large negative values for quiet bins
# → p = Sxx_dB / Sxx_dB.sum() has negative entries
# → np.log(negative) = NaN
# → all 20+ index columns are NaN for 60% of recordings
alpha_df, beta_df = maad.features.alpha_indices(Sxx_dB, tn, fn, extent)
return alpha_df.to_dict(orient='records')[0]
# ── FIXED pipeline ────────────────────────────────────────────────────────────
def compute_indices(wav_path: str) -> dict:
"""Compute alpha diversity indices — FIXED: linear Sxx to feature functions."""
s, fs = maad.sound.load(wav_path)
Sxx, tn, fn, extent = maad.sound.spectrogram(s, fs)
# Safety gate: assert Sxx is non-negative linear power before feature extraction
# Negative values indicate a dB-converted array was passed — log a diagnostic
if np.any(Sxx < 0):
raise ValueError(
f"[{wav_path}] Sxx contains negative values (min={Sxx.min():.4f}). "
"alpha_indices() expects linear power spectrogram from "
"maad.sound.spectrogram(), not dB output from maad.sound.power2dB(). "
"Check that no power2dB() call is applied between spectrogram() and "
"alpha_indices(). The dB array is for display only."
)
# FIX: pass linear power Sxx — not Sxx_dB — to all feature extraction functions
alpha_df, beta_df = maad.features.alpha_indices(Sxx, tn, fn, extent)
# NaN validation: any NaN in alpha indices indicates a programming error
nan_cols = alpha_df.columns[alpha_df.isnull().any()].tolist()
if nan_cols:
raise RuntimeError(
f"[{wav_path}] alpha_indices() returned NaN in columns: {nan_cols}. "
f"Input Sxx stats: min={Sxx.min():.2e}, max={Sxx.max():.2e}, "
f"zero_frac={np.mean(Sxx == 0):.3f}. "
"NaN in alpha indices typically means the input array contained "
"negative or zero values that broke the probability normalisation. "
"Verify that Sxx is the raw linear power output of spectrogram()."
)
# Keep Sxx_dB for display only — never pass it to feature extraction
Sxx_dB = maad.sound.power2dB(Sxx) # for plotting, not for feature computation
_ = Sxx_dB # used by visualisation layer only
return alpha_df.to_dict(orient='records')[0]
How passing a dB spectrogram to a function that requires linear power units, a silent RuntimeWarning quota exhausted by an upstream log step, and all-NaN index values that look identical to sensor hardware failure combine to produce four weeks of unnecessary field dispatches — and the correct scikit-maad spectrogram unit contract for all feature extraction functions
The core failure combines three factors. First, the scikit-maad API has a strict but undeclared precondition: all feature extraction functions (alpha_indices, beta_indices, shape_features, and others) expect the linear power spectrogram returned by maad.sound.spectrogram() directly, without dB conversion. The library provides maad.sound.power2dB() for display and visualisation purposes only; passing its output back into feature functions violates the linear power precondition and produces NaN silently. Second, NumPy’s default warning filter prints each unique warning type once per Python process lifetime and then suppresses it. The production pipeline had already triggered a RuntimeWarning: invalid value encountered in log from an earlier signal-processing step in the same process, exhausting the quota for that warning. The identical warning from alpha_indices() was silently swallowed. Third, an all-NaN alpha index row in the biodiversity report is visually indistinguishable from a sensor hardware failure — both produce missing data with no readable error message in the downstream report. The fix was a single-line change: alpha_df, beta_df = maad.features.alpha_indices(Sxx, tn, fn, extent) instead of alpha_indices(Sxx_dB, tn, fn, extent), plus a pre-call assertion assert np.all(Sxx >= 0) that would catch any future unit confusion immediately with a descriptive error. The NaN validation on the output DataFrame was added as a belt-and-suspenders check: if any index column is NaN after a valid non-negative Sxx input, that indicates an edge case in the maad algorithm for the specific recording (such as a completely silent file) rather than a unit error, and can be handled with a targeted diagnostic. The retainer engagement was 2.0h: 0.5h triage (add print(np.isnan(alpha_df).any(axis=1).sum()) to pipeline; 1,200 NaN recordings confirmed; compare Sxx vs Sxx_dB statistics; identify negative values in Sxx_dB); 0.5h root cause (alpha_indices() documentation confirms linear power requirement; refactor history shows Sxx_dB substituted for display feature; fix identified); 0.5h fix (remove power2dB() call before alpha_indices(); add non-negative assertion; add NaN validation; re-run pipeline on backlog of 1,200 affected recordings); 0.5h validation (100 recordings re-processed; zero NaN rows; ACI and Hf values in expected range for dawn chorus recordings; 2.0h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- librosa developer on retainer — librosa 0.10.1; Python 3.10; librosa.load() default sr=22050 resamples audio silently; feature vectors computed at wrong sample rate; model trained at 44100 Hz receives 22050 Hz features at inference; classification accuracy 0.61 not 0.84 — 2.0h
- birdnetlib developer on retainer — birdnetlib 0.9.0; Python 3.9; SQLAlchemy Column(Integer) calls int(0.73)=0 on confidence float INSERT; all detections stored with confidence=0; dashboard filter confidence >= 0.5 returns zero rows; app shows no birds detected; 3 weeks — 1.5h
- openSMILE developer on retainer — opensmile 2.5.0; Python 3.10; ComParE_2016 Functionals returns (0, 6373) DataFrame for sub-500ms files; np.vstack() raises ValueError on mixed (1,6373)+(0,6373) shapes; model trained on 80% of data; F1 0.73 not 0.81; 4 weeks — 2.0h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →