Skip to content

Commit 195521d

Browse files
committed
RF: Remove old copy of _create_mem_gb
Cache estimate_bold_mem_usage to avoid unnecessary I/O
1 parent 8fd5fbe commit 195521d

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

fmriprep/utils/misc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#
2323
"""Miscellaneous utilities."""
2424
import typing as ty
25+
from functools import cache
2526

2627

2728
def check_deps(workflow):
@@ -48,6 +49,7 @@ def fips_enabled():
4849
return fips.exists() and fips.read_text()[0] != "0"
4950

5051

52+
@cache
5153
def estimate_bold_mem_usage(bold_fname: str) -> ty.Tuple[int, dict]:
5254
import nibabel as nb
5355
import numpy as np

fmriprep/workflows/bold/base.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
from ... import config
4141
from ...interfaces import DerivativesDataSink
42+
from ...utils.misc import estimate_bold_mem_usage
4243

4344
# BOLD workflows
4445
from .apply import init_bold_volumetric_resample_wf
@@ -176,7 +177,7 @@ def init_bold_wf(
176177
omp_nthreads = config.nipype.omp_nthreads
177178
all_metadata = [config.execution.layout.get_metadata(file) for file in bold_series]
178179

179-
nvols, mem_gb = _create_mem_gb(bold_file)
180+
nvols, mem_gb = estimate_bold_mem_usage(bold_file)
180181
if nvols <= 5 - config.execution.sloppy:
181182
config.loggers.workflow.warning(
182183
f"Too short BOLD series (<= 5 timepoints). Skipping processing of <{bold_file}>."
@@ -683,21 +684,6 @@ def _last(inlist):
683684
return workflow
684685

685686

686-
def _create_mem_gb(bold_fname):
687-
img = nb.load(bold_fname)
688-
nvox = int(np.prod(img.shape, dtype='u8'))
689-
# Assume tools will coerce to 8-byte floats to be safe
690-
bold_size_gb = 8 * nvox / (1024**3)
691-
bold_tlen = 1 if img.ndim < 4 else img.shape[3]
692-
mem_gb = {
693-
"filesize": bold_size_gb,
694-
"resampled": bold_size_gb * 4,
695-
"largemem": bold_size_gb * (max(bold_tlen / 100, 1.0) + 4),
696-
}
697-
698-
return bold_tlen, mem_gb
699-
700-
701687
def _get_wf_name(bold_fname, prefix):
702688
"""
703689
Derive the workflow name for supplied BOLD file.

0 commit comments

Comments
 (0)