Skip to content

Commit d2ae227

Browse files
committed
FIX: Use last volume as reference for shorter BOLD series
1 parent d088c89 commit d2ae227

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

nibabies/workflows/bold/reference.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,25 @@ def init_raw_boldref_wf(
160160
def _select_frames(
161161
in_file: str, ref_frame_start: int, dummy_scans: int | None
162162
) -> tuple[int, list]:
163+
import warnings
164+
163165
import nibabel as nb
164166
import numpy as np
165167

166168
img = nb.load(in_file)
167169
img_len = img.shape[3]
168170

169-
if dummy_scans:
170-
# Ensure start index is the largest of the two
171-
# Will usually be `ref_frame_start`
172-
start_frame = max(ref_frame_start, dummy_scans)
173-
else:
174-
start_frame = ref_frame_start
171+
# Ensure start index is the largest of the two
172+
# Will usually be `ref_frame_start`
173+
start_frame = max(ref_frame_start, dummy_scans) if dummy_scans else ref_frame_start
175174

176175
if start_frame >= img_len:
177-
raise KeyError(
178-
f'Caculating the BOLD reference starting on frame: {start_frame} but not enough BOLD '
179-
f'volumes in {in_file}.'
176+
warnings.warn(
177+
f'Caculating the BOLD reference starting on frame {start_frame} but only {img_len} '
178+
'volumes in BOLD file, so using last volume.',
179+
stacklevel=1,
180180
)
181+
start_frame = img_len - 1
181182

182183
t_mask = np.array([False] * img_len, dtype=bool)
183184
t_mask[start_frame:] = True

0 commit comments

Comments
 (0)