From 860fd06fa66f3c60ffaba27d285304d3843382fd Mon Sep 17 00:00:00 2001 From: RDoerfel Date: Sat, 27 Aug 2022 15:57:45 +0200 Subject: [PATCH 1/2] enh: implement get_spm_globals function to load image and compute global volume. --- spm_funcs.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spm_funcs.py b/spm_funcs.py index 450c1ab..e805e32 100644 --- a/spm_funcs.py +++ b/spm_funcs.py @@ -54,8 +54,13 @@ def get_spm_globals(fname): spm_vals : array SPM global metric for each 3D volume in the 4D image. """ - # +++your code here+++ - # return + image = nib.load(fname) + data = image.get_fdata() + spm_vals = [] + for i in range(data.shape[-1]): + volume = data[..., i] + spm_vals.append(spm_global(volume)) + return spm_vals def main(): From daac753f2e9ae90344e05a190e0e6866616cbe7d Mon Sep 17 00:00:00 2001 From: RDoerfel Date: Tue, 30 Aug 2022 19:59:10 +0200 Subject: [PATCH 2/2] return spm_vals as numpy array and update docstring to be more explicit about the return type. --- spm_funcs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spm_funcs.py b/spm_funcs.py index e805e32..92c8ef2 100644 --- a/spm_funcs.py +++ b/spm_funcs.py @@ -51,7 +51,7 @@ def get_spm_globals(fname): Returns ------- - spm_vals : array + spm_vals : np.array SPM global metric for each 3D volume in the 4D image. """ image = nib.load(fname) @@ -60,7 +60,7 @@ def get_spm_globals(fname): for i in range(data.shape[-1]): volume = data[..., i] spm_vals.append(spm_global(volume)) - return spm_vals + return np.array(spm_vals) def main():