示例#1
0
def setupsimdir(f_psim, p_exp, rank):
    ddir = fio.SimulationPaths(dconf['dbase'])
    ddir.create_new_sim(dproj, p_exp.expmt_groups, p_exp.sim_prefix)
    if rank == 0:
        ddir.create_datadir()
        copy_paramfile(ddir.dsim, f_psim, ddir.str_date)
    return ddir
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()
示例#3
0
    def do_load(self, args):
        """Load parameter file and regens all vars
           Date needs to be set correctly for this to work. See 'help setdate'
           Usage example:
           [s1sh] setdate 2013-01-01
           [s1sh] load mucomplex-000

           Running without arguments will load the last modified directory found in the date dir:
           [s1] load
        """
        if not args:
            # attempt to load the most recent in the dproj/ddate
            # find the most recent directory in this folder
            list_d = []

            for dsim_short in os.listdir(self.ddate):
                # check to see if dsim_tmp is actually a dir
                dsim_tmp = os.path.join(self.ddate, dsim_short)

                # append to list along with its modified time (mtime)
                if os.path.isdir(dsim_tmp):
                    list_d.append(
                        (dsim_tmp, time.ctime(os.path.getmtime(dsim_tmp))))

            # sort by mtime
            list_d.sort(key=lambda x: x[1])

            # grab the directory name of the most recent dir
            dcheck = list_d[-1][0]

        else:
            # dir_check is the attempt at creating this directory
            dcheck = os.path.join(self.dproj, self.ddate, args)

        # check existence of the path
        if os.path.exists(dcheck):
            # create blank ddata structure from SimPaths
            self.ddata = fio.SimulationPaths()

            # set dsim after using ddata's readsim method
            self.dsim = self.ddata.read_sim(self.dproj, dcheck)
            self.p_exp = paramrw.ExpParams(self.ddata.fparam)
            print self.ddata.fparam
            self.var_list = paramrw.changed_vars(self.ddata.fparam)

        else:
            print dcheck
            print "Could not find that dir, maybe check your date?"
示例#4
0
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)
示例#5
0
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()