Fix plot_approach_figures execution during book build#86
Conversation
The setup cell referenced func_dir without defining it (NameError), and the model cell ran `-1 * data['echo_times']` on the list returned by load_pafin, which yields [] and raises ValueError in np.column_stack. Both errors halt `jupyter-book build`. - Define func_dir alongside ted_dir, matching 04_Dual_Echo_Denoising and load_pafin (ted_dir was already correct). - Coerce echo_times to a NumPy array once after load_pafin so the chapter's array arithmetic works; load_pafin itself still returns a list, which 02/03 rely on. - Guard the boldref->T1w background: fall back to nilearn's default (bg_img=None) when the transform or T1w image are absent (the transform is a git-annex file the download step never fetches). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes execution failures in the Jupyter Book build for content/plot_approach_figures.md by aligning the chapter’s setup with load_pafin output types and making background-anatomy handling robust when optional dataset files are missing.
Changes:
- Define
func_dirin the setup cell to avoid aNameError. - Convert
data["echo_times"]from list tonp.ndarrayto ensure downstream array arithmetic behaves correctly. - Make
bg_imgoptional by only constructing it when both the boldref→T1w transform and T1w file are present; otherwise usebg_img=None.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Background anatomical image | ||
| # Background anatomical image. The boldref->T1w transform and the T1w image are | ||
| # optional dataset files that the download step does not fetch; when either is |
There was a problem hiding this comment.
I think the download step should fetch these instead of making the later code more flexible.
There was a problem hiding this comment.
Good call — done in 1a0bd21. The download step (00_Download_Data.md) now datalad gets the boldref→T1w transform and the T1w image, and the bg_img block is back to its original unconditional form (the func_dir / echo_times fixes stay). Verified the chapter executes end-to-end with the fetched files.
…g_img Per @tsalo's review: rather than making the chapter code flexible to absent files, the download step now fetches the boldref->T1w transform and the T1w image, so plot_approach_figures builds bg_img unconditionally. - Revert the bg_img construction to its original unconditional form. - 00_Download_Data: datalad get the boldref->T1w transform and the T1w. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Problem
content/plot_approach_figures.mdfails to execute during the Jupyter Book build. There were two execution-halting bugs in the chapter:func_dirwithout defining it →NameError: name 'func_dir' is not defined(the originally-reported failure).-1 * data['echo_times']on the list returned byload_pafin(-1 * a_listyields[]), raisingValueErrorinnp.column_stack.The cell also builds a background anatomical image from a
boldref->T1wtransform that the data-download step never fetches (a git-annex file), so it would fail wherever that file is absent.Changes (
content/plot_approach_figures.mdonly)func_dirin the setup cell (data/ds006185/sub-24053/ses-1/func/), matching04_Dual_Echo_Denoising.mdandload_pafin.ted_dirwas already correct.echo_timesto a NumPy array once afterload_pafin, so the chapter's array arithmetic works. Kept local to this chapter —load_pafinstill returns a list, which02/03rely on.bg_imgconstruction: fall back to nilearn's default background (bg_img=None, a documented mode) when theboldref->T1wtransform or the T1w image are absent.Verification
nbclient(which raises on any cell error — this is what caught theecho_timesbug): all 38 cells run clean.UV_PROJECT_ENVIRONMENT=meda uv run --locked jupyter-book build ./re-executes the page (77.9 s) and emits all 16 figures (including thebg_img=Noneadaptive-mask figure);build succeeded.Out of scope / note
The chapter's tedana-derivative loads remain unguarded — they rely on
data/tedanabeing present (generated by chapter03, which persists across builds sincemake cleansparesdata/). Because this chapter is ordered before03in the TOC, a clean-data build would still render it broken. Reordering it after03would fix that, but is left out here (the chapter is also slated to be merged intoTE_Dependence/Signal_Decay).🤖 Generated with Claude Code