Skip to content

Fix plot_approach_figures execution during book build#86

Open
eurunuela wants to merge 2 commits into
ME-ICA:mainfrom
eurunuela:fix-plot-approach-figures-build
Open

Fix plot_approach_figures execution during book build#86
eurunuela wants to merge 2 commits into
ME-ICA:mainfrom
eurunuela:fix-plot-approach-figures-build

Conversation

@eurunuela

Copy link
Copy Markdown
Contributor

Problem

content/plot_approach_figures.md fails to execute during the Jupyter Book build. There were two execution-halting bugs in the chapter:

  1. The setup cell referenced func_dir without defining it → NameError: name 'func_dir' is not defined (the originally-reported failure).
  2. After fixing that, the "Prepare data for model" cell ran -1 * data['echo_times'] on the list returned by load_pafin (-1 * a_list yields []), raising ValueError in np.column_stack.

The cell also builds a background anatomical image from a boldref->T1w transform 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.md only)

  • Define func_dir in the setup cell (data/ds006185/sub-24053/ses-1/func/), matching 04_Dual_Echo_Denoising.md 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. Kept local to this chapter — load_pafin still returns a list, which 02/03 rely on.
  • Guard the bg_img construction: fall back to nilearn's default background (bg_img=None, a documented mode) when the boldref->T1w transform or the T1w image are absent.

Verification

  • Executed the full page via nbclient (which raises on any cell error — this is what caught the echo_times bug): 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 the bg_img=None adaptive-mask figure); build succeeded.

Out of scope / note

The chapter's tedana-derivative loads remain unguarded — they rely on data/tedana being present (generated by chapter 03, which persists across builds since make clean spares data/). Because this chapter is ordered before 03 in the TOC, a clean-data build would still render it broken. Reordering it after 03 would fix that, but is left out here (the chapter is also slated to be merged into TE_Dependence/Signal_Decay).

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 9, 2026 11:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_dir in the setup cell to avoid a NameError.
  • Convert data["echo_times"] from list to np.ndarray to ensure downstream array arithmetic behaves correctly.
  • Make bg_img optional by only constructing it when both the boldref→T1w transform and T1w file are present; otherwise use bg_img=None.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eurunuela eurunuela requested a review from tsalo June 9, 2026 13:07
Comment thread content/plot_approach_figures.md Outdated

# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the download step should fetch these instead of making the later code more flexible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants