Exemplo n.º 1
0
def praster(f_param, tstop, file_spk, dfig):
    # ddipole is dipole data
    s_dict = spikefn.spikes_from_file(f_param, file_spk)

    s_dict_L2 = {}
    s_dict_L5 = {}
    s_dict_L2_extgauss = {}
    s_dict_L2_extpois = {}
    s_dict_L5_extgauss = {}
    s_dict_L5_extpois = {}

    # clean out s_dict destructively
    for key in s_dict.keys():
        # do this first to remove all extgauss feeds
        if 'extgauss' in key:
            if 'L2_' in key:
                s_dict_L2_extgauss[key] = s_dict.pop(key)

            elif 'L5_' in key:
                s_dict_L5_extgauss[key] = s_dict.pop(key)

        elif 'extpois' in key:
            # s_dict_extpois[key] = s_dict.pop(key)
            if 'L2_' in key:
                s_dict_L2_extpois[key] = s_dict.pop(key)

            elif 'L5_' in key:
                s_dict_L5_extpois[key] = s_dict.pop(key)

        # L2 next
        elif 'L2_' in key:
            s_dict_L2[key] = s_dict.pop(key)

        elif 'L5_' in key:
            s_dict_L5[key] = s_dict.pop(key)

    # split to find file prefix
    file_prefix = file_spk.split('/')[-1].split('.')[0]

    # create standard fig and axes
    f = FigRaster(tstop)
    spikefn.spike_png(f.ax['L2'], s_dict_L2)
    spikefn.spike_png(f.ax['L5'], s_dict_L5)
    spikefn.spike_png(f.ax['L2_extpois'], s_dict_L2_extpois)
    spikefn.spike_png(f.ax['L2_extgauss'], s_dict_L2_extgauss)
    spikefn.spike_png(f.ax['L5_extpois'], s_dict_L5_extpois)
    spikefn.spike_png(f.ax['L5_extgauss'], s_dict_L5_extgauss)

    # testfig.ax0.plot(t_vec, dp_total)
    fig_name = os.path.join(dfig, file_prefix + '.png')

    plt.savefig(fig_name, dpi=300)
    f.close()
Exemplo n.º 2
0
def pfreqpwr_with_hist(file_name, freqpwr_result, f_spk, gid_dict, p_dict,
                       key_types):
    f = ac.FigFreqpwrWithHist()
    f.ax['hist'].hold(True)

    xmin = 50.
    xmax = p_dict['tstop']

    f.ax['freqpwr'].plot(freqpwr_result['freq'], freqpwr_result['avgpwr'])

    # grab alpha feed data. spikes_from_file() from spikefn.py
    s_dict = spikefn.spikes_from_file(gid_dict, f_spk)

    # check for existance of alpha feed keys in s_dict.
    s_dict = spikefn.alpha_feed_verify(s_dict, p_dict)

    # Account for possible delays
    s_dict = spikefn.add_delay_times(s_dict, p_dict)

    # set number of bins (150 bins/1000ms)
    bins = 150. * (xmax - xmin) / 1000.
    hist_data = []

    # Proximal feed
    hist_data.extend(f.ax['hist'].hist(s_dict['alpha_feed_prox'].spike_list,
                                       bins,
                                       range=[xmin, xmax],
                                       color='red',
                                       label='Proximal feed')[0])

    # Distal feed
    hist_data.extend(f.ax['hist'].hist(s_dict['alpha_feed_dist'].spike_list,
                                       bins,
                                       range=[xmin, xmax],
                                       color='green',
                                       label='Distal feed')[0])

    # set hist axis props
    f.set_hist_props(hist_data)

    # axis labels
    f.ax['freqpwr'].set_xlabel('freq (Hz)')
    f.ax['freqpwr'].set_ylabel('power')
    f.ax['hist'].set_xlabel('time (ms)')
    f.ax['hist'].set_ylabel('# spikes')

    # create title
    title_str = ac.create_title(p_dict, key_types)
    f.f.suptitle(title_str)
    # title_str = [key + ': %2.1f' % p_dict[key] for key in key_types['dynamic_keys']]

    f.savepng(file_name)
    f.close()
Exemplo n.º 3
0
def exec_spike_rates(ddata, opts):
    # opts should be:
    # opts_default = {
    #     expmt_group: 'something',
    #     celltype: 'L5_pyramidal',
    # }
    expmt_group = opts['expmt_group']
    celltype = opts['celltype']

    list_f_spk = ddata.file_match(expmt_group, 'rawspk')
    list_f_param = ddata.file_match(expmt_group, 'param')

    # note! this is NOT ignoring first 50 ms
    for fspk, fparam in zip(list_f_spk, list_f_param):
        s_all = spikefn.spikes_from_file(fparam, fspk)
        _, p_dict = paramrw.read(fparam)
        T = p_dict['tstop']

        # check if the celltype is in s_all
        if celltype in s_all.keys():
            s = s_all[celltype].spike_list
            n_cells = len(s)

            # grab all the sp_counts
            sp_counts = np.array([len(spikes_cell) for spikes_cell in s])

            # calc mean and stdev
            sp_count_mean = np.mean(sp_counts)
            sp_count_stdev = np.std(sp_counts)

            # calc rate in Hz, assume T in ms
            sp_rates = sp_counts * 1000. / T
            sp_rate_mean = np.mean(sp_rates)
            sp_rate_stdev = np.std(sp_rates)

            # direct
            sp_rate = sp_count_mean * 1000. / T

            print "Sim No. %i, Trial %i, celltype is %s:" % (p_dict['Sim_No'], p_dict['Trial'], celltype)
            print "  spike count mean is: %4.3f" % sp_count_mean
            print "  spike count stdev is: %4.3f" % sp_count_stdev
            print "  spike rate over %4.3f ms is %4.3f Hz +/- %4.3f" % (T, sp_rate_mean, sp_rate_stdev)
            print "  spike rate over %4.3f ms is %4.3f Hz" % (T, sp_rate)
Exemplo n.º 4
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()
Exemplo n.º 5
0
def pdipole_evoked(dfig, f_dpl, f_spk, f_param, ylim=[]):
    """ for each individual simulation/trial
    """
    gid_dict, p_dict = paramrw.read(f_param)

    # get the spike dict from the files
    s_dict = spikefn.spikes_from_file(f_param, f_spk)
    s = s_dict.keys()
    s.sort()

    # create an empty dict 'spk_unique'
    spk_unique = dict.fromkeys([key for key in s_dict.keys() if key.startswith(('evprox', 'evdist'))])

    for key in spk_unique:
        spk_unique[key] = s_dict[key].unique_all(0)

    # draw vertical lines for each item in this

    # x_dipole is dipole data
    # x_dipole = np.loadtxt(open(f_dpl, 'r'))
    dpl = Dipole(f_dpl)

    # split to find file prefix
    file_prefix = f_dpl.split('/')[-1].split('.')[0]

    # # set xmin value
    # xmin = xlim[0] / p_dict['dt']

    # # set xmax value
    # if xlim[1] == 'tstop':
    #     xmax = p_dict['tstop'] / p_dict['dt']
    # else:
    #     xmax = xlim[1] / p_dict['dt']

    # these are the vectors for now, but this is going to change
    t_vec = dpl.t
    dp_total = dpl.dpl['agg']

    f = ac.FigStd()

    # hold on
    f.ax0.hold(True)

    f.ax0.plot(t_vec, dp_total)

    lines_spk = dict.fromkeys(spk_unique)

    print(spk_unique)

    # plot the lines
    for key in spk_unique:
        print(key, spk_unique[key])
        x_val = spk_unique[key][0]
        lines_spk[key] = plt.axvline(x=x_val, linewidth=0.5, color='r')

    # title_txt = [key + ': {:.2e}' % p_dict[key] for key in key_types['dynamic_keys']]
    title_txt = 'test'
    f.ax0.set_title(title_txt)

    if ylim:
        f.ax0.set_ylim(ylim)

    fig_name = os.path.join(dfig, file_prefix+'.png')

    plt.savefig(fig_name, dpi=300)
    f.close()
Exemplo n.º 6
0
def calc_avgdpl_stimevoked(ddata):
    for expmt_group in ddata.expmt_groups:
        # create the filename
        dexp = ddata.dexpmt_dict[expmt_group]
        fname_short = '%s-%s-dpl' % (ddata.sim_prefix, expmt_group)
        fname_data = os.path.join(dexp, fname_short + '.txt')

        # grab the list of raw data dipoles and assoc params in this expmt
        fdpl_list = ddata.file_match(expmt_group, 'rawdpl')
        param_list = ddata.file_match(expmt_group, 'param')
        spk_list = ddata.file_match(expmt_group, 'rawspk')

        # actual list of Dipole() objects
        dpl_list = [Dipole(fdpl) for fdpl in fdpl_list]
        t_truncated = []

        # iterate through the lists, grab the spike time, phase align the signals,
        # cut them to length, and then mean the dipoles
        for dpl, f_spk, f_param in zip(dpl_list, spk_list, param_list):
            _, p = paramrw.read(f_param)

            # grab the corresponding relevant starting spike time
            s = spikefn.spikes_from_file(f_param, f_spk)
            s = spikefn.alpha_feed_verify(s, p)
            s = spikefn.add_delay_times(s, p)

            # t_evoked is the same for all of the cells in these simulations
            t_evoked = s['evprox0'].spike_list[0][0]

            # attempt to give a 50 ms buffer
            if t_evoked > 50.:
                t0 = t_evoked - 50.
            else:
                t0 = t_evoked

            # truncate the dipole related vectors
            dpl.t = dpl.t[dpl.t > t0]
            dpl.dpl['agg'] = dpl.dpl['agg'][dpl.t > t0]
            t_truncated.append(dpl.t[0])

        # find the t0_max value to compare on other dipoles
        t_truncated -= np.max(t_truncated)

        for dpl, t_adj in zip(dpl_list, t_truncated):
            # negative numbers mean that this vector needs to be shortened by that many ms
            T_new = dpl.t[-1] + t_adj
            dpl.dpl['agg'] = dpl.dpl['agg'][dpl.t < T_new]
            dpl.t = dpl.t[dpl.t < T_new]

            if dpl is dpl_list[0]:
                dpl_total = dpl.dpl['agg']

            else:
                dpl_total += dpl.dpl['agg']

        dpl_mean = dpl_total / len(dpl_list)
        t_dpl = dpl_list[0].t

        # write this data to the file
        with open(fname_data, 'w') as f:
            for t, x in zip(t_dpl, dpl_mean):
                f.write("%03.3f\t%5.4f\n" % (t, x))
Exemplo n.º 7
0
def pkernel(dfig_dpl, f_dpl, f_spk, f_spec, f_current, f_spec_current, f_param, ax_handles, spec_cmap='jet'):
    T = paramrw.find_param(f_param, 'tstop')
    xlim = (50., T)

    # into the pdipole directory, this will plot dipole, spec, and spikes
    # create the axis handle
    f = ac.FigDipoleExp(ax_handles)

    # create the figure name
    fprefix = fio.strip_extprefix(f_dpl) + '-dpl'
    fname = os.path.join(dfig_dpl, fprefix + '.png')

    # grab the dipole
    dpl = dipolefn.Dipole(f_dpl)
    dpl.convert_fAm_to_nAm()

    # plot the dipole to the agg axes
    dpl.plot(f.ax['dpl_agg'], xlim)
    dpl.plot(f.ax['dpl_agg_L5'], xlim)
    # f.ax['dpl_agg_L5'].hold(True)
    # dpl.plot(f.ax['dpl_agg_L5'], xlim, 'L5')

    # plot individual dipoles
    dpl.plot(f.ax['dpl'], xlim, 'L2')
    dpl.plot(f.ax['dpl_L5'], xlim, 'L5')

    # f.ysymmetry(f.ax['dpl'])
    # print dpl.max('L5', (0., -1)), dpl.max('L5', (50., -1))
    # print f.ax['dpl_L5'].get_ylim()
    # f.ax['dpl_L5'].set_ylim((-1e5, 1e5))
    # f.ysymmetry(f.ax['dpl_L5'])

    # plot the current
    I_soma = currentfn.SynapticCurrent(f_current)
    I_soma.plot_to_axis(f.ax['I_soma'], 'L2')
    I_soma.plot_to_axis(f.ax['I_soma_L5'], 'L5')

    # plot the dipole-based spec data
    pc = specfn.pspec_ax(f.ax['spec_dpl'], f_spec, xlim, 'L2')
    f.f.colorbar(pc, ax=f.ax['spec_dpl'])

    pc = specfn.pspec_ax(f.ax['spec_dpl_L5'], f_spec, xlim, 'L5')
    f.f.colorbar(pc, ax=f.ax['spec_dpl_L5'])

    # grab the current spec and plot them
    spec_L2, spec_L5 = data_spec_current = specfn.read(f_spec_current, type='current')
    pc_L2 = f.ax['spec_I'].imshow(spec_L2['TFR'], aspect='auto', origin='upper',cmap=plt.get_cmap(spec_cmap))
    pc_L5 = f.ax['spec_I_L5'].imshow(spec_L5['TFR'], aspect='auto', origin='upper',cmap=plt.get_cmap(spec_cmap))

    # plot the current-based spec data
    # pci = specfn.pspec_ax(f.ax['spec_I'], f_spec_current, type='current')
    f.f.colorbar(pc_L2, ax=f.ax['spec_I'])
    f.f.colorbar(pc_L5, ax=f.ax['spec_I_L5'])

    # get all spikes
    s = spikefn.spikes_from_file(f_param, f_spk)

    # these work primarily because of how the keys are done
    # in the spike dict s (consequence of spikefn.spikes_from_file())
    s_L2 = spikefn.filter_spike_dict(s, 'L2_')
    s_L5 = spikefn.filter_spike_dict(s, 'L5_')

    # resize xlim based on our 50 ms cutoff thingy
    xlim = (50., xlim[1])

    # plot the spikes
    spikefn.spike_png(f.ax['spk'], s_L2)
    spikefn.spike_png(f.ax['spk_L5'], s_L5)

    f.ax['dpl'].set_xlim(xlim)
    # f.ax['dpl_L5'].set_xlim(xlim)
    # f.ax['spec_dpl'].set_xlim(xlim)
    f.ax['spk'].set_xlim(xlim)
    f.ax['spk_L5'].set_xlim(xlim)

    f.savepng(fname)
    f.close()

    return 0
Exemplo n.º 8
0
def aggregate_with_hist(f, ax, f_spec, f_dpl, f_spk, f_param):
    # load param dict
    _, p_dict = paramrw.read(f_param)

    # load spec data from file
    spec = specfn.Spec(f_spec)
    # data_spec = np.load(f_spec)

    # timevec = data_spec['time']
    # freqvec = data_spec['freq']
    # TFR = data_spec['TFR']

    xmin = timevec[0]
    xmax = p_dict['tstop']
    x = (xmin, xmax)

    pc = spec.plot_TFR(ax['spec'], layer='agg', xlim=x)
    # pc = ax['spec'].imshow(TFR, extent=[timevec[0], timevec[-1], freqvec[-1], freqvec[0]], aspect='auto', origin='upper')
    f.f.colorbar(pc,
                 ax=ax['spec'],
                 norm=plt.colors.Normalize(vmin=0, vmax=90000),
                 cmap=plt.get_cmap('jet'))

    # grab the dipole data
    dpl = dipolefn.Dipole(f_dpl)
    dpl.plot(ax['dipole'], x, layer='agg')
    # data_dipole = np.loadtxt(open(f_dpl, 'r'))

    # t_dpl = data_dipole[xmin/p_dict['dt']:, 0]
    # dp_total = data_dipole[xmin/p_dict['dt']:, 1]

    # ax['dipole'].plot(t_dpl, dp_total)

    # grab alpha feed data. spikes_from_file() from spikefn.py
    s_dict = spikefn.spikes_from_file(f_param, f_spk)

    # check for existance of alpha feed keys in s_dict.
    s_dict = spikefn.alpha_feed_verify(s_dict, p_dict)

    # Account for possible delays
    s_dict = spikefn.add_delay_times(s_dict, p_dict)

    # set number of bins (150 bins/1000ms)
    bins = 150. * (xmax - xmin) / 1000.

    hist = {}

    # Proximal feed
    hist['feed_prox'] = ax['feed_prox'].hist(
        s_dict['alpha_feed_prox'].spike_list,
        bins,
        range=[xmin, xmax],
        color='red',
        label='Proximal feed')

    # Distal feed
    hist['feed_dist'] = ax['feed_dist'].hist(
        s_dict['alpha_feed_dist'].spike_list,
        bins,
        range=[xmin, xmax],
        color='green',
        label='Distal feed')

    # for now, set the xlim for the other one, force it!
    ax['dipole'].set_xlim(x)
    ax['spec'].set_xlim(x)
    ax['feed_prox'].set_xlim(x)
    ax['feed_dist'].set_xlim(x)

    # set hist axis props
    f.set_hist_props(ax, hist)

    # axis labels
    ax['spec'].set_xlabel('Time (ms)')
    ax['spec'].set_ylabel('Frequency (Hz)')

    # Add legend to histogram
    for key in ax.keys():
        if 'feed' in key:
            ax[key].legend()
Exemplo n.º 9
0
def ppsth_grid(simpaths):
    # get filename lists in dictionaries of experiments
    dict_exp_param = simpaths.exp_files_of_type('param')
    dict_exp_spk = simpaths.exp_files_of_type('rawspk')

    # recreate the ExpParams object used in the simulation
    p_exp = paramrw.ExpParams(simpaths.fparam[0])

    # need number of lambda vals (cols) and number of sigma vals (rows)
    try:
        N_rows = len(p_exp.p_all['L2Pyr_Gauss_A_weight'])
    except TypeError:
        N_rows = 1

    try:
        N_cols = len(p_exp.p_all['L2Basket_Pois_lamtha'])
    except TypeError:
        N_cols = 1

    tstop = p_exp.p_all['tstop']

    print N_rows, N_cols, tstop

    # ugly but slightly less ugly than the index arithmetic i had planned. muahaha
    f = ac.FigGrid(N_rows, N_cols, tstop)

    # create coordinates for axes
    # this is backward-looking for a reason!
    axes_coords = [
        (j, i) for i, j in it.product(np.arange(N_cols), np.arange(N_rows))
    ]

    if len(simpaths.expnames) != len(axes_coords):
        print "um ... see ppsth.py"

    # assumes a match between expnames and the keys of the previous dicts
    for expname, axis_coord in zip(simpaths.expnames, axes_coords):
        # get the tstop
        exp_param_list = dict_exp_param[expname]
        exp_spk_list = dict_exp_spk[expname]
        gid_dict, p = paramrw.read(exp_param_list[0])
        tstop = p['tstop']
        lamtha = p['L2Basket_Pois_lamtha']
        sigma = p['L2Pyr_Gauss_A_weight']

        # these are total spike dicts for the experiments
        s_L2Pyr_list = []
        # s_L5Pyr_list = []

        # iterate through params and spikes for a given experiment
        for fparam, fspk in zip(dict_exp_param[expname],
                                dict_exp_spk[expname]):
            # get gid dict
            gid_dict, p = paramrw.read(fparam)

            # get spike dict
            s_dict = spikefn.spikes_from_file(gid_dict, fspk)

            # add a new entry to list for each different file assoc with an experiment
            s_L2Pyr_list.append(
                np.array(
                    list(
                        it.chain.from_iterable(
                            s_dict['L2_pyramidal'].spike_list))))
            # s_L5Pyr_list.append(np.array(list(it.chain.from_iterable(s_dict['L5_pyramidal'].spike_list))))

        # now aggregate over all spikes
        s_L2Pyr = np.array(list(it.chain.from_iterable(s_L2Pyr_list)))
        # s_L5Pyr = np.array(list(it.chain.from_iterable(s_L5Pyr_list)))

        # optimize bins, currently unused for comparison reasons!
        N_trials = len(fparam)
        bin_L2 = 250
        # bin_L5 = 120
        # bin_L2 = spikefn.hist_bin_opt(s_L2Pyr, N_trials)
        # bin_L5 = spikefn.hist_bin_opt(s_L5Pyr, N_trials)

        r = axis_coord[0]
        c = axis_coord[1]
        # create standard fig and axes
        f.ax[r][c].hist(s_L2Pyr, bin_L2, facecolor='g', alpha=0.75)

        if r == 0:
            f.ax[r][c].set_title(r'$\lambda_i$ = %d' % lamtha)

        if c == 0:
            f.ax[r][c].set_ylabel(r'$A_{gauss}$ = %.3e' % sigma)
            # f.ax[r][c].set_ylabel(r'$\sigma_{gauss}$ = %d' % sigma)

        # normalize these axes
        y_L2 = f.ax[r][c].get_ylim()
        # y_L2 = f.ax['L2_psth'].get_ylim()

        print expname, lamtha, sigma, r, c, y_L2[1]

        f.ax[r][c].set_ylim((0, 250.))
        # f.ax['L2_psth'].set_ylim((0, 450.))
        # f.ax['L5_psth'].set_ylim((0, 450.))

        # spikefn.spike_png(f.ax['L2'], s_dict_L2)
        # spikefn.spike_png(f.ax['L5'], s_dict_L5)
        # spikefn.spike_png(f.ax['L2_extpois'], s_dict_L2_extpois)
        # spikefn.spike_png(f.ax['L2_extgauss'], s_dict_L2_extgauss)
        # spikefn.spike_png(f.ax['L5_extpois'], s_dict_L5_extpois)
        # spikefn.spike_png(f.ax['L5_extgauss'], s_dict_L5_extgauss)

    # testfig.ax0.plot(t_vec, dp_total)
    fig_name = os.path.join(simpaths.dsim, 'aggregate.eps')

    plt.savefig(fig_name)
    f.close()

    # run the compression
    fio.epscompress(simpaths.dsim, '.eps', 1)
Exemplo n.º 10
0
def ppsth(simpaths):
    # get filename lists in dictionaries of experiments
    dict_exp_param = simpaths.exp_files_of_type('param')
    dict_exp_spk = simpaths.exp_files_of_type('rawspk')

    # assumes a match between expnames and the keys of the previous dicts
    for expname in simpaths.expnames:
        # get the tstop
        exp_param_list = dict_exp_param[expname]
        exp_spk_list = dict_exp_spk[expname]
        gid_dict, p = paramrw.read(exp_param_list[0])
        # gid_dict, p = paramrw.read(dict_exp_param[expname][0])
        tstop = p['tstop']

        # get representative spikes
        s_dict = spikefn.spikes_from_file(gid_dict, exp_spk_list[0])

        s_dict_L2 = {}
        s_dict_L5 = {}
        s_dict_L2_extgauss = {}
        s_dict_L2_extpois = {}
        s_dict_L5_extgauss = {}
        s_dict_L5_extpois = {}

        # clean out s_dict destructively
        # borrowed from praster
        for key in s_dict.keys():
            # do this first to remove all extgauss feeds
            if 'extgauss' in key:
                if 'L2_' in key:
                    s_dict_L2_extgauss[key] = s_dict.pop(key)

                elif 'L5_' in key:
                    s_dict_L5_extgauss[key] = s_dict.pop(key)

            elif 'extpois' in key:
                # s_dict_extpois[key] = s_dict.pop(key)
                if 'L2_' in key:
                    s_dict_L2_extpois[key] = s_dict.pop(key)

                elif 'L5_' in key:
                    s_dict_L5_extpois[key] = s_dict.pop(key)

            # L2 next
            elif 'L2_' in key:
                s_dict_L2[key] = s_dict.pop(key)

            elif 'L5_' in key:
                s_dict_L5[key] = s_dict.pop(key)

        # these are total spike dicts for the experiments
        s_L2Pyr_list = []
        s_L5Pyr_list = []

        # iterate through params and spikes for a given experiment
        for fparam, fspk in zip(dict_exp_param[expname],
                                dict_exp_spk[expname]):
            # get gid dict
            gid_dict, p = paramrw.read(fparam)

            # get spike dict
            s_dict = spikefn.spikes_from_file(gid_dict, fspk)

            # add a new entry to list for each different file assoc with an experiment
            s_L2Pyr_list.append(
                np.array(
                    list(
                        it.chain.from_iterable(
                            s_dict['L2_pyramidal'].spike_list))))
            s_L5Pyr_list.append(
                np.array(
                    list(
                        it.chain.from_iterable(
                            s_dict['L5_pyramidal'].spike_list))))

        # now aggregate over all spikes
        s_L2Pyr = np.array(list(it.chain.from_iterable(s_L2Pyr_list)))
        s_L5Pyr = np.array(list(it.chain.from_iterable(s_L5Pyr_list)))

        # optimize bins, currently unused for comparison reasons!
        N_trials = len(fparam)
        # bin_L2 = 120
        # bin_L5 = 120
        bin_L2 = spikefn.hist_bin_opt(s_L2Pyr, N_trials)
        bin_L5 = spikefn.hist_bin_opt(s_L5Pyr, N_trials)

        # create standard fig and axes
        f = ac.FigPSTH(400.)
        f.ax['L2_psth'].hist(s_L2Pyr, bin_L2, facecolor='g', alpha=0.75)
        f.ax['L5_psth'].hist(s_L5Pyr, bin_L5, facecolor='g', alpha=0.75)

        # normalize these axes
        y_L2 = f.ax['L2_psth'].get_ylim()
        y_L5 = f.ax['L5_psth'].get_ylim()

        print y_L2, y_L5

        # f.ax['L2_psth'].set_ylim((0, 450.))
        # f.ax['L5_psth'].set_ylim((0, 450.))

        spikefn.spike_png(f.ax['L2'], s_dict_L2)
        spikefn.spike_png(f.ax['L5'], s_dict_L5)
        spikefn.spike_png(f.ax['L2_extpois'], s_dict_L2_extpois)
        spikefn.spike_png(f.ax['L2_extgauss'], s_dict_L2_extgauss)
        spikefn.spike_png(f.ax['L5_extpois'], s_dict_L5_extpois)
        spikefn.spike_png(f.ax['L5_extgauss'], s_dict_L5_extgauss)

        # # testfig.ax0.plot(t_vec, dp_total)
        fig_name = os.path.join(simpaths.dsim, expname + '.eps')

        plt.savefig(fig_name)
        f.close()

    # run the compression
    fio.epscompress(simpaths.dsim, '.eps', 1)