def example_analysis_for_simulation(): # from these two directories droot = fio.return_data_dir() dsim = os.path.join(droot, '2016-02-03/beta-sweep-000') # create the SimulationPaths() object ddata and read the simulation ddata = fio.SimulationPaths() ddata.read_sim(droot, dsim) # print dir(ddata) # print type(np.zeros(5)) # print ddata.expmt_groups # print ddata.fparam # for key, val in ddata.dfig['testing'].items(): # print key, val # print dir({}) # p_exp = paramrw.ExpParams(ddata.fparam) # print p_exp.p_all['dt'] # # print p_exp.p_all # iterate through experimental groups and do the analysis on individual files, etc. for expmt_group in ddata.expmt_groups: print "experiment group is: %s" % (expmt_group) # print ddata.dfig[expmt_group] flist_param = ddata.file_match(expmt_group, 'param') flist_dpl = ddata.file_match(expmt_group, 'rawdpl') # flist_spk = ddata.file_match(expmt_group, 'rawspk') # fio.prettyprint(flist_spk) # iterate through files in the lists for fparam, fdpl in zip(flist_param, flist_dpl): # print fparam, fdpl gid_dict, p_tr = paramrw.read(fparam) # for key, val in p_tr.items(): # print key, val # fio.prettyprint(p_tr.keys()) # create and load dipole data structure d = dipolefn.Dipole(fdpl) # more or less analysis goes here. # generate a filename for a dipole plot fname_png = ddata.return_filename_example('figdpl', expmt_group, p_tr['Sim_No'], tr=p_tr['Trial']) # print p_tr['Trial'], p_tr['Sim_No'], fname_png # example figure for this pair of files fig = PT_example.FigExample() # plot dipole fig.ax['dipole'].plot(d.t, d.dpl['agg']) fig.ax['dipole'].plot(d.t, d.dpl['L2']) fig.ax['dipole'].plot(d.t, d.dpl['L5']) fig.savepng(fname_png) fig.close()
def praw(ddata): # grab the original dipole from a specific dir dproj = fio.return_data_dir() runtype = 'parallel' # runtype = 'debug' # check on spec data # generates both spec because both are needed here specfn.generate_missing_spec(ddata) # test experiment # expmt_group = ddata.expmt_groups[0] ax_handles = [ 'dpl_agg', 'dpl', 'spec_dpl', 'spk', 'I_soma', 'spec_I', ] # iterate over exmpt groups for expmt_group in ddata.expmt_groups: dfig_dpl = ddata.dfig[expmt_group]['figdpl'] # grab lists of files (l_) l_dpl = ddata.file_match(expmt_group, 'rawdpl') l_spk = ddata.file_match(expmt_group, 'rawspk') l_param = ddata.file_match(expmt_group, 'param') l_spec = ddata.file_match(expmt_group, 'rawspec') l_current = ddata.file_match(expmt_group, 'rawcurrent') l_spec_current = ddata.file_match(expmt_group, 'rawspeccurrent') if runtype == 'parallel': pl = mp.Pool() for f_dpl, f_spk, f_spec, f_current, f_spec_current, f_param \ in zip(l_dpl, l_spk, l_spec, l_current, l_spec_current, l_param): pl.apply_async(pkernel, (dfig_dpl, f_dpl, f_spk, f_spec, f_current, f_spec_current, f_param, ax_handles), callback=cb) pl.close() pl.join() elif runtype == 'debug': for f_dpl, f_spk, f_spec, f_current, f_spec_current, f_param \ in zip(l_dpl, l_spk, l_spec, l_current, l_spec_current, l_param): pkernel(dfig_dpl, f_dpl, f_spk, f_spec, f_current, f_spec_current, f_param, ax_handles)
def average_dipole(dsim): dproj = fio.return_data_dir() ddata = fio.SimulationPaths() ddata.read_sim(dproj, dsim) # grab the first experimental group expmt_group = ddata.expmt_groups[0] flist = ddata.file_match(expmt_group, 'rawdpl') N_dpl = len(flist) # grab the time and the length dpl_time = dipolefn.Dipole(flist[0]).t length_dpl = dipolefn.Dipole(flist[0]).N # preallocation of the total dipole # dpl_agg = np.zeros((N_dpl, length_dpl)) dpl_sum = np.zeros(length_dpl) # the specific dipole to use dpl_specific = 'agg' for f in flist: dpl_f = dipolefn.Dipole(f) dpl_sum = dpl_sum + dpl_f.dpl[dpl_specific] dpl_scaled = dpl_sum * 1e-6 dpl_mean = dpl_scaled / N_dpl print dpl_sum print ' ' print dpl_scaled print ' ' print dpl_mean figure_create(dpl_time, dpl_mean)
def __init__(self, file_input=""): Cmd.__init__(self) self.prompt = '\033[93m' + "[s1] " + '\033[0m' self.intro = "\nThis is the SomatoSensory SHell\n" self.dproj = fio.return_data_dir() self.server_default = self.__check_server() self.f_history = '.s1sh_hist_local' self.ddate = '' self.dlast = [] self.dlist = [] self.dsim = [] self.expmts = [] self.sim_list = [] self.param_list = [] self.var_list = [] self.N_sims = 0 # check to see if file_input is legit if os.path.isfile(file_input): self.file_input = file_input else: # use a default self.file_input = 'param/debug.param' # get initial count of avail processors for subprocess/multiprocessing routines self.nprocs = multiprocessing.cpu_count() # Create the initial datelist self.datelist = clidefs.get_subdir_list(self.dproj) # create the initial paramfile list self.__get_paramfile_list() # set the date, grabs a dlist self.do_setdate(datetime.now().strftime("%Y-%m-%d"))
def pdipole_evoked_aligned(ddata): """ over ALL trials in ALL conditions in EACH experiment appears to be iteration over pdipole_exp2() """ # grab the original dipole from a specific dir dproj = fio.return_data_dir() runtype = 'somethingotherthandebug' # runtype = 'debug' if runtype == 'debug': ddate = '2013-04-08' dsim = 'mubaseline-04-000' i_ctrl = 0 else: ddate = raw_input('Short date directory? ') dsim = raw_input('Sim name? ') i_ctrl = ast.literal_eval(raw_input('Sim number: ')) dcheck = os.path.join(dproj, ddate, dsim) # create a blank ddata structure ddata_ctrl = fio.SimulationPaths() dsim = ddata_ctrl.read_sim(dproj, dcheck) # find the mu_low and mu_high in the expmtgroup names # this means the group names must be well formed for expmt_group in ddata_ctrl.expmt_groups: if 'mu_low' in expmt_group: mu_low_group = expmt_group elif 'mu_high' in expmt_group: mu_high_group = expmt_group # choose the first [0] from the list of the file matches for mu_low fdpl_mu_low = ddata_ctrl.file_match(mu_low_group, 'rawdpl')[i_ctrl] fparam_mu_low = ddata_ctrl.file_match(mu_low_group, 'param')[i_ctrl] fspk_mu_low = ddata_ctrl.file_match(mu_low_group, 'rawspk')[i_ctrl] fspec_mu_low = ddata_ctrl.file_match(mu_low_group, 'rawspec')[i_ctrl] # choose the first [0] from the list of the file matches for mu_high fdpl_mu_high = ddata_ctrl.file_match(mu_high_group, 'rawdpl')[i_ctrl] fparam_mu_high = ddata_ctrl.file_match(mu_high_group, 'param')[i_ctrl] # grab the relevant dipole and renormalize it for mu_low dpl_mu_low = Dipole(fdpl_mu_low) dpl_mu_low.baseline_renormalize(fparam_mu_low) # grab the relevant dipole and renormalize it for mu_high dpl_mu_high = Dipole(fdpl_mu_high) dpl_mu_high.baseline_renormalize(fparam_mu_high) # input feed information s = spikefn.spikes_from_file(fparam_mu_low, fspk_mu_low) _, p_ctrl = paramrw.read(fparam_mu_low) s = spikefn.alpha_feed_verify(s, p_ctrl) s = spikefn.add_delay_times(s, p_ctrl) # find tstop, assume same over all. grab the first param file, get the tstop tstop = paramrw.find_param(fparam_mu_low, 'tstop') # hard coded bin count for now n_bins = spikefn.bin_count(150., tstop) # sim_prefix fprefix = ddata.sim_prefix # create the figure name fname_exp = '%s_dpl_align' % (fprefix) fname_exp_fig = os.path.join(ddata.dsim, fname_exp + '.png') # create one figure comparing across all N_expmt_groups = len(ddata.expmt_groups) ax_handles = [ 'spec', 'input', 'dpl_mu', 'spk', ] f_exp = ac.FigDipoleExp(ax_handles) # plot the ctrl dipoles f_exp.ax['dpl_mu'].plot(dpl_mu_low.t, dpl_mu_low.dpl, color='k') f_exp.ax['dpl_mu'].hold(True) f_exp.ax['dpl_mu'].plot(dpl_mu_high.t, dpl_mu_high.dpl) # function creates an f_exp.ax_twinx list and returns the index of the new feed f_exp.create_axis_twinx('input') # input hist information: predicated on the fact that the input histograms # should be identical for *all* of the inputs represented in this figure # places 2 histograms on two axes (meant to be one axis flipped) hists = spikefn.pinput_hist(f_exp.ax['input'], f_exp.ax_twinx['input'], s['alpha_feed_prox'].spike_list, s['alpha_feed_dist'].spike_list, n_bins) # grab the max counts for both hists # the [0] item of hist are the counts max_hist = np.max([np.max(hists[key][0]) for key in hists.keys()]) ymax = 2 * max_hist # plot the spec here pc = specfn.pspec_ax(f_exp.ax['spec'], fspec_mu_low) # deal with the axes here f_exp.ax['input'].set_ylim((0, ymax)) f_exp.ax_twinx['input'].set_ylim((ymax, 0)) # f_exp.ax[1].set_ylim((0, ymax)) # f_exp.ax[1].set_xlim((50., tstop)) # turn hold on f_exp.ax[dpl_mu].hold(True) # empty list for the aggregate dipole data dpl_exp = [] # go through each expmt # calculation is extremely redundant for expmt_group in ddata.expmt_groups: # a little sloppy, just find the param file # this param file was for the baseline renormalization and # assumes it's the same in all for this expmt_group # also for getting the gid_dict, also assumed to be the same fparam = ddata.file_match(expmt_group, 'param')[0] # general check to see if the aggregate dipole data exists if 'mu_low' in expmt_group or 'mu_high' in expmt_group: # check to see if these files exist flist = ddata.find_aggregate_file(expmt_group, 'dpl') # if no file exists, then find one if not len(flist): calc_aggregate_dipole(ddata) flist = ddata.find_aggregate_file(expmt_group, 'dpl') # testing the first file list_spk = ddata.file_match(expmt_group, 'rawspk') list_s_dict = [spikefn.spikes_from_file(fparam, fspk) for fspk in list_spk] list_evoked = [s_dict['evprox0'].spike_list[0][0] for s_dict in list_s_dict] lines_spk = [f_exp.ax['dpl_mu'].axvline(x=x_val, linewidth=0.5, color='r') for x_val in list_evoked] lines_spk = [f_exp.ax['spk'].axvline(x=x_val, linewidth=0.5, color='r') for x_val in list_evoked] # handle mu_low and mu_high separately if 'mu_low' in expmt_group: dpl_mu_low_ev = Dipole(flist[0]) dpl_mu_low_ev.baseline_renormalize(fparam) f_exp.ax['spk'].plot(dpl_mu_low_ev.t, dpl_mu_low_ev.dpl, color='k') # get xlim stuff t0 = dpl_mu_low_ev.t[0] T = dpl_mu_low_ev.t[-1] elif 'mu_high' in expmt_group: dpl_mu_high_ev = Dipole(flist[0]) dpl_mu_high_ev.baseline_renormalize(fparam) f_exp.ax['spk'].plot(dpl_mu_high_ev.t, dpl_mu_high_ev.dpl, color='b') f_exp.ax['input'].set_xlim(50., tstop) for ax_name in f_exp.ax_handles[2:]: ax.set_xlim((t0, T)) f_exp.savepng(fname_exp_fig) f_exp.close()
dpl_scaled = dpl_sum * 1e-6 dpl_mean = dpl_scaled / N_dpl print dpl_sum print ' ' print dpl_scaled print ' ' print dpl_mean figure_create(dpl_time, dpl_mean) # simple plot of the mean dipole def figure_create(dpl_time, dpl_agg): fig = plt.figure() ax = { 'dpl_agg': fig.add_subplot(1, 1, 1), } # example ax['dpl_agg'].plot(dpl_time, dpl_agg, linewidth=0.5, color='k') fig.savefig('testing_dpl.png', dpi=200) plt.close(fig) if __name__ == '__main__': droot = fio.return_data_dir() dsim = os.path.join(droot, '2015-12-02/tonic_L5Pyr-000') average_dipole(dsim)