<jupyter_start><jupyter_text>DataJoint Workflow for Neuropixels Analysis with Kilosort+ This notebook will describe the steps for interacting with the data processed with the workflow.+ This workflow is assembled from 4 DataJoint elements:     + [element-lab](https://github.com/datajoint/element-lab)     + [element-animal](https://github.com/datajoint/element-animal)     + [element-session](https://github.com/datajoint/element-session)     + [element-array-ephys](https://github.com/datajoint/element-array-ephys)+ DataJoint provides abundant functions to query and fetch data.  For a detailed tutorials, visit our [general tutorial site](https://playground.datajoint.io/)  Load modules<jupyter_code>import datajoint as dj
import matplotlib.pyplot as plt
import numpy as np

from workflow.pipeline import subject, session, probe, ephys<jupyter_output><empty_output><jupyter_text>Workflow architecture<jupyter_code>dj.Diagram(subject.Subject) + dj.Diagram(session.Session) + dj.Diagram(probe) + dj.Diagram(ephys)<jupyter_output><empty_output><jupyter_text>Experimental metadata<jupyter_code>subject.Subject()
session_key = (session.Session & 'subject="subject5"' & 'session_datetime = "2021-10-07 12:00:00"').fetch1('KEY')
session_key<jupyter_output><empty_output><jupyter_text>Recordings for a particular session from one or more probes.<jupyter_code>ephys.EphysRecording & session_key<jupyter_output><empty_output><jupyter_text>Spike-sorting results<jupyter_code>ephys.CuratedClustering.Unit & session_key<jupyter_output><empty_output><jupyter_text>Generate a raster plot for one probe insertion, one parameter set, and the 'good' units<jupyter_code>clustering_query = (ephys.CuratedClustering.Unit & \
                session_key & \
                'insertion_number = 2' & \
                'paramset_idx=0' & \
                'cluster_quality_label = "good"')

units, unit_spiketimes = clustering_query.fetch('unit', 'spike_times')
x = np.hstack(unit_spiketimes)
y = np.hstack([np.full_like(s, u) for u, s in zip(units, unit_spiketimes)])
fig, ax = plt.subplots(1, 1, figsize=(32, 16))
ax.plot(x, y, '|')
ax.set_xlabel('Time (s)');
ax.set_ylabel('Unit');<jupyter_output><empty_output><jupyter_text>Plot the waveform of a unit<jupyter_code>unit_key = (clustering_query & 'unit = 1').fetch1('KEY')
unit_data = (ephys.CuratedClustering.Unit * ephys.WaveformSet.PeakWaveform & unit_key).fetch1()
sampling_rate = (ephys.EphysRecording & session_key & 'insertion_number = 2').fetch1('sampling_rate')/1000 # in kHz
plt.plot(np.r_[:unit_data['peak_electrode_waveform'].size] * 1/sampling_rate, unit_data['peak_electrode_waveform'])
plt.xlabel('Time (ms)');
plt.ylabel(r'Voltage ($\mu$V)');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12973171628077912, 'fraction_numerical': 0.012862918044836457, 'mean_word_length': 6.1820580474934035, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 5, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '96381', 'license': 'MIT', 'n_tokens_mistral': 978, 'n_tokens_neox': 912, 'n_words': 169, 'path': 'notebooks/01-explore.ipynb', 'repo_name': 'Yambottle/sciops-demo-workflow-1', 'size': '2721'}