Skip to content

Commit

Permalink
Merge pull request #233 from berkeley-stat159/find_activated
Browse files Browse the repository at this point in the history
Find activated
  • Loading branch information
ye-zhi committed Dec 13, 2015
2 parents 4b30121 + 8df0757 commit 4c08d99
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,18 @@ def find_activated_voxel(shape, p):
The index of our activated voxels
position1...4 correspond to the cond001...4 .txt in model_one
"""
loc1 = [i for i,j in enumerate(p[1,...]) if j < 0.05]
loc2 = [i for i,j in enumerate(p[2,...]) if j < 0.05]
loc3 = [i for i,j in enumerate(p[3,...]) if j < 0.05]
loc4 = [i for i,j in enumerate(p[4,...]) if j < 0.05]
# get the number of predictors(betas) first
n = p.shape[0]-1
loc={}
lst=[]
position=[]
for t in range(1,n+1):
loc["loc{0}".format(t)] = [i for i,j in enumerate(p[t,...]) if j < 0.05]
for i in loc["loc{0}".format(t)]:
position.append(get_index(shape,i))
position = np.asarray(position)
lst.append(position)
position=[]

position1 = []
for i in loc1:
position1.append(get_index(shape, i))

position2 = []
for i in loc2:
position2.append(get_index(shape, i))

position3 = []
for i in loc3:
position3.append(get_index(shape, i))

position4 = []
for i in loc4:
position4.append(get_index(shape, i))


position1 = np.asarray(position1)
position2 = np.asarray(position2)
position3 = np.asarray(position3)
position4 = np.asarray(position4)

return position1, position2, position3, position4
return lst

10 changes: 5 additions & 5 deletions code/utils/scripts/find_activated_voxel_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
beta, t, df,p=t_test(data,X_matrix_high_res)
shape = data.shape[:3]

position1,position2, position3,position4 = find_activated_voxel(shape, p)
lst = find_activated_voxel(shape, p)
location_of_txt="../txt_files/"
np.savetxt(location_of_txt+'ds005_sub001_t1r1_position1.txt',position1,fmt='%i')
np.savetxt(location_of_txt+'ds005_sub001_t1r1_position2.txt',position2,fmt='%i')
np.savetxt(location_of_txt+'ds005_sub001_t1r1_position3.txt',position3,fmt='%i')
np.savetxt(location_of_txt+'ds005_sub001_t1r1_position4.txt',position4,fmt='%i')

for i in range(1,len(lst)+1):
np.savetxt(location_of_txt+'ds005_sub001_t1r1_position%s.txt'%(str(i)),lst[i-1].ravel())

33 changes: 33 additions & 0 deletions code/utils/tests/test_find_activated_voxel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import sys
import numpy as np
import nibabel as nib
from nose.tools import assert_equal
from numpy.testing import assert_almost_equal, assert_array_equal


# Add path to functions to the system path.
sys.path.append(os.path.join(os.path.dirname(__file__), "../functions/"))

from find_activated_voxel_functions import *
project_path=os.path.join(os.path.dirname(__file__), '../../../')


def test_size():
shape = (2, 3, 2)
assert_equal(size(shape), 12)
assert_equal(size(shape, axis=0),2)

def test_get_increment():
assert_equal(get_increment((2, 4)),[4, 1])
assert_equal(get_increment((2, 2, 2)),[4, 2, 1])

def test_get_index():
shape = (2, 2, 2)
assert_equal(get_index(shape, 4),(1, 0, 0))
assert_equal(get_index(shape, 2),(0, 1, 0))


def test_find_activated_voxel():
p = np.array([[ 0.39764537],[ 0.005514348],[ 0.04195935]])
assert_array_equal(find_activated_voxel((2, 3, 4),p)[0],[[0, 0, 0]])

0 comments on commit 4c08d99

Please sign in to comment.