size_keys = ['size'] * len(vsigkeys)
roi_bkeys = ['roi_'+x for x in bsigkeys]
roi_tkeys = ['roi_'+x for x in tsigkeys]
roi_zkeys = ['roi_'+x for x in zsigkeys]
roi_vkeys = ['roi_'+x for x in vsigkeys]
roi_ekeys = ['roi_E'+x for x in MT_con_key]
mean_vkeys = ['mean_'+x for x in vsigkeys]
#########################################################################
atlas_stattk.update_cached_stats(lambda x:x, mean_bkeys, roi_bkeys)
pooled_fixedvar_tk = meantk
atlas_stattk.extract_signals_stats(vsignals, pooled_fixedvar_tk, vsigkeys)
atlas_stattk.update_cached_stats(lambda x, y: x/y, zip(mean_vkeys, size_keys), roi_vkeys) # pooled fixed variance == mean region variance / region size == sum of variance / region size**2  AND DoF = sum of each voxel's DoF
atlas_stattk.update_cached_stats(np.sqrt, roi_vkeys, roi_ekeys)
atlas_stattk.update_cached_stats(lambda x, y: x/y, zip(roi_bkeys, roi_ekeys), roi_tkeys)
dof = 160
atlas_stattk.update_cached_stats(lambda x, y: atlastk.t_ztransform(x, dof*y - 1), zip(roi_tkeys, size_keys), roi_zkeys)

t3 = time.time() - t2
print 'Signal Value and Statistics Done: %f sec' % t3
########################################################################
anat_img = '/nfs/j3/userhome/huangtaicheng/workingdir/parcellation_MT/BAA/results/yang_test/template/HarvardOxford-cort-maxprob-thr0-2mm.nii.gz'
anat_img = nib.load(anat_img).get_data()

atlas_stattk.cal_anat_relations('overlap', atlastk.multi_left_overlap, 'HOcort_thr0', anat_img)
#########################################################################
atlas_stattk.cal_between_subj_relation('dice', atlastk.between_dice)
#########################################################################
dist_func = lambda x, y:atlastk.dist(x, y, atlas_deposite.img_resolution)
atlas_stattk.cal_multi_roi_relation('peak_distance', dist_func, atlastk.RoiStatTk.get_subject_peak)
hausdorff_func = lambda x, y: atlastk.hausdorff(x, y, atlas_deposite.img_resolution)
atlas_stattk.cal_multi_roi_relation('hausdorff_distance', hausdorff_func, atlastk.RoiStatTk.get_subject_label)