{ "cells": [ { "cell_type": "markdown", "id": "6c76b6dd", "metadata": { "papermill": { "duration": 0.005922, "end_time": "2023-11-30T05:54:34.789829", "exception": false, "start_time": "2023-11-30T05:54:34.783907", "status": "completed" }, "tags": [] }, "source": [ "# Visual Behavior Neuropixels Quickstart\n", "\n", "A short introduction to the Visual Behavior Neuropixels data and SDK. This notebook focuses on aligning neural data to visual and optotagging stimuli. To learn more about how to access the data, see our [data access tutorial](./visual_behavior_neuropixels_data_access.ipynb). For more information about task and behavioral data, check out the [other tutorials](https://allensdk.readthedocs.io/en/latest/visual_behavior_neuropixels.html) accompanying this dataset.\n", "\n", "Also note that this project shares many features with the [Visual Coding Neuropixels](http://portal.brain-map.org/explore/circuits/visual-coding-neuropixels) and [Visual Behavior 2-Photon](http://portal.brain-map.org/explore/circuits/visual-coding-2p) datasets. Users are encouraged to check out the documentation for those projects for additional information and context.\n", "\n", "Contents\n", "-------------\n", "* PSTH for image changes\n", "* Plot Receptive Fields\n", "* Optotagging" ] }, { "cell_type": "code", "execution_count": 1, "id": "ceda3ce7", "metadata": { "execution": { "iopub.execute_input": "2023-11-30T05:54:34.801423Z", "iopub.status.busy": "2023-11-30T05:54:34.800961Z", "iopub.status.idle": "2023-11-30T05:54:39.587698Z", "shell.execute_reply": "2023-11-30T05:54:39.587043Z" }, "papermill": { "duration": 4.794439, "end_time": "2023-11-30T05:54:39.589471", "exception": false, "start_time": "2023-11-30T05:54:34.795032", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "import os\n", "from pathlib import Path\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "from allensdk.brain_observatory.behavior.behavior_project_cache.\\\n", " behavior_neuropixels_project_cache \\\n", " import VisualBehaviorNeuropixelsProjectCache" ] }, { "cell_type": "markdown", "id": "a7f3faf9", "metadata": { "papermill": { "duration": 0.005187, "end_time": "2023-11-30T05:54:39.600409", "exception": false, "start_time": "2023-11-30T05:54:39.595222", "status": "completed" }, "tags": [] }, "source": [ "The `VisualBehaviorNeuropixelsProjectCache` is the main entry point to the Visual Behavior Neuropixels dataset. It allows you to download data for individual recording sessions and view cross-session summary information." ] }, { "cell_type": "code", "execution_count": 2, "id": "d1b9c0de", "metadata": { "execution": { "iopub.execute_input": "2023-11-30T05:54:39.612009Z", "iopub.status.busy": "2023-11-30T05:54:39.611430Z", "iopub.status.idle": "2023-11-30T05:54:39.614573Z", "shell.execute_reply": "2023-11-30T05:54:39.613987Z" }, "papermill": { "duration": 0.010411, "end_time": "2023-11-30T05:54:39.615904", "exception": false, "start_time": "2023-11-30T05:54:39.605493", "status": "completed" }, "tags": [ "parameters" ] }, "outputs": [], "source": [ "# Update this to a valid directory in your filesystem. This is where the data will be stored.\n", "output_dir = \"/path/to/vbn_cache\"" ] }, { "cell_type": "code", "execution_count": 4, "id": "708db976", "metadata": { "execution": { "iopub.execute_input": "2023-11-30T05:54:39.642457Z", "iopub.status.busy": "2023-11-30T05:54:39.642042Z", "iopub.status.idle": "2023-11-30T05:54:49.013831Z", "shell.execute_reply": "2023-11-30T05:54:49.013152Z" }, "papermill": { "duration": 9.379274, "end_time": "2023-11-30T05:54:49.015493", "exception": false, "start_time": "2023-11-30T05:54:39.636219", "status": "completed" }, "scrolled": false, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/runner/work/AllenSDK/AllenSDK/allensdk/api/cloud_cache/cloud_cache.py:439: MissingLocalManifestWarning: This cache directory appears to contain data files, but it has no record of what those files are. You might want to consider running\n", "\n", "VisualBehaviorNeuropixelsProjectCache.construct_local_manifest()\n", "\n", "to avoid needlessly downloading duplicates of data files that did not change between data releases. NOTE: running this method will require hashing every data file you have currently downloaded and could be very time consuming.\n", "\n", "To avoid this warning in the future, make sure that\n", "\n", "/tmp/tmpfn0fgvq_/_downloaded_data.json\n", "\n", "is not deleted between instantiations of this cache\n", " warnings.warn(msg, MissingLocalManifestWarning)\n", "ecephys_sessions.csv: 100%|██████████| 64.7k/64.7k [00:00<00:00, 512kMB/s] \n", "behavior_sessions.csv: 100%|██████████| 562k/562k [00:00<00:00, 3.56MMB/s] \n", "units.csv: 100%|██████████| 132M/132M [00:04<00:00, 27.7MMB/s]\n", "probes.csv: 100%|██████████| 130k/130k [00:00<00:00, 815kMB/s] \n", "channels.csv: 100%|██████████| 27.9M/27.9M [00:01<00:00, 21.7MMB/s]\n" ] } ], "source": [ "cache = VisualBehaviorNeuropixelsProjectCache.from_s3_cache(\n", " cache_dir=Path(output_dir))\n", "\n", "# get the metadata tables\n", "units_table = cache.get_unit_table()\n", "\n", "channels_table = cache.get_channel_table()\n", "\n", "probes_table = cache.get_probe_table()\n", "\n", "behavior_sessions_table = cache.get_behavior_session_table()\n", "\n", "ecephys_sessions_table = cache.get_ecephys_session_table()" ] }, { "cell_type": "markdown", "id": "9fad545a", "metadata": { "papermill": { "duration": 0.007841, "end_time": "2023-11-30T05:54:49.031761", "exception": false, "start_time": "2023-11-30T05:54:49.023920", "status": "completed" }, "tags": [] }, "source": [ "This dataset contains ephys recording sessions from 3 genotypes (C57BL6J, VIP-IRES-CrexAi32 and SST-IRES-CrexAi32). For each mouse, two recordings were made on consecutive days. One of these sessions used the image set that was familiar to the mouse from training. The other session used a novel image set containing two familiar images from training and six new images that the mouse had never seen. As an example, let's grab a session from an SST mouse during a novel session." ] }, { "cell_type": "code", "execution_count": 5, "id": "19bf649c", "metadata": { "execution": { "iopub.execute_input": "2023-11-30T05:54:49.048554Z", "iopub.status.busy": "2023-11-30T05:54:49.048149Z", "iopub.status.idle": "2023-11-30T05:54:49.069795Z", "shell.execute_reply": "2023-11-30T05:54:49.069179Z" }, "papermill": { "duration": 0.031613, "end_time": "2023-11-30T05:54:49.071146", "exception": false, "start_time": "2023-11-30T05:54:49.039533", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " | behavior_session_id | \n", "date_of_acquisition | \n", "equipment_name | \n", "session_type | \n", "mouse_id | \n", "genotype | \n", "sex | \n", "project_code | \n", "age_in_days | \n", "unit_count | \n", "... | \n", "channel_count | \n", "structure_acronyms | \n", "image_set | \n", "prior_exposures_to_image_set | \n", "session_number | \n", "experience_level | \n", "prior_exposures_to_omissions | \n", "file_id | \n", "abnormal_histology | \n", "abnormal_activity | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ecephys_session_id | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
1048189115 | \n", "1048221709 | \n", "2020-09-03 14:16:57.913000+00:00 | \n", "NP.1 | \n", "EPHYS_1_images_H_3uL_reward | \n", "509808 | \n", "Sst-IRES-Cre/wt;Ai32(RCL-ChR2(H134R)_EYFP)/wt | \n", "M | \n", "NeuropixelVisualBehavior | \n", "264 | \n", "1925 | \n", "... | \n", "2304 | \n", "['APN', 'CA1', 'CA3', 'DG-mo', 'DG-po', 'DG-sg... | \n", "H | \n", "0 | \n", "2 | \n", "Novel | \n", "1 | \n", "879 | \n", "NaN | \n", "NaN | \n", "
1048196054 | \n", "1048222325 | \n", "2020-09-03 14:25:07.290000+00:00 | \n", "NP.0 | \n", "EPHYS_1_images_H_3uL_reward | \n", "524925 | \n", "Sst-IRES-Cre/wt;Ai32(RCL-ChR2(H134R)_EYFP)/wt | \n", "F | \n", "NeuropixelVisualBehavior | \n", "166 | \n", "2288 | \n", "... | \n", "2304 | \n", "['APN', 'CA1', 'CA3', 'DG-mo', 'DG-po', 'DG-sg... | \n", "H | \n", "0 | \n", "2 | \n", "Novel | \n", "1 | \n", "880 | \n", "NaN | \n", "NaN | \n", "
1053941483 | \n", "1053960987 | \n", "2020-10-01 17:03:58.362000+00:00 | \n", "NP.1 | \n", "EPHYS_1_images_H_3uL_reward | \n", "527749 | \n", "Sst-IRES-Cre/wt;Ai32(RCL-ChR2(H134R)_EYFP)/wt | \n", "M | \n", "NeuropixelVisualBehavior | \n", "180 | \n", "1543 | \n", "... | \n", "2304 | \n", "['APN', 'CA1', 'CA3', 'DG-mo', 'DG-po', 'DG-sg... | \n", "H | \n", "0 | \n", "2 | \n", "Novel | \n", "1 | \n", "891 | \n", "NaN | \n", "NaN | \n", "
1064644573 | \n", "1064666428 | \n", "2020-11-19 15:18:01.372000+00:00 | \n", "NP.1 | \n", "EPHYS_1_images_H_3uL_reward | \n", "544456 | \n", "Sst-IRES-Cre/wt;Ai32(RCL-ChR2(H134R)_EYFP)/wt | \n", "M | \n", "NeuropixelVisualBehavior | \n", "120 | \n", "2254 | \n", "... | \n", "2304 | \n", "['APN', 'CA1', 'CA3', 'DG-mo', 'DG-po', 'DG-sg... | \n", "H | \n", "0 | \n", "2 | \n", "Novel | \n", "1 | \n", "909 | \n", "NaN | \n", "NaN | \n", "
1065905010 | \n", "1065929713 | \n", "2020-11-24 14:21:48.847000+00:00 | \n", "NP.0 | \n", "EPHYS_1_images_H_3uL_reward | \n", "544358 | \n", "Sst-IRES-Cre/wt;Ai32(RCL-ChR2(H134R)_EYFP)/wt | \n", "F | \n", "NeuropixelVisualBehavior | \n", "126 | \n", "1998 | \n", "... | \n", "2304 | \n", "['APN', 'CA1', 'CA3', 'DG-mo', 'DG-po', 'DG-sg... | \n", "H | \n", "0 | \n", "2 | \n", "Novel | \n", "1 | \n", "912 | \n", "NaN | \n", "NaN | \n", "
5 rows × 21 columns
\n", "\n", " | start_time | \n", "condition | \n", "level | \n", "stop_time | \n", "stimulus_name | \n", "duration | \n", "
---|---|---|---|---|---|---|
id | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
0 | \n", "8801.01737 | \n", "half-period of a cosine wave | \n", "0.950 | \n", "8802.01737 | \n", "raised_cosine | \n", "1.00 | \n", "
1 | \n", "8803.02730 | \n", "a single square pulse | \n", "0.800 | \n", "8803.03730 | \n", "pulse | \n", "0.01 | \n", "
2 | \n", "8805.12189 | \n", "a single square pulse | \n", "0.800 | \n", "8805.13189 | \n", "pulse | \n", "0.01 | \n", "
3 | \n", "8806.91173 | \n", "a single square pulse | \n", "0.800 | \n", "8806.92173 | \n", "pulse | \n", "0.01 | \n", "
4 | \n", "8809.01283 | \n", "half-period of a cosine wave | \n", "0.685 | \n", "8810.01283 | \n", "raised_cosine | \n", "1.00 | \n", "