From a3fb08aced4ccebc0c86a0d67ac3d973a87ef5f5 Mon Sep 17 00:00:00 2001 From: Jagruti Patel Date: Sun, 28 Aug 2022 20:42:48 +0200 Subject: [PATCH 1/2] Fixes to the spm_funcs.py to get the spm_global for each volume --- spm_funcs.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spm_funcs.py b/spm_funcs.py index 450c1ab..cb7651c 100644 --- a/spm_funcs.py +++ b/spm_funcs.py @@ -54,8 +54,15 @@ def get_spm_globals(fname): spm_vals : array SPM global metric for each 3D volume in the 4D image. """ - # +++your code here+++ - # return + # Load the image given by "fname" + img = nib.load(fname) + # Get the data + data = img.get_fdata() + # Calculate the SPM global value for each volume + spm_vals = [] + for i in range(data.shape[-1]): + spm_vals.append(spm_global(data[...,i])) + return np.array(spm_vals) def main(): From e3b6dac0e4a9328e185836949c272d8457da9e1b Mon Sep 17 00:00:00 2001 From: Jagruti Patel Date: Wed, 31 Aug 2022 12:21:11 +0200 Subject: [PATCH 2/2] Usage of list comprehension instead of for loop inside the get_spm_globals function for calculating the spm_global of each volume in the given 4D image --- spm_funcs.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spm_funcs.py b/spm_funcs.py index cb7651c..c9eed1a 100644 --- a/spm_funcs.py +++ b/spm_funcs.py @@ -59,10 +59,8 @@ def get_spm_globals(fname): # Get the data data = img.get_fdata() # Calculate the SPM global value for each volume - spm_vals = [] - for i in range(data.shape[-1]): - spm_vals.append(spm_global(data[...,i])) - return np.array(spm_vals) + spm_vals = np.array([spm_global(data[...,i]) for i in range(data.shape[-1])]) + return spm_vals def main():