makelab: fix plotting bugs, prune dead code, add docs + audio tests#11
Merged
Conversation
Review/cleanup of the makelab helper library (scoped to the .py files; notebooks untouched). Correctness: - plot_audio now passes its computed bit-depth title to plot_signal (previously discarded, so the title never appeared) - plot_spectrogram default title: duration is len(s)/sampling_rate, not len(s)*sampling_rate - == None -> is None in plot_signal/plot_spectrogram - set_xticks() before set_xticklabels() everywhere to avoid the matplotlib FixedFormatter warning students would otherwise see - convert_to_mono uses mean(axis=1) (correct for any channel count, not just stereo) Cleanup: - drop unused scipy/librosa/distance imports; the scipy.signal import was shadowed by local `signal` vars - de-duplicate map/remap (map is now a thin alias of remap) - remove dead last_zero_crossing_idx var; simplify the min_gap guard - hoist matplotlib.ticker import to the top Pedagogy: - standardize docstrings with Parameters/Returns; fix stale comments - add pointers to library equivalents (numpy.interp, scipy.ndimage.shift, librosa.zero_crossings, librosa.to_mono) noting behavioral differences - add Tutorials/makelab/README.md documenting the package + public API Tests: - add tests/test_makelab_audio.py (incl. a >2-channel case that guards the convert_to_mono fix) Verified: pytest tests/ (29 passed); Agg render smoke of all plot helpers with warnings-as-errors (clean); nbmake on the three signals notebooks (3 passed). Notebook-side follow-up tracked in #10. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Review and cleanup of the
makelabhelper library behind the signals tutorials. Scoped deliberately to the.pyfiles — no notebooks were changed.Correctness fixes
plot_audionow passes its computed bit-depth title through toplot_signal(it was building the title then discarding it, so the"{bits}-bit, {rate} Hz audio"title never appeared).plot_spectrogramdefault title: duration islen(s) / sampling_rate, notlen(s) * sampling_rate.== None→is Noneinplot_signal/plot_spectrogram.set_xticks()beforeset_xticklabels()everywhere, eliminating the matplotlibFixedFormatterwarning students would otherwise see.convert_to_monousesmean(axis=1)— correct for any channel count, not just stereo (oldsum(axis=1)/2assumed exactly two channels).Code-quality cleanup
scipy/librosa/distanceimports; thescipy.signalimport was being shadowed by localsignalvariables.map/remap(mapis now a thin alias ofremap).min_gapguard incalc_zero_crossings(output unchanged — pinned by existing tests).matplotlib.tickerimport to the top.Pedagogy
Parameters:/Returns:; fixed stale comments/typos (plot_Signal,y=1.14, a non-existent "quantization level" param).numpy.interp,scipy.ndimage.shift,librosa.zero_crossings,librosa.to_mono) with the behavioral differences noted — keeping the hand-written versions as the teaching artifact.Tutorials/makelab/README.mddocumenting the package purpose, import/CWD rules, and the public API.Tests
tests/test_makelab_audio.py(none existed), including a >2-channel case that guards theconvert_to_monofix.Verification
pytest tests/→ 29 passedpytest --nbmakeon the three signals notebooks → 3 passed (17m19s)Follow-up
quantization_bitsintoplot_signal'stitleslot; should useplot_audio) tracked separately in Quantization & Sampling notebook: plot_signal called with quantization_bits in the title slot (should be plot_audio) #10.🤖 Generated with Claude Code