Esempio n. 1
0
def test_two_stim_make_neuron_list():
    # Load data
    raw_behavior_summary = mat4py.loadmat('TB41_behavior_summary.mat')
    raw_encoding_struct = mat4py.loadmat('TB41_encoding_structs.mat')

    # Extract structures from the raw data
    one, two, three, four, correct, incorrect, left, right, prev_corr, prev_incorr, \
    stim_onset_per_trial = utils.get_multiple_struct_fields_mat4py(raw_behavior_summary,
                                                                   ['one', 'two', 'three', 'four', 'correct',
                                                                    'incorrect',
                                                                    'left', 'right', 'prev_right', 'prev_wrong',
                                                                    'stim_onset_per_trial'])

    # Being careful about one-indexing
    for i in [one, two, three, four, correct, incorrect, prev_corr, prev_incorr, left, right]:
        i -= 1

    neural_matmat, predall_matmat = \
        utils.get_multiple_struct_fields_mat4py(raw_encoding_struct, ['neural_matmat', 'predall_matmat'])

    # Make an experiment object to capture the experiment
    exp_dict = dict(l_trials=left, r_trials=right, one_diff=one, two_diff=two, three_diff=three,
                    four_diff=four, correct=correct, incorrect=incorrect, prev_corr=prev_corr,
                    prev_incorr=prev_incorr)
    exp = neuron_utils.Experiment(exp_dict)

    # Make a neuron group
    neurons = neuron_group_utils.make_neuron_list(raw_encoding_struct, 'neural_act_mat', np.arange(180), exp)

    for neuron in neurons:
        neuron.align_activity(stim_onset_per_trial, [-5, 18])
    neuron_group = neuron_group_utils.NeuronGroup(neurons)

    assert len(neuron_group.neurons) == 180
    assert neuron_group.n_neurons == 180
    assert neuron_group.neurons[0].aligned_activity.shape == (173, 24)
Esempio n. 2
0
#dates = ['20190724', '20190725', '20190726', '20190727', '20190730', '20190801', '20190806', '20190807']
align_by = 'stim'
split_by = 'four-way'
plot_group = False
to_plot_examples = True

for date in dates:
    neuron_groups = []
    print(date)
    summary_fname = animal + '_' + date + '_behavior_summary.mat'
    encoding_fname = animal + '_' + date + '_encoding_structs.mat'
    epoch_fname = animal + '_' + date + '_epochs.mat'

    # Make an experiment object to capture the experiment
    exp_dict = dict(rate=samp_rate, window=window, animal=animal)
    exp = neuron_utils.Experiment(exp_dict)

    subgroup = utils.make_neuron_group(encoding_fname,
                                       epoch_fname,
                                       exp,
                                       align_by=align_by)

    neuron_groups.append(subgroup)

    neuron_group = neuron_group_utils.combine_groups_by_neurons(neuron_groups)
    print('Number of neurons: ', neuron_group.n_neurons)
    print('Number of trials: ', neuron_group.neurons[0].ntrials)

    # Extract structures from the raw data
    raw_behavior_summary = mat4py.loadmat(summary_fname)
    correct, incorrect, left_stim, right_stim, left_choice, right_choice, opp_contrast = utils.get_multiple_struct_fields_mat4py(
import neuron_utils
import os
import neuron_group_utils

if os.environ['COMPUTERNAME'] == 'DESKTOP-FN1P6HD':
    filedir = 'C:/Users/Sur lab/Documents/RafiqAnalysis'
elif os.environ['COMPUTERNAME'] == 'homecomputer':
    filedir = 'C:/Users/Le/Dropbox (MIT)/Sur/For Nhat'
raw_data = mat4py.loadmat(filedir + '/error_trial_data_permuted_20190715.mat')
c_corr_all = raw_data['c_corr_all']
c_incorr_all = raw_data['c_incorr_all']
i_corr_all = raw_data['i_corr_all']
i_incorr_all = raw_data['i_incorr_all']

# Make neuron groups
exp = neuron_utils.Experiment(dict(l_trials=[0], r_trials=[1]))
neur_group_c_corr = neuron_group_utils.make_neuron_group(c_corr_all, exp)
session_list = neur_group_c_corr.get_session_list()
neur_group_i_corr = neuron_group_utils.make_neuron_group(i_corr_all, exp)
neur_group_c_incorr = neuron_group_utils.make_neuron_group(c_incorr_all, exp)
neur_group_i_incorr = neuron_group_utils.make_neuron_group(
    i_incorr_all, exp, session_list)

# Plot
#neur_group_c_corr.plot_all_means(sort=True, style='heatmap')
#neur_group_c_incorr.plot_all_means(sort=True, style='heatmap')
#neur_group_i_corr.plot_all_means(sort=True, style='heatmap')
#neur_group_i_incorr.plot_all_means(sort=True, style='heatmap')

# Combine groups
neur_correct = neuron_group_utils.combine_groups_by_trials(