-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsizeeffect.py
50 lines (41 loc) · 1.14 KB
/
sizeeffect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Convert T maps into R maps for effect size
Authors: Chris Foulon & Michel Thiebaut de Scotten
"""
#see http://www.bcblab.com/BCB/Coding/Coding.html for a step by step installation of python
#don't forget to pip install nibabel :)
### modules ###
import os
from os import system as oss
import sys
import pandas as pd
import numpy as np
import nibabel as nib
print("python Effectsize_T2R.py numberofparticipants tvaluemap.nii.gz output.nii.gz")
# Defines the variable
n = int(sys.argv[1])
tval = sys.argv[2]
Rpower = sys.argv[3]
#import the nifti
i_tval = nib.load(tval)
# extract the data from the images
data_tval = i_tval.get_fdata()
#create df n - 2
df = np.subtract(n,2)
#Create t^2
step1 = np.square(data_tval)
#Create t^2 +44
step2 = np.add(step1,df)
#create (t^2 + 44)^1/2
step3 = pow(step2,0.5)
#create R = t / (t^2 + 44)^1/2
step4 = np.divide(data_tval,step3)
#create R^2
step5 = np.square(step4)
#create 1 - R^2
step6 = np.subtract(1,step5)
#create f^2 = R^2 / (1 - R^2)
step7 = np.divide(step5,step6)
#save the data
i_Rpower = nib.Nifti1Image(step7, i_tval.affine)
nib.save(i_Rpower, Rpower)