Skip to content

Commit 0f9fbde

Browse files
committed
dvars function
1 parent 8b7de78 commit 0f9fbde

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

findoutlie/metrics.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
# Any imports you need
55
# +++your code here+++
6+
import numpy as np
67

78

89
def dvars(img):
@@ -29,4 +30,21 @@ def dvars(img):
2930
# You may be be able to solve this in four lines, without a loop.
3031
# But solve it any way you can.
3132
# This is a placeholder, replace it to write your solution.
33+
data=img.get_fdata()
34+
vol_shape=data.shape[:-1]
35+
n_voxels=np.prod(vol_shape)
36+
37+
voxel_by_time = np.reshape(data, (n_voxels, data.shape[-1]))
38+
39+
vol_diff= voxel_by_time[...,1:]-voxel_by_time[...,:-1] # 2D array
40+
#print(vol_diff.shape())
41+
print(vol_diff)
42+
#vol_diff_1D=vol_diff.flatten()
43+
dvar_val = np.sqrt(np.mean(vol_diff ** 2, axis=0))
44+
#print(dvar_val.shape())
45+
print(dvar_val)
46+
return dvar_val
47+
48+
49+
3250
raise NotImplementedError('Code up this function')

0 commit comments

Comments
 (0)