def obtain_traubs_srcVele(conductivity, run_type='seeg', save=False): '''Fetch the potentials for the default run - SEEG section For Traubs column''' mesh = meshes.load_just_mesh() if run_type == 'seeg': pos_list, conductivity, path, sbspt = params.default_run(conductivity) elif run_type == 'ecog': pos_list, conductivity, path, sbspt = params.ecog_run(size=0.98) elif run_type == 'heeg': pos_list, conductivity, path, sbspt = params.hippo_eeg_run() num_pts = len(pos_list) ele_list = params.load_traubs_points() # points from traubs colum num_ele = len(ele_list) phi_mat = np.zeros((num_pts, num_ele)) num_proc = how_many_procs(path, sbspt) proc_vals = np.linspace(0, num_pts, num_proc + 1).astype(int) for kk in range(num_proc): proc_idx = kk + 1 # as proc ids start from 1 pt_idxs = range(proc_vals[proc_idx - 1], proc_vals[proc_idx]) f_string = sbspt + str(num_proc) + '_' + str(proc_idx) + '.h5' dump_file = load_file(os.path.join(path, f_string), mesh) for pt in pt_idxs: this_phi = load_vector(dump_file, mesh, str(pt)) phi_mat[pt, :] = extract_pots(this_phi, np.array(ele_list)) dump_file.close() print('Finished processing proc number: ', proc_idx) if save: phi_mat_fname = sbspt + conductivity + '_' + run_type + '_traub_phi_mat.npy' np.save(os.path.join(path, phi_mat_fname), phi_mat) return
def test_few_points(): mesh = meshes.load_just_mesh() pos_list = [[5.196, 22.913, -4.9957], [8.4, 31.4, -6.151], [5.5945, 22.699, -5.6637]] dump_file = load_file(os.path.join(params.results_path, 'test_del_ih.h5'), mesh) phi_1 = load_vector(dump_file, mesh, '0') phi_2 = load_vector(dump_file, mesh, '1') phi_3 = load_vector(dump_file, mesh, '2') print(extract_pots(phi_1, np.array([pos_list[1], pos_list[2]]))) print(extract_pots(phi_2, np.array([pos_list[0], pos_list[2]]))) print(extract_pots(phi_3, np.array([pos_list[0], pos_list[1]])))
def obtain_orth_planes(src_label, orig_label, conductivity, save=False): ''' Sources placed at src_label, with orth planes meeting at orig_label The pots observed at the corresponding xx, yy, zz planes is reported - dumps an npz with arrays corres to orig_label corresp to each plane''' mesh = meshes.load_just_mesh() pos_list, conductivity, path, sbspt = params.default_run(conductivity) sp_pts = params.load_special_points() src_x, src_y, src_z = sp_pts[src_label] xx, yy, zz = sp_pts[orig_label] print('Testing if src location has exact probe point') src_idx = find_nearest_avail_pt(pos_list, src_x, src_y, src_z) k = np.array((pos_list[src_idx])) dists = np.linalg.norm(pos_list - k, axis=1) src_idx = np.argmin(dists) f_string = which_file(path, sbspt, pos_list, src_idx) dump_file = load_file(os.path.join(path, f_string), mesh) this_phi = load_vector(dump_file, mesh, str(src_idx)) planes = fetch_cut_planes(xx, yy, zz, 0.1) ### TODO - FUTURE ### instead get this from params as a special planes ### Planes get dumped from probe_points file instead - so premtively obtain these planes. phi_planes = [] # plane pots for ii, label in enumerate(['x', 'y', 'z']): ele_list = planes[ii] num_ele = len(ele_list) phi_mat = np.zeros((1, num_ele)) phi_mat[0, :] = extract_pots(this_phi, np.array(ele_list)) phi_planes.append(phi_mat) dump_file.close() if save: phi_mat_fname = sbspt + conductivity + '_' + src_label + '_' + orig_label + '_phi_mat.npz' np.savez(os.path.join(path, phi_mat_fname), xx=phi_planes[0], yy=phi_planes[1], zz=phi_planes[2], x_plane=planes[0], y_plane=planes[1], z_plane=planes[2]) return
def obtain_unsorted_srcVele(conductivity, save=False): '''Fetch the potentials for the default run - SEEG section to test reciprocity''' mesh = meshes.load_just_mesh() pos_list, conductivity, path, sbspt = params.default_run(conductivity) num_pts = len(pos_list) phi_mat = np.zeros((num_pts, num_pts)) num_proc = how_many_procs(path, sbspt) proc_vals = np.linspace(0, num_pts, num_proc + 1).astype(int) for kk in range(num_proc): proc_idx = kk + 1 # as proc ids start from 1 pt_idxs = range(proc_vals[proc_idx - 1], proc_vals[proc_idx]) f_string = sbspt + str(num_proc) + '_' + str(proc_idx) + '.h5' dump_file = load_file(os.path.join(path, f_string), mesh) for pt in pt_idxs: this_phi = load_vector(dump_file, mesh, str(pt)) phi_mat[pt, :] = extract_pots(this_phi, np.array(pos_list)) dump_file.close() print('Finished processing proc number: ', proc_idx) if save: phi_mat_fname = sbspt + conductivity + '_phi_mat.npy' np.save(os.path.join(path, phi_mat_fname), phi_mat) return
def compute_conductivity(conductivity, save=False): print('Computing sigma tensor for case :', conductivity) mesh = meshes.load_just_mesh() cells_all = d.cells(mesh) idx_out, idx_grnd, idx_csf, np_fa = params.load_barycenters_ids() points_to_sample = params.load_barycenters() idx_all = np.arange(len(points_to_sample)) if conductivity == 'anisotropic': np_v1, np_v2, np_v3 = params.load_eigen_vectors() longi_sigma = [] trans_sigma = [] for jj in idx_all: longi_sigma.append(scale_gm_wm(np_fa[jj], sig_brain, sig_wm_long)) trans_sigma.append(scale_gm_wm(np_fa[jj], sig_brain, sig_wm_trans)) print 'Did the scaling, now assigning vals' c00, c01, c02, c11, c12, c22 = tensor_components(mesh) for jj in idx_all: cell = cells_all.next() if jj in idx_grnd: # Electrode c00[cell] = sig_ele c11[cell] = sig_ele c22[cell] = sig_ele c01[cell] = sig_zero c02[cell] = sig_zero c12[cell] = sig_zero elif jj in idx_out: # Pt outside brain volume c00[cell] = sig_air c01[cell] = sig_zero c02[cell] = sig_zero c11[cell] = sig_air c12[cell] = sig_zero c22[cell] = sig_air elif jj in idx_csf: c00[cell] = sig_csf c01[cell] = sig_zero c02[cell] = sig_zero c11[cell] = sig_csf c12[cell] = sig_zero c22[cell] = sig_csf else: sig_wm_matrix = np.zeros((3, 3)) np.fill_diagonal( sig_wm_matrix, (longi_sigma[jj], trans_sigma[jj], trans_sigma[jj])) S = np.matrix((np_v1[jj], np_v2[jj], np_v3[jj])) # This is correct. S is eigen vectors are row vectors sigma_mat = np.around(S.T * sig_wm_matrix * S, decimals=4) c00[cell] = sigma_mat[0, 0] c11[cell] = sigma_mat[1, 1] c22[cell] = sigma_mat[2, 2] c01[cell] = sigma_mat[0, 1] c02[cell] = sigma_mat[0, 2] c12[cell] = sigma_mat[1, 2] if save: c00_file = d.File( os.path.join(params.anis_path, "sigma_anis_d0.xml.gz")) c01_file = d.File( os.path.join(params.anis_path, "sigma_anis_d1.xml.gz")) c02_file = d.File( os.path.join(params.anis_path, "sigma_anis_d2.xml.gz")) c11_file = d.File( os.path.join(params.anis_path, "sigma_anis_d3.xml.gz")) c12_file = d.File( os.path.join(params.anis_path, "sigma_anis_d4.xml.gz")) c22_file = d.File( os.path.join(params.anis_path, "sigma_anis_d5.xml.gz")) c00_file << c00 c01_file << c01 c02_file << c02 c11_file << c11 c12_file << c12 c22_file << c22 elif conductivity == 'inhomogeneous': c = d.MeshFunction("double", mesh, 3) fa_scaled_sigma = [] for jj in idx_all: fa_scaled_sigma.append(scale_gm_wm(np_fa[jj], sig_brain, sig_wm)) print 'Did the scaling, now assigning vals' for jj in idx_all: cell = cells_all.next() if jj in idx_grnd: c[cell] = sig_ele elif jj in idx_out: c[cell] = sig_air elif jj in idx_csf: c[cell] = sig_csf else: c[cell] = fa_scaled_sigma[jj] if save: c00_file = d.File( os.path.join(params.inhom_path, "sigma_inhom.xml.gz")) c00_file << c elif conductivity == 'homogeneous': c = d.MeshFunction("double", mesh, 3) for jj in idx_all: cell = cells_all.next() if jj in idx_grnd: c[cell] = sig_ele elif jj in idx_out: c[cell] = sig_air elif jj in idx_csf: c[cell] = sig_csf else: c[cell] = sig_brain if save: c00_file = d.File(os.path.join(params.hom_path, "sigma_hom.xml.gz")) c00_file << c