def mat_to_ply(): fol = '/homes/5/npeled/space1/Angelique/Lionel Recon/' files = glob.glob(op.join(fol, 'Iso*.mat')) avg_fname = op.join(fol, 'blender', 'mean_vertices.npy') if not op.isfile(avg_fname): vertices_avg = [] for f in files: print(f) m = utils.read_mat_file_into_bag(f) vertices_avg.append(np.mean(m.vertices.T / 10, 0)) m.clear() vertices_avg = np.mean(vertices_avg) np.save(avg_fname, vertices_avg) else: vertices_avg = np.load(avg_fname) for f in files: print(f) m = utils.read_mat_file_into_bag(f) ply_fname = utils.change_fname_extension(f, 'ply') utils.write_ply_file(m.vertices.T / 10.0 - vertices_avg , m.faces.T, ply_fname, True) m.clear()
def read_psd_mat_file(subject, psd_fname, stim_channel): x = utils.read_mat_file_into_bag(psd_fname) labels = get_labels(x) data = x.psd if 'psd' in x else x.Psd if 'time' in x: time = x.time.reshape((x.time.shape[1])) else: time = None freqs = [(0, 4), (4, 8), (8, 15), (15, 30), (30, 55), (65, 100)] # plt.plot(time, psd[0, 0, :]) # plt.show() out_fol = op.join(BLENDER_ROOT_DIR, subject, 'electrodes') utils.make_dir(out_fol) np.savez(op.join(out_fol, 'psd_{}'.format(stim_channel)), labels=labels, psd=data, time=time, freqs=freqs)
def get_labels(x=None, mat_fname=''): if mat_fname != '': x = utils.read_mat_file_into_bag(mat_fname) if x is None: raise Exception('x is None!') labels = x['Label'] labels = labels.reshape((len(labels))) fix_labels = [] for label in labels: label = label[0] elecs = label.split('-') group, elc1_name = utils.elec_group_number(elecs[0], False) _, elc2_name = utils.elec_group_number(elecs[1], False) fix_labels.append('{0}{2}-{0}{1}'.format(group, elc1_name, elc2_name)) return sorted(fix_labels, key=utils.natural_keys)
def read_new_psd_mat_file(subject, psd_fname, stim_channel, labels): x = utils.read_mat_file_into_bag(psd_fname) psd = None freqs = [(0, 4), (4, 8), (8, 15), (15, 30), (30, 55), (65, 100)] F = len(freqs) for ind, field in enumerate(['P{}'.format(ind) for ind in range(1, F + 1)]): if psd is None: T, L = x[field].shape psd = np.zeros((F, T, L)) psd[ind, :, :] = x[field] del x time = range(psd.shape[1]) # plt.plot(time, psd[0, 0, :]) # plt.show() out_fol = op.join(BLENDER_ROOT_DIR, subject, 'electrodes') utils.make_dir(out_fol) np.savez(op.join(out_fol, 'psd_{}'.format(stim_channel)), labels=labels, psd=psd, time=time, freqs=freqs)