# Envelope for plots, 95% confidence interval
ci = 95

## Select units
duration = 2
units = exp.select_units(
    min_depth=0,
    max_depth=1200,
    #min_spike_width=0.4,
    name="cortex0-1200")

# get spike rate for left & right visual stim.
stim_left = exp.align_trials(
    ActionLabels.naive_left,
    Events.led_on,
    'spike_rate',
    units=units,
    duration=duration,
)
stim_right = exp.align_trials(
    ActionLabels.naive_right,
    Events.led_on,
    'spike_rate',
    units=units,
    duration=duration,
)

# side of PPC recording
sides = [
    "left",
    "right",
#for session in range(len(exp)):
#    fig = spike_times.per_unit_histogram(stim, session, bin_ms=bin_ms, duration=duration)
#    name = exp[session].name
#    plt.suptitle(f'Session {name} - per-unit across-trials spike times (aligned to stim push)')
#    save(f'unit_spike_histograms_stim_{duration}s_{name}_in_brain.png')
#
#for session in range(len(exp)):
#    fig = spike_times.per_trial_histogram(stim, session, bin_ms=bin_ms, duration=duration)
#    name = exp[session].name
#    plt.suptitle(f'Session {name} - per-trial across-unit spike times (aligned to stim push)')
#    save(f'trial_spike_histograms_stim_{duration}s_{name}_in_brain.png')


stim_miss = exp.align_trials(
    ActionLabels.uncued_laser_nopush,
    Events.laser_onset,
    'spike_times',
    duration=duration,
)

for session in range(len(exp)):
    fig = spike_times.per_unit_histogram(stim_miss, session, bin_ms=bin_ms, duration=duration)
    name = exp[session].name
    plt.suptitle(f'Session {name} - per-unit across-trials spike times (aligned to nopush stim)')
    utils.save(fig_dir / f'unit_spike_histograms_stim-miss_{duration}s_{name}_in_brain')

for session in range(len(exp)):
    fig = spike_times.per_trial_histogram(stim_miss, session, bin_ms=bin_ms, duration=duration)
    name = exp[session].name
    plt.suptitle(f'Session {name} - per-trial across-unit spike times (aligned to nopush stim)')
    utils.save(fig_dir / f'trial_spike_histograms_stim-miss_{duration}s_{name}_in_brain')
Esempio n. 3
0
# Envelope for plots, 95% confidence interval
ci = 95

## Select units
duration = 2
units = exp.select_units(
    min_depth=0,
    max_depth=1200,
    #min_spike_width=0.4,
    name="cortex0-1200")

# get spike rate for left & right visual stim.
stim_left = exp.align_trials(
    ActionLabels.miss_left,
    Events.led_on,
    'spike_rate',
    units=units,
    duration=duration,
)

# side of PPC recording
sides = [
    "left",
    "right",
]

ipsi_ppc_list = []
contra_m2_list = []
contra_ppc_list = []

for session in range(len(exp)):
Esempio n. 4
0
exp = Experiment(
    mice,
    LeverPush,
    '~/duguidlab/thalamus_paper/Npx_data',
    '~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)

sns.set(font_scale=0.4)
fig_dir = Path('~/duguidlab/visuomotor_control/figures')
duration = 4

## Spike rate plots
hits = exp.align_trials(
    ActionLabels.cued_shutter_push_full,
    Events.back_sensor_open,
    'spike_rate',
    duration=duration,
)

stim = exp.align_trials(
    ActionLabels.uncued_laser_push_full,
    Events.back_sensor_open,
    'spike_rate',
    duration=duration,
)

stim_miss = exp.align_trials(
    ActionLabels.uncued_laser_nopush,
    Events.laser_onset,
    'spike_rate',
    duration=duration,
Esempio n. 5
0
    mice,
    LeverPush,
    '~/duguidlab/thalamus_paper/Npx_data',
    '~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)

sns.set(font_scale=0.4)
fig_dir = Path('~/duguidlab/visuomotor_control/figures')
duration = 2

_, axes = plt.subplots(len(exp), 1)

hits = exp.align_trials(
    ActionLabels.cued_shutter_push_full,
    Events.back_sensor_open,
    'spike_rate',
    duration=duration,
    min_depth=500,
    max_depth=1200,
)

for session in range(len(exp)):
    name = exp[session].name
    data = hits[session].stack()
    norm = StandardScaler().fit(data).transform(data)
    num_components = norm.shape[1]
    pca = PCA(n_components=num_components)
    # probably don't need to transform
    pc = pca.fit(norm).transform(norm)

    axes[session].plot(np.cumsum(pca.explained_variance_ratio_))
    axes[session].plot([0, num_components], [0, 1], '--', linewidth=0.4)
}

area = ["M2", "PPC"][rec_num]

## Spike rate plots for all visual stimulations

#hits = exp.align_trials(
    #ActionLabels.correct_left | correct_right,
    #Events.led_on,
    #'spike_rate',
    #duration=duration,
#)

stim_all = exp.align_trials(
    ActionLabels.naive_left | ActionLabels.naive_right,
    Events.led_on,
    'spike_rate',
    **select,
)

## Spike rate plots for short & long visual stimulation separately

#stim_short = exp.align_trials(
#    ActionLabels.naive_short,
#    Events.led_on,
#    'spike_rate',
#    **select,
#)
#
#
#stim_long = exp.align_trials(
#    ActionLabels.naive_long,
    '~/duguidlab/Direction_Sensitivity/Data/Neuropixel',
    #'~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)


sns.set(font_scale=0.4)
fig_dir = Path('~/duguidlab/visuomotor_control/figures/DS')
duration = 4
rec_num = 0


## Spike rate plots
pushes = exp.align_trials(
    ActionLabels.rewarded_push,
    Events.back_sensor_open,
    'spike_rate',
    duration=duration,
    uncurated=True,
)

pulls = exp.align_trials(
    ActionLabels.rewarded_pull,
    Events.front_sensor_open,
    'spike_rate',
    duration=duration,
    uncurated=True,
)

for session in range(len(exp)):
    # per unit
    fig = spike_rate.per_unit_spike_rate(pushes[session][rec_num], ci='sd')
Esempio n. 8
0
]

exp = Experiment(
    mice,
    LeverPush,
    '~/duguidlab/thalamus_paper/Npx_data',
    '~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)

sns.set(font_scale=0.4)
fig_dir = Path('~/duguidlab/visuomotor_control/figures/srf_grant')

if rates_not_rasters:
    firing_rates = exp.align_trials(
        ActionLabels.rewarded_push,
        Events.back_sensor_open,
        'spike_rate',
        duration=duration,
    )

    # IPN
    ses = exp[ses_ipn_gpi].name
    spike_rate.per_unit_spike_rate(firing_rates[ses_ipn_gpi][ipn], ci='sd')
    plt.suptitle(f'IPN - per-unit across-trials firing rate (aligned to push)')
    utils.save(fig_dir / f'IPN_unit_spike_rate_{duration}s_{ses}.png')

    # GPi
    spike_rate.per_unit_spike_rate(firing_rates[ses_ipn_gpi][gpi], ci='sd')
    plt.suptitle(f'GPi - per-unit across-trials firing rate (aligned to push)')
    utils.save(fig_dir / f'GPi_unit_spike_rate_{duration}s_{ses}.png')

    # MTh
Esempio n. 9
0
mice = [
    'C57_1288723',
    'C57_1288727',
]

exp = Experiment(
    mice,
    LeverPush,
    '~/duguidlab/thalamus_paper/Npx_data',
    '~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)

hit_times = exp.align_trials(
    ActionLabels.cued_shutter_push_full,
    Events.back_sensor_open,
    'spike_times',
    duration=4,
)

stim_times = exp.align_trials(
    ActionLabels.uncued_laser_push_full,
    Events.back_sensor_open,
    'spike_times',
    duration=4,
)

hits = exp.align_trials(
    ActionLabels.cued_shutter_push_full,
    Events.back_sensor_open,
    'spike_rate',
    duration=4,
Esempio n. 10
0
    #'C57_1288723',
    #'C57_1288727',
]

exp = Experiment(
    mice,
    LeverPush,
    '~/duguidlab/thalamus_paper/Npx_data',
    '~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)

exp.set_cache(True)
sns.set(font_scale=0.4)
fig_dir = Path('~/duguidlab/visuomotor_control/figures').expanduser()

duration = 2
hits = exp.align_trials(
    ActionLabels.rewarded_push,
    Events.back_sensor_open,
    'spike',
    duration=duration,
    raw=True,
)

fig, axes = plt.subplots(2, 2)
for i, ai in enumerate(axes):
    for j, aj in enumerate(ai):
        aj.specgram(hits[0][i][j], Fs=30000, NFFT=256*8)
        aj.set_ylim([0, 100])
plt.show()
Esempio n. 11
0
# And from a session we can get continuous processed data:
spike_data = myexp[0].get_spike_data()
lfp_data = myexp[0].get_lfp_data()
behavioural_data = myexp[0].get_behavioural_data()

# Data can be loading as trial-aligned data using the Experiment.align_trials method.
# This returns a multidimensional pandas DataFrame containing the desired data organised
# by session, unit, and trial.
#
# Here are some examples of how data can be plotted:
#

# Plotting all behavioural data channels for session 1, trial 3
hits = myexp.align_trials(
    ActionLabels.rewarded_push,  # This selects which trials we want
    Events.back_sensor_open,  # This selects what event we want them aligned to 
    'behaviour'  # And this selects what kind of data we want
)

plt.figure()
fig, axes = plt.subplots(6, 1, sharex=True)
channels = hit_trials.columns.get_level_values('unit').unique()
trial = 3
session = 0
for i in range(6):
    chan_name = channels[i]
    sns.lineplot(
        data=hits[session][chan_name][trial],
        estimator=None,
        style=None,
        ax=axes[i]
sns.set(font_scale=0.4)
fig_dir = Path('~/duguidlab/visuomotor_control/figures')
duration = 4
rec_num = 0

select = {
    "min_depth": 500,
    "max_depth": 1200,
    "min_spike_width": 0.4,
}

hits = exp.align_trials(
    ActionLabels.cued_shutter_push_full,
    Events.back_sensor_open,
    'spike_times',
    duration=duration,
    **select,
)

stim = exp.align_trials(
    ActionLabels.uncued_laser_push_full,
    Events.back_sensor_open,
    'spike_times',
    duration=duration,
    **select,
)

hit_cis = exp.get_aligned_spike_rate_CI(
    ActionLabels.cued_shutter_push_full,
    Events.back_sensor_open,
#area = ["M2", "PPC"][rec_num] #for all other recordings
area = ["PPC"][rec_num]  #for HFR29 session 0

## Spike rate plots for all hits
#hits = exp.align_trials(
#ActionLabels.correct_left | correct_right,
#Events.led_on,
#'spike_rate',
#duration=duration,
#)

## Spike rate plots for all miss trials
miss_all = exp.align_trials(
    ActionLabels.miss_left | ActionLabels.miss_right,
    Events.led_on,
    'spike_rate',
    units=units,
    duration=duration,
)

#plot firing rate per unit & per trial
for session in range(len(exp)):
    # per unit
    #   fig = spike_rate.per_unit_spike_rate(hits[session][rec_num])
    #   name = exp[session].name
    #   plt.suptitle(f'Session {name} - per-unit across-trials firing rate (aligned to cued reach)')
    #   utils.save(fig_dir / f'unit_spike_rate_cued_reach_{duration}s_{area}_{name}')

    #   m2 = stim_all[session][0]
    #   ppc = stim_all[session][1]
exp = Experiment(
    mice,
    PushPull,
    '~/duguidlab/Direction_Sensitivity/Data/Neuropixel',
)

units = exp.select_units(
    min_depth=550,
    max_depth=1200,
    name="550-1200",
)

pushes = exp.align_trials(
    ActionLabels.rewarded_push_good_mi,
    Events.motion_index_onset,
    'spike_rate',
    duration=duration,
    units=units,
)

pulls = exp.align_trials(
    ActionLabels.rewarded_pull_good_mi,
    Events.motion_index_onset,
    'spike_rate',
    duration=duration,
    units=units,
)

# Only one recording
rec_num = 0
Esempio n. 15
0
    "C57_1350951",  # MI done
    #"C57_1350952",  # MI done
    #"C57_1350953",  # MI done
    #"C57_1350954",  # MI done
    #"C57_1350955",  # no ROIs drawn
]

exp = Experiment(
    mice,
    PushPull,
    '~/duguidlab/Direction_Sensitivity/Data/Neuropixel',
)

hits = exp.align_trials(
    ActionLabels.rewarded_push,
    Events.back_sensor_open,
    'motion_index',
    duration=duration,
)


for i, session in enumerate(exp):
    fig, axes = plt.subplots(10, 1, sharex=True)

    for t in range(10):
        sns.lineplot(
            data=hits[i][rec_num][0][t],
            estimator=None,
            style=None,
            ax=axes[t]
        )
        axes[t].set_title(f"Trial {t}")
    mice,
    LeverPush,
    '~/duguidlab/thalamus_paper/Npx_data',
    '~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)

sns.set(font_scale=0.4)
fig_dir = Path('~/duguidlab/visuomotor_control/figures')
duration = 4
rec_num = 0


## Spike rate plots
hits = exp.align_trials(
    ActionLabels.cued_shutter_push_full,
    Events.back_sensor_open,
    'spike_rate',
    duration=duration,
)

stim = exp.align_trials(
    ActionLabels.uncued_laser_push_full,
    Events.back_sensor_open,
    'spike_rate',
    duration=duration,
)

stim_miss = exp.align_trials(
    ActionLabels.uncued_laser_nopush,
    Events.laser_onset,
    'spike_rate',
    duration=duration,
Esempio n. 17
0
# This performs spike sorting, and ...
# myexp.extract_spikes()

# This...
# myexp.process_motion_tracking()

# Step 3: Run analyses
#
# Once all the data has been processed and converted into forms that are compatible with
# the rest of the data, we are ready to extract data organised by trials.
#

myexp.trial_duration = 60

# # behaviour
hit_trials = myexp.align_trials(ActionLabels.rewarded_push,
                                Events.back_sensor_open, 'behaviour')[0]
#
# fig, axes = plt.subplots(6, 1, sharex=True)
# tmp=hit_trials.columns.get_level_values('unit').unique()
# for i in range(6):
#     sns.lineplot(data=hit_trials[tmp[i]][1], estimator=None, style=None, ax=axes[i])
# plt.show()

# lfp
hit_trials_lfp = myexp.align_trials(ActionLabels.rewarded_push,
                                    Events.back_sensor_open, 'lfp')[0]

fig, axes = plt.subplots(10, 1, sharex=True)
for i in range(10):
    sns.lineplot(data=hit_trials_lfp[100 + i][8],
                 estimator=None,
exp = Experiment(
    mice,
    LeverPush,
    '~/duguidlab/thalamus_paper/Npx_data',
    '~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)
exp.set_cache(False)

sns.set(font_scale=0.4)
fig_dir = Path('~/duguidlab/visuomotor_control/figures')

exp.process_behaviour()

hits = exp.align_trials(
    ActionLabels.rewarded_push,
    Events.back_sensor_open,
    'behavioural',
    duration=duration,
)

fig, axes = plt.subplots(5, 1, sharex=True)
channels = hits.columns.get_level_values('unit').unique()

for i, session in enumerate(exp):
    for c in range(5):
        chan_name = channels[c]
        sns.lineplot(
            data=hits[i][rec_num][chan_name][trial],
            estimator=None,
            style=None,
            ax=axes[c]
        )
    '~/duguidlab/thalamus_paper/Npx_data',
    '~/duguidlab/CuedBehaviourAnalysis/Data/TrainingJSON',
)

fig_dir = Path('~/duguidlab/visuomotor_control/figures')
sns.set(font_scale=0.4)

align_args = {
    "duration": 1,
    "min_depth": 500,
    "max_depth": 1200,
}

hits = exp.align_trials(
    ActionLabels.cued_shutter_push_full,
    Events.back_sensor_open,
    'spike_rate',
    **align_args,
)

stim = exp.align_trials(
    ActionLabels.uncued_laser_push_full,
    Events.back_sensor_open,
    'spike_rate',
    **align_args,
)

stim_miss = exp.align_trials(
    ActionLabels.uncued_laser_nopush,
    Events.laser_onset,
    'spike_rate',
    **align_args,