Skip to content

Commit a4fec43

Browse files
author
Emi Nomura
committed
Added different functions to handle multiple conditions.
1 parent 5570ce2 commit a4fec43

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

brainx/util.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,33 @@ def format_matrix(data,s,b,lk,co,nouptri = False):
2929

3030
#cmat = replace_diag(cmat) #replace diagonals with zero
3131
cmat = thresholded_arr(cmat,th,fill_val=0)
32+
3233
if not nouptri:
3334
cmat = np.triu(cmat,1)
35+
36+
return cmat
37+
38+
def format_matrix2(data,s,sc,c,lk,co,nouptri = False):
39+
""" Function which formats matrix for a particular subject and particular block (thresholds, upper-tris it) so that we can make a graph object out of it
40+
41+
Parameters:
42+
-----------
43+
data = full data array
44+
s = subject
45+
b = block
46+
lk = lookup table for study
47+
co = cost value to threshold at
48+
"""
49+
50+
cmat = data[sc,c,s]
51+
th = cost2thresh2(co,s,sc,c,lk,[]) #get the right threshold
52+
53+
#cmat = replace_diag(cmat) #replace diagonals with zero
54+
cmat = thresholded_arr(cmat,th,fill_val=0)
3455

56+
if not nouptri:
57+
cmat = np.triu(cmat,1)
58+
3559
return cmat
3660

3761

@@ -406,6 +430,35 @@ def cost2thresh(cost,sub,bl,lk,last):
406430
#print th
407431
return th
408432

433+
def cost2thresh2(cost,sub,sc,c,lk,last):
434+
"""A definition for loading the lookup table and finding the threshold associated with a particular cost for a particular subject in a particular block
435+
436+
inputs:
437+
cost: cost value for which we need the associated threshold
438+
sub: subject number
439+
bl: block number
440+
lk: lookup table (block x subject x cost
441+
last: last threshold value
442+
443+
output:
444+
th: threshold value for this cost"""
445+
446+
#print cost,sub,bl
447+
448+
ind=np.where(lk[sc,c,sub][1]==cost)
449+
th=lk[sc,c,sub][0][ind]
450+
451+
if len(th)>1:
452+
th=th[0] #if there are multiple thresholds, go down to the lower cost ####Is this right?!!!####
453+
print 'multiple thresh'
454+
elif len(th)<1:
455+
th=last #if there is no associated thresh value because of repeats, just use the previous one
456+
print 'use previous thresh'
457+
else:
458+
th=th[0]
459+
460+
#print th
461+
return th
409462

410463
def network_ind(ntwk_type,n_nodes):
411464
"""Reads in a network type, number of nodes total and returns the indices of that network"""

0 commit comments

Comments
 (0)