From 001f1aa69350f9264f9ef2541ed49a65be49332d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eneko=20Uru=C3=B1uela?= Date: Tue, 9 Jun 2026 13:05:52 +0200 Subject: [PATCH 1/2] Fix plot_approach_figures execution during book build 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) --- content/plot_approach_figures.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/content/plot_approach_figures.md b/content/plot_approach_figures.md index fe0c3434..d038fe09 100644 --- a/content/plot_approach_figures.md +++ b/content/plot_approach_figures.md @@ -35,6 +35,7 @@ from tedana.utils import make_adaptive_mask data_path = os.path.abspath('../data') +func_dir = os.path.join(data_path, "ds006185/sub-24053/ses-1/func/") ted_dir = os.path.join(data_path, "tedana") ``` @@ -42,16 +43,24 @@ ted_dir = os.path.join(data_path, "tedana") ```{code-cell} ipython3 :tags: [hide-cell] data = load_pafin(data_path) +# load_pafin returns echo_times as a list; this chapter does array arithmetic on +# it (e.g. -1 * echo_times), so coerce to an array once here. +data['echo_times'] = np.asarray(data['echo_times']) -# 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 +# absent, fall back to nilearn's default background by leaving bg_img as None. anat_dir = os.path.join(data_path, "ds006185/sub-24053/ses-1/anat/") -xfm = os.path.join( +xfm_file = os.path.join( func_dir, "sub-24053_ses-1_task-rat_dir-PA_run-01_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt", ) -xfm = nit.linear.load(xfm, fmt="itk") t1_file = os.path.join(anat_dir, "sub-24053_ses-1_rec-norm_desc-preproc_T1w.nii.gz") -bg_img = xfm.apply(spatialimage=t1_file, reference=data['echo_files'][0]) +if os.path.exists(xfm_file) and os.path.exists(t1_file): + xfm = nit.linear.load(xfm_file, fmt="itk") + bg_img = xfm.apply(spatialimage=t1_file, reference=data['echo_files'][0]) +else: + bg_img = None # Tedana outputs adaptive_mask_file = os.path.join( From 1a0bd21bf5c4fd34038a07e6d32a4fbfc5dfe737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eneko=20Uru=C3=B1uela?= Date: Wed, 10 Jun 2026 08:32:47 +0200 Subject: [PATCH 2/2] Fetch background transform/T1w in download step instead of guarding bg_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) --- content/00_Download_Data.md | 2 ++ content/plot_approach_figures.md | 13 ++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/content/00_Download_Data.md b/content/00_Download_Data.md index 12dab6c1..124dcf3c 100644 --- a/content/00_Download_Data.md +++ b/content/00_Download_Data.md @@ -23,4 +23,6 @@ cd ../data/ds006185 datalad get -J5 sub-24053/ses-1/func/sub-24053_ses-1_task-rat_dir-PA_run-01_echo-* datalad get sub-24053/ses-1/func/sub-24053_ses-1_task-rat_dir-PA_run-01_part-mag_desc-brain_mask.nii.gz datalad get sub-24053/ses-1/func/sub-24053_ses-1_task-rat_dir-PA_run-01_part-mag_desc-confounds_timeseries.tsv +datalad get sub-24053/ses-1/func/sub-24053_ses-1_task-rat_dir-PA_run-01_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt +datalad get sub-24053/ses-1/anat/sub-24053_ses-1_rec-norm_desc-preproc_T1w.nii.gz ``` diff --git a/content/plot_approach_figures.md b/content/plot_approach_figures.md index d038fe09..33cc150d 100644 --- a/content/plot_approach_figures.md +++ b/content/plot_approach_figures.md @@ -47,20 +47,15 @@ data = load_pafin(data_path) # it (e.g. -1 * echo_times), so coerce to an array once here. data['echo_times'] = np.asarray(data['echo_times']) -# 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 -# absent, fall back to nilearn's default background by leaving bg_img as None. +# Background anatomical image anat_dir = os.path.join(data_path, "ds006185/sub-24053/ses-1/anat/") -xfm_file = os.path.join( +xfm = os.path.join( func_dir, "sub-24053_ses-1_task-rat_dir-PA_run-01_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt", ) +xfm = nit.linear.load(xfm, fmt="itk") t1_file = os.path.join(anat_dir, "sub-24053_ses-1_rec-norm_desc-preproc_T1w.nii.gz") -if os.path.exists(xfm_file) and os.path.exists(t1_file): - xfm = nit.linear.load(xfm_file, fmt="itk") - bg_img = xfm.apply(spatialimage=t1_file, reference=data['echo_files'][0]) -else: - bg_img = None +bg_img = xfm.apply(spatialimage=t1_file, reference=data['echo_files'][0]) # Tedana outputs adaptive_mask_file = os.path.join(