コード例 #1
0
def analysis_typespecific(ddata, opts=None):
    # def analysis_typespecific(ddata, p_exp, opts=None):
    # 'opts' input are the options in a dictionary
    # if opts is defined, then make it well formed
    # the valid keys of opts are in list_opts
    opts_run = {
        'type': 'dpl_laminar',
        'f_max': 100.,
        'save_data': 0,
        'runtype': 'parallel',
    }
    # check if opts is supplied
    if opts:
        # assume opts is a dict
        # iterate through provided opts and assign if the key is present
        # otherwise, ignore
        for key, val in opts.items():
            if key in opts_run.keys():
                opts_run[key] = val
    # preallocate lists for use below
    list_param, list_ts, list_spec = [], [], []

    # aggregrate all files from individual expmts into lists
    expmt_group = ddata.expmt_groups[0]
    # get the list of params
    # returns an alpha SORTED list
    # add to list of all param files
    param_tmp = ddata.file_match(expmt_group, 'param')
    print('param_tmp:', param_tmp)
    list_param.extend(param_tmp)
    # get exp prefix for each trial in this expmt group
    list_exp_prefix = [fio.strip_extprefix(fparam) for fparam in param_tmp]
    # get the list of dipoles and create spec output filenames
    if opts_run['type'] in ('dpl', 'dpl_laminar'):
        list_ts.extend(ddata.file_match(expmt_group, 'rawdpl'))
        list_spec.extend([
            ddata.create_filename(expmt_group, 'rawspec', exp_prefix)
            for exp_prefix in list_exp_prefix
        ])
    elif opts_run['type'] == 'current':
        list_ts.extend(ddata.file_match(expmt_group, 'rawcurrent'))
        list_spec.extend(
            ddata.create_filename(expmt_group, 'rawspeccurrent',
                                  list_exp_prefix[-1]))
    # create list of spec output names
    # this is sorted because of file_match
    # exp_prefix_list = [fio.strip_extprefix(fparam) for fparam in list_param]

    # perform analysis on all runs from all exmpts at same time
    if opts_run['type'] == 'current':
        # list_spec.extend([ddata.create_filename(expmt_group, 'rawspeccurrent', exp_prefix) for exp_prefix in exp_prefix_list])
        if opts_run['runtype'] == 'parallel':
            pl = mp.Pool()
            for fparam, fts, fspec in zip(list_param, list_ts, list_spec):
                pl.apply_async(spec_current_kernel,
                               (fparam, fts, fspec, opts_run['f_max']))
            pl.close()
            pl.join()
        elif opts_run['runtype'] == 'debug':
            for fparam, fts, fspec in zip(list_param, list_ts, list_spec):
                spec_current_kernel(fparam, fts, fspec, opts_run['f_max'])
    elif opts_run['type'] == 'dpl_laminar':
        # these should be OUTPUT filenames that are being generated
        # list_spec.extend([ddata.create_filename(expmt_group, 'rawspec', exp_prefix) for exp_prefix in exp_prefix_list])
        # also in this case, the original spec results will be overwritten
        # and replaced by laminar specific ones and aggregate ones
        # in this case, list_ts is a list of dipole
        if opts_run['runtype'] == 'parallel':
            pl = mp.Pool()
            for fparam, fts, fspec in zip(list_param, list_ts, list_spec):
                pl.apply_async(spec_dpl_kernel,
                               (fparam, fts, fspec, opts_run['f_max']))
            pl.close()
            pl.join()
        elif opts_run['runtype'] == 'debug':
            # spec_results_L2 and _L5
            for fparam, fts, fspec in zip(list_param, list_ts, list_spec):
                spec_dpl_kernel(fparam, fts, fspec, opts_run['f_max'])
コード例 #2
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