<jupyter_start><jupyter_text>Overview plot An overall summary plot of behavior, tracking, and spiking activity for a particular session<jupyter_code>session_key = {'subject_id': 'vIRt47', 'session': 20}
experiment.Session & session_key
experiment.BehaviorTrial & session_key<jupyter_output><empty_output><jupyter_text>Extract whisker tracking data<jupyter_code>tracking.Tracking.WhiskerTracking & session_key
device_key = {'tracking_device': 'WT_Camera_Vincent 0'}
tracking_timestamps = (tracking.Tracking & session_key & device_key).fetch1('tracking_timestamps')
tracking_timestamps
whiskers, whisker_angles = (tracking.Tracking.WhiskerTracking & session_key & device_key).fetch(
    'whisker_idx', 'angle', order_by='whisker_idx')
whiskers
whisker_angles
plt.plot(whisker_angles[1])
whisker_phase = (tracking.ProcessedWhisker & session_key & device_key).fetch(
    'phase', order_by='whisker_idx')
plt.plot(whisker_phase[1])<jupyter_output><empty_output><jupyter_text>Extract units' spiketimes<jupyter_code>ephys.Unit & session_key
insertion_keys = (ephys.ProbeInsertion & session_key).fetch('KEY')
insertion_keys
spike_rasters = {}
for insertion_key in insertion_keys:
    units, spikes = (ephys.Unit & insertion_key).fetch('unit', 'spike_times')
    
    # concatenating spiketimes from all units into a 1d-vector
    spike_vec = np.concatenate(spikes)  
    
    # build a 1d-vector of equal length, representing the corresponding unit number for each spike in the "spike_vec"
    unit_vec = np.concatenate([[t] * len(s) for s, t in zip(spikes, unit)])
    
    # store in the "spike_rasters" with the insertion_number as key
    spike_rasters[insertion_key['insertion_number']] = {'spike_vec': spike_vec, 'unit_vec': unit_vec}
spike_rasters<jupyter_output><empty_output><jupyter_text>PLOT<jupyter_code>fig, axes = plt.subplots(len(spike_rasters) + 1, 1, figsize=(16, 8))

# plot whisker angle in the first subplot
axes[0].plot(tracking_timestamps, whisker_angles[0])

# plot spike raster in the remaining subplots, one per probe
for insertion_num, ax in zip(spike_rasters, axes[1:]):
    ax.plot(spike_rasters[insertion_num]['spike_vec'], spike_rasters[insertion_num]['unit_vec'], 'k|')<jupyter_output><empty_output><jupyter_text>Example segmentation by trial<jupyter_code>experiment.BehaviorTrial * experiment.SessionTrial & session_key<jupyter_output><empty_output><jupyter_text>fetch back the start and stop times of all trials in this session<jupyter_code>trial_starts, trial_stops = (experiment.BehaviorTrial * experiment.SessionTrial & session_key).fetch('start_time', 'stop_time')
trial_starts
trial_stops<jupyter_output><empty_output><jupyter_text>extract the whisker angle data from the last trial only<jupyter_code>in_trial = np.logical_and(tracking_timestamps >= trial_starts[-1], tracking_timestamps < trial_stops[-1])
trial_timestamps = tracking_timestamps[in_trial]
trial_whisker = whisker_angles[1][in_trial]
trial_timestamps
trial_whisker
plt.plot(trial_timestamps, trial_whisker)<jupyter_output><empty_output><jupyter_text>extract the unit spiketimes from the last trial only<jupyter_code>units, spikes, waveforms = (ephys.Unit * ephys.Unit.Waveform & insertion_key).fetch('unit', 'spike_times', 'waveform')
units
unit_spikes = spikes[5]  # select spike times from unit #5
unit_spikes
in_trial = np.logical_and(unit_spikes >= trial_starts[-1], unit_spikes < trial_stops[-1])
trial_spikes = unit_spikes[in_trial]
trial_spikes<jupyter_output><empty_output><jupyter_text>PLOT<jupyter_code>fig, ax = plt.subplots(1, 1, figsize=(16, 8))
ax.plot(trial_timestamps, trial_whisker)
ax.plot(trial_spikes, np.full_like(trial_spikes, np.nanmax(trial_whisker)), 'k*')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10979228486646884, 'fraction_numerical': 0.008092797410304829, 'mean_word_length': 8.178217821782178, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '230249', 'license': 'MIT', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1308, 'n_words': 246, 'path': 'notebooks/plotting/Overview.ipynb', 'repo_name': 'wanglab-neuro/orofacial_pipeline', 'size': '3707'}