Skip to content

Commit 1cdfb6a

Browse files
oestebanclaude
andcommitted
fix: avoid indexed_gzip seek failure in save_3d_to_4d
Load each 3D volume's data into memory before concatenation to prevent `indexed_gzip` `ZranError` when many gzipped NIfTI files are open simultaneously. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 26a1a31 commit 1cdfb6a

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

dmriprep/data/tests/dwi_b0.nii.gz

-11 Bytes
Binary file not shown.

dmriprep/utils/images.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,13 @@ def save_3d_to_4d(in_files):
324324
>>> assert len(threeD_files) == nb.load(out_file).shape[-1]
325325
"""
326326
# Remove one-sized extra dimensions
327+
# Load data eagerly to avoid indexed_gzip seek failures with many open files
327328
nii_list = []
328-
for _i, f in enumerate(in_files):
329-
filenii = nb.load(f)
330-
filenii = nb.squeeze_image(filenii)
329+
for f in in_files:
330+
filenii = nb.squeeze_image(nb.load(f))
331331
if len(filenii.shape) != 3:
332332
raise RuntimeError(f'Input image ({f}) is not 3D.')
333-
else:
334-
nii_list.append(filenii)
333+
nii_list.append(nb.Nifti1Image(filenii.get_fdata(), filenii.affine, filenii.header))
335334
img_4d = nb.funcs.concat_images(nii_list)
336335
out_file = fname_presuffix(in_files[0], suffix='_merged')
337336
img_4d.to_filename(out_file)

0 commit comments

Comments
 (0)