Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Optimize interface to minimize memory fingerprint #1351

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions mriqc/interfaces/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,26 +226,12 @@ class Spikes(SimpleInterface):

def _run_interface(self, runtime):
func_nii = nb.load(self.inputs.in_file)
func_data = func_nii.get_fdata()
func_data = func_nii.get_fdata(dtype='float32')
func_shape = func_data.shape
ntsteps = func_shape[-1]
tr = func_nii.header.get_zooms()[-1]
nskip = self.inputs.skip_frames

if self.inputs.detrend:
from nilearn.signal import clean

data = func_data.reshape(-1, ntsteps)
clean_data = clean(data[:, nskip:].T, t_r=tr, standardize=False).T
new_shape = (
func_shape[0],
func_shape[1],
func_shape[2],
clean_data.shape[-1],
)
func_data = np.zeros(func_shape)
func_data[..., nskip:] = clean_data.reshape(new_shape)

mask_data = np.bool_(nb.load(self.inputs.in_mask).dataobj)
mask_data[..., :nskip] = 0
mask_data = np.stack([mask_data] * ntsteps, axis=-1)
Expand All @@ -256,6 +242,11 @@ def _run_interface(self, runtime):
mask_data[..., : self.inputs.skip_frames] = 1
brain = np.ma.array(func_data, mask=(mask_data == 1))

if self.inputs.detrend:
from nilearn.signal import clean

brain = clean(brain[:, nskip:].T, t_r=tr, standardize=False).T

if self.inputs.no_zscore:
ts_z = find_peaks(brain)
total_spikes = []
Expand Down
1 change: 1 addition & 0 deletions mriqc/workflows/functional/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def init_func_report_wf(name='func_report_wf'):
name='SpikesFinderBgMask',
mem_gb=mem_gb * 2.5,
iterfield=['in_file', 'in_mask'],
n_procs=(config.nipype.nprocs + 3) // 4, # spikes is a memory hog
)

# Generate crown mask
Expand Down
Loading