Skip to content

Conversation

@The-Obstacle-Is-The-Way

Summary

  • Single-line fix: Change dataobj=nifti_image.get_fdata()dataobj=nifti_image.dataobj
  • Preserves nibabel's ArrayProxy for true lazy loading instead of eagerly loading entire NIfTI files into memory
  • Improves error handling: corrupted files now fail at access time with clear context instead of silently during decode

Problem

The Nifti1ImageWrapper.__init__ was calling get_fdata() which immediately loads the entire image into memory. For large 4D fMRI files (often 1-2GB), this causes:

  1. Memory issues - Full data loaded during decode, not on demand
  2. Poor error handling - Corrupted files crash at access time with unclear error messages (e.g., EOFError with no file path)
  3. No graceful recovery - Entire dataset iteration fails on one bad file

Solution

Use nifti_image.dataobj which preserves the underlying ArrayProxy, deferring actual I/O to get_fdata() calls.

Test Plan

  • Added test_nifti_lazy_loading to verify ArrayProxy is preserved
  • All 22 existing NIfTI tests pass
  • End-to-end tested with real OpenNeuro data (ds000102)
  • CodeRabbit approved: "Switch to dataobj correctly restores nibabel's lazy loading semantics... This looks solid"

Related

- Change dataobj initialization from get_fdata() to .dataobj
- Preserves nibabel's ArrayProxy for lazy loading
- Prevents OOM errors on large 4D fMRI files
- Defers I/O errors to usage time for better error handling

Resolves #1
@The-Obstacle-Is-The-Way The-Obstacle-Is-The-Way deleted the feat/nifti-lazy-loading branch November 29, 2025 14:56
@The-Obstacle-Is-The-Way The-Obstacle-Is-The-Way restored the feat/nifti-lazy-loading branch November 29, 2025 14:58
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.

1 participant