def make_lda_features_from_spks(SpkFileNames): "all files should have been generated by the same parameters" clu_means, clu_covs = [], [] pars0 = n_ch, sample_rate, s_before, s_after = get_pars_from_xml2( switch_ext(SpkFileNames[0], "xml")) print "parameters: %s" % str(pars0[1:]) for fname in SpkFileNames: pars = get_pars_from_xml2(switch_ext(fname, "xml")) if pars[1:] != pars0[1:]: print "%s has wrong parameters. skipping" % fname continue n_ch = pars[0] X_nsc = read_spk(fname, n_ch, s_after + s_before) Clu_n = read_clu(switch_ext(fname, "clu.1")) for i_ch in xrange(n_ch): Mean_ms, Cov_mss, Count_m = get_clu_params(Clu_n, X_nsc[:, :, i_ch]) for mean, cov, count in zip(Mean_ms, Cov_mss, Count_m): if count > 100: clu_means.append(mean) clu_covs.append(cov) Feat_ss = compute_feats_lda(clu_means, clu_covs) save_feature_info(Feat_ss, s_before, s_after, sample_rate)
def plot_probe(ProbeFileName,output_dir=None): load_probe(ProbeFileName) if PROBE_DIM == 0: x = [np.cos(2*np.pi*i_site/N_SITES) for i_site in xrange(N_SITES)] y = [np.sin(2*np.pi*i_site/N_SITES) for i_site in xrange(N_SITES)] elif PROBE_DIM == 1: x = [site.x for site in PROBE_SITES] y = [0 for site in PROBE_SITES] elif PROBE_DIM == 2: x = [site.x for site in PROBE_SITES] y = [site.y for site in PROBE_SITES] #if max2min(x) > max2min(y): #figsize = (6,1+max2min(y)/max2min(x)*6) #else: #figsize = (1+max2min(x)/max2min(y)*6,6) plt.plot(x,y,'go') ax = plt.gca() ax.set_xticks([]) ax.set_yticks([]) for ind_src,ind_targ in edges(PROBE_GRAPH): ax.add_line(matplotlib.lines.Line2D([x[ind_src],x[ind_targ]],[y[ind_src],y[ind_targ]],lw=1)) for ind_node in nodes(PROBE_GRAPH): site = PROBE_SITES[ind_node] ax.text(x[ind_node],y[ind_node],site.name,color='r') img_filename = join(output_dir or dirname(ProbeFileName),switch_ext(basename(ProbeFileName),"png")) print("Saving figure as %s"%abspath(img_filename)) plt.savefig(img_filename)
def get_dat_pars(DatFileName): xmlpath = switch_ext(DatFileName, 'xml') if os.path.exists(xmlpath): n_ch_dat, sample_rate = get_pars_from_xml(xmlpath) else: n_ch_dat, sample_rate = get_pars_from_prompt() write_xml(n_ch_dat, 0, 0, sample_rate, xmlpath) print("writing parameters in xml file %s" % xmlpath) return n_ch_dat, sample_rate
def get_dat_pars(DatFileName): xmlpath = switch_ext(DatFileName,'xml') if os.path.exists(xmlpath): n_ch_dat,sample_rate = get_pars_from_xml(xmlpath) else: n_ch_dat,sample_rate = get_pars_from_prompt() write_xml(n_ch_dat,0,0,sample_rate,xmlpath) print("writing parameters in xml file %s"%xmlpath) return n_ch_dat,sample_rate
def make_lda_features_from_spks(SpkFileNames): "all files should have been generated by the same parameters" clu_means, clu_covs = [],[] pars0 = n_ch,sample_rate,s_before,s_after = get_pars_from_xml2(switch_ext(SpkFileNames[0],"xml")) print "parameters: %s"%str(pars0[1:]) for fname in SpkFileNames: pars = get_pars_from_xml2(switch_ext(fname,"xml")) if pars[1:] != pars0[1:]: print "%s has wrong parameters. skipping"%fname continue n_ch = pars[0] X_nsc = read_spk(fname,n_ch,s_after+s_before) Clu_n = read_clu(switch_ext(fname,"clu.1")) for i_ch in xrange(n_ch): Mean_ms, Cov_mss, Count_m = get_clu_params(Clu_n,X_nsc[:,:,i_ch]) for mean,cov,count in zip(Mean_ms, Cov_mss, Count_m): if count > 100: clu_means.append(mean) clu_covs.append(cov) Feat_ss = compute_feats_lda(clu_means,clu_covs) save_feature_info(Feat_ss,s_before,s_after,sample_rate)
def plot_probe(ProbeFileName, output_dir=None): load_probe(ProbeFileName) if PROBE_DIM == 0: x = [ np.cos(2 * np.pi * i_site / N_SITES) for i_site in xrange(N_SITES) ] y = [ np.sin(2 * np.pi * i_site / N_SITES) for i_site in xrange(N_SITES) ] elif PROBE_DIM == 1: x = [site.x for site in PROBE_SITES] y = [0 for site in PROBE_SITES] elif PROBE_DIM == 2: x = [site.x for site in PROBE_SITES] y = [site.y for site in PROBE_SITES] #if max2min(x) > max2min(y): #figsize = (6,1+max2min(y)/max2min(x)*6) #else: #figsize = (1+max2min(x)/max2min(y)*6,6) plt.plot(x, y, 'go') ax = plt.gca() ax.set_xticks([]) ax.set_yticks([]) for ind_src, ind_targ in edges(PROBE_GRAPH): ax.add_line( matplotlib.lines.Line2D([x[ind_src], x[ind_targ]], [y[ind_src], y[ind_targ]], lw=1)) for ind_node in nodes(PROBE_GRAPH): site = PROBE_SITES[ind_node] ax.text(x[ind_node], y[ind_node], site.name, color='r') img_filename = join(output_dir or dirname(ProbeFileName), switch_ext(basename(ProbeFileName), "png")) print("Saving figure as %s" % abspath(img_filename)) plt.savefig(img_filename)