Skip to content

Commit

Permalink
fixed np load string array
Browse files Browse the repository at this point in the history
  • Loading branch information
trislett committed Sep 12, 2018
1 parent 0fa6b24 commit fedd276
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tfce_mediation/tmanalysis/STEP_0_load_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run(opts):
nonzero_data = np.array(nonzero_data).T
elif opts.filelist:
nonzero_data = []
for image_path in np.genfromtxt(opts.filelist[0], delimiter=','):
for image_path in np.genfromtxt(opts.filelist[0], delimiter=',', dtype=None):
nonzero_data.append(import_voxel_neuroimage(image_path, mask_index))
nonzero_data = np.array(nonzero_data).T
else:
Expand Down
23 changes: 22 additions & 1 deletion tfce_mediation/tools/voxel_extract_mean_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
import argparse as ap
from sklearn.decomposition import PCA

# Detects outliers using median absolute deviation
# Reference
# Boris Iglewicz and David Hoaglin (1993), "Volume 16: How to Detect and
# Handle Outliers", The ASQC Basic References in Quality Control:
# Statistical Techniques, Edward F. Mykytka, Ph.D., Editor.
def mad_based_outlier(points, thresh=3.5):
if len(points.shape) == 1:
points = points[:,None]
median = np.median(points, axis=0)
diff = np.sum((points - median)**2, axis=-1)
diff = np.sqrt(diff)
med_abs_deviation = np.median(diff)
modified_z_score = 0.6745 * diff / med_abs_deviation
return modified_z_score > thresh


DESCRIPTION = "Calculate mean FA values from label after running STEP_0."

def getArgumentParser(ap = ap.ArgumentParser(description = DESCRIPTION)):
Expand Down Expand Up @@ -54,10 +70,15 @@ def run(opts):
start=opts.range[0]
stop=opts.range[1] + 1
meanvalue = np.zeros((num_subjects,int(stop-start)))
outliers = np.zeros((num_subjects,int(stop-start)))
for i in range(start,stop):
meanvalue[:,(i-1)]=allFA4D[label_data==i].mean(axis=0)
mean = allFA4D[label_data==i].mean(axis=0)
meanvalue[:,(i-1)] = mean
outliers[:,(i-1)] = mad_based_outlier(mean)*1
np.savetxt("Mean_voxel_label.csv", meanvalue, delimiter=",")
np.savetxt("Outlier_voxel_label.csv", outliers, delimiter=",")


if opts.pca:
print(("Evaluating %d components" % opts.pca[0]))
x = (meanvalue - np.mean(meanvalue, 0)) / np.std(meanvalue, 0)
Expand Down

0 comments on commit fedd276

Please sign in to comment.