def main():

    # Single field
    simdata = load_pickle('results/sim/raw/squarematch.pickle')
    single_field_preprocess_Romani(
        simdata, save_pth='results/sim/singlefield_df.pickle')

    # # Pair field
    simdata = load_pickle('results/sim/raw/squarematch.pickle')
    pair_field_preprocess_Romani(simdata,
                                 save_pth='results/sim/pairfield_df.pickle')
Пример #2
0
def main():
    save_dir = 'result_plots/sim'
    os.makedirs(save_dir, exist_ok=True)

    # single_simdf = load_pickle('results/sim/singlefield_df.pickle')
    # singlefield_analysis_Romani(single_simdf, save_dir=save_dir)

    pair_simdf = load_pickle('results/sim/pairfield_df.pickle')
    pair_simdf['border'] = (pair_simdf['border1'] & pair_simdf['border2'])
    pairfield_analysis_Romani(pair_simdf, save_dir=save_dir)
Пример #3
0
def calc_preprocessing_info():
    # Get
    # (1) Straightness distribution of passes,
    # (2) Average spike counts per field per session
    # (3) Pass counts per passes

    simdata = load_pickle('results/network_proj/sim_result.pickle')
    Indata = simdata['Indata']
    SpikeData = simdata['SpikeData']
    NeuronPos = simdata['NeuronPos']

    all_spikecounts = []
    all_straightness = []
    radius = 10
    minpasstime = 0.6
    unique_neurons = SpikeData['neuronidx'].unique()
    num_neurons = unique_neurons.shape[0]
    for idx, nidx in enumerate(unique_neurons):

        print('%d/%d'%(idx, num_neurons))

        spks_count = SpikeData[SpikeData.neuronidx == nidx].shape[0]
        all_spikecounts.append(spks_count)

        # Get tok
        neuronx, neurony = NeuronPos.loc[nidx, ['neuronx', 'neurony']]
        dist = np.sqrt((neuronx - Indata.x) ** 2 + (neurony - Indata.y) ** 2)
        tok = dist < radius
        all_passidx = segment_passes(tok.to_numpy())

        for pid1, pid2 in all_passidx:
            pass_angles = Indata.loc[pid1:pid2, 'angle'].to_numpy()
            pass_t = Indata.loc[pid1:pid2, 't'].to_numpy()

            # Pass duration threshold
            if pass_t.shape[0] < 5:
                continue
            if (pass_t[-1] - pass_t[0]) < minpasstime:
                continue

            straightness = compute_straightness(pass_angles)
            all_straightness.append(straightness)

    print('Average spk count per field = %0.2f'% (np.mean(all_spikecounts)))
    print('0.1 quantile of straightness = %0.2f'% (np.quantile(all_straightness, 0.1)))
Пример #4
0
def sanity_check():

    simdata = load_pickle('results/network_proj/sim_result.pickle')
    indf = simdata['Indata']
    spdf = simdata['SpikeData']
    ntun = simdata['NeuronPos']
    np.random.seed(1)
    selected_nidxs = np.random.choice(spdf['neuronidx'].unique(), 4)

    fig, ax = plt.subplots(2, 2, figsize=(10, 10))
    ax = ax.ravel()

    fig_den, ax_den = plt.subplots(2, 2, figsize=(10, 10))
    ax_den = ax_den.ravel()

    for idx, nidx in enumerate(selected_nidxs):
        spdf_each = spdf[spdf.neuronidx == nidx]

        neu_x, neu_y = ntun.loc[nidx, ['neuronx', 'neurony']]
        tidxsp = spdf_each.tidxsp
        xsp = indf.x[tidxsp].to_numpy()
        ysp = indf.y[tidxsp].to_numpy()

        # Scatter
        ax[idx].plot(indf.x, indf.y)
        ax[idx].scatter(xsp, ysp, c='r', marker='.', alpha=0.5)
        ax[idx].scatter(neu_x, neu_y, c='k', marker='x')

        # Density
        xx, yy, zz = linear_gauss_density(xsp, ysp, 5, 5, 500, 500, (-40, 40), (-40, 40))
        ax_den[idx].pcolormesh(xx, yy, zz)

        ax_den[idx].scatter(neu_x, neu_y, c='k', marker='x')

    fig.savefig('result_plots/network_proj/sanity_check.png')
    fig_den.savefig('result_plots/network_proj/sanity_check_den.png')
def main():
    input_df_pth = 'data/emankindata_processed_withwave.pickle'
    output_dict_dir = 'results/sim/raw'
    output_dict_name = 'squarematch.pickle'

    print('Load experiment data')
    input_df = pd.read_pickle(input_df_pth)

    print('Extract experiment trajectory')
    t, pos, _ = load_exp_trajectory(input_df)

    print('Generate setting of Square environment')
    neuron_theta, I_E, I_phase, ensemble_dict = gen_setting(t, pos, w_cos_scaled, gt_cos_scaled)

    print('Simulate Squarematch environment')
    simdata = simulate(t, pos, neuron_theta, I_E, I_phase, ensemble_dict, max_duration=None)

    print('Save simulated results')
    with open(join(output_dict_dir, output_dict_name), 'wb') as fh:
        pickle.dump(simdata, fh)

    print('Sanity check')
    sanity_check(data=load_pickle(join(output_dict_dir, output_dict_name)),
                 save_pth=join(output_dict_dir, output_dict_name + '.png'))
    fig_paireg.tight_layout()
    fig_paireg.subplots_adjust(wspace=0.01, hspace=0.05)
    fig_paireg.savefig(os.path.join(plot_dir, 'examples_pair.%s' % (figext)), dpi=dpi)


    fig_kld.tight_layout()
    fig_kld.subplots_adjust(wspace=0.05, hspace=0.2)
    fig_kld.savefig(os.path.join(plot_dir, 'examples_kld.%s' % (figext)), dpi=dpi)


if __name__ == '__main__':
    # Experiment's data preprocessing
    data_pth = 'data/emankindata_processed_withwave.pickle'
    save_pth = 'results/emankin/pairfield_df.pickle'

    expdf = load_pickle(data_pth)
    pair_field_preprocess_exp(expdf, vthresh=5, sthresh=3, NShuffles=200, save_pth=save_pth)



    # # Plotting
    # plot_dir = 'result_plots/pair_fields/'

    # plot_pair_examples(expdf, vthresh=5, sthresh=3, plot_dir=plot_dir)


    # simdata = load_pickle('results/sim/raw/squarematch.pickle')
    # pair_field_preprocess_sim(simdata, save_pth='results/sim/pair_field/pairfield_df_square2.pickle')

                             dpi=dpi)
                plt.close()

                fieldid[ca] += 1


if __name__ == '__main__':
    rawdf_pth = 'data/emankindata_processed_withwave.pickle'
    save_pth = 'results/emankin/singlefield_df_NoShuffle.pickle'

    # df = load_pickle(rawdf_pth)
    # single_field_preprocess_exp(df, vthresh=5, sthresh=3, save_pth=save_pth)

    # # # Plotting
    plot_dir = 'result_plots/single_field/'
    df = load_pickle(rawdf_pth)
    plot_placefield_examples(df, plot_dir)

    # # Simulation
    # simdata = load_pickle('results/sim/raw/squarematch.pickle')
    # single_field_preprocess_sim(simdata, save_pth='results/sim/singlefield_df_square2.pickle')

    # # Network project
    # simdata = load_pickle('results/network_proj/sim_result_dwdt.pickle')
    # single_field_preprocess_networks(simdata, save_pth='results/network_proj/singlefield_df_networkproj_dwdt.pickle')

    # df = load_pickle(rawdf_pth)
    # precession_dist_inspection(df)
    # test_pass_criteria(df)
    # test_pass_minbins()