The following notebook demonstrates how to load neural data for all imaging planes in one 2-photon imaging session into a single 'tidy' dataframe, make simple event-triggered plots, and do some basic analysis using scikit-learn.
This is designed to demonstrate a simple method for interacting with the visual behavior data. Many aspects of the dataset are not explored here.
We have built a package called mindscope_utilities
which contains some useful convenience functions. The allenSDK
is a dependency of this package and will be automatically installed when you install mindscope_utilities
per the instrutions below.
We will first install mindscope_utilities
into our colab environment by running the commands below. When this cell is complete, click on the RESTART RUNTIME
button that appears at the end of the output. Note that running this cell will produce a long list of outputs and some error messages. Clicking RESTART RUNTIME
at the end will resolve these issues.
You can minimize the cell after you are done to hide the output.
# @title Install packages
!pip install pip --upgrade --quiet
!pip install mindscope_utilities --quiet
!pip install pandas --quiet
!pip install seaborn --quiet
|████████████████████████████████| 2.1 MB 5.8 MB/s ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.1/64.1 kB 3.8 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 25.8 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 33.4 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 130.3/130.3 kB 6.4 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 668.3/668.3 kB 18.0 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.3/54.3 kB 4.3 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 39.2 MB/s eta 0:00:00 Preparing metadata (setup.py) ... done ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 35.1 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 130.3/130.3 kB 10.9 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 26.5/26.5 MB 24.7 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 50.9 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 115.5/115.5 kB 11.1 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 185.3/185.3 kB 11.1 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.4/48.4 MB 11.9 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 77.5/77.5 kB 8.1 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 271.8/271.8 kB 22.4 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 94.8/94.8 kB 8.1 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 73.4/73.4 kB 6.9 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.7/7.7 MB 65.5 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 69.7/69.7 kB 6.7 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.1/42.1 kB 3.7 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 47.9/47.9 kB 4.1 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 109.5/109.5 kB 9.5 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 128.0/128.0 kB 11.5 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 546.8/546.8 kB 31.9 MB/s eta 0:00:00 Building wheel for glymur (setup.py) ... done Building wheel for argschema (pyproject.toml) ... done ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. xarray-einstats 0.2.2 requires xarray>=0.20, but you have xarray 0.15.1 which is incompatible. markdown 3.3.7 requires importlib-metadata>=4.4; python_version < "3.10", but you have importlib-metadata 4.2.0 which is incompatible. datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible. arviz 0.12.1 requires xarray>=0.16.1, but you have xarray 0.15.1 which is incompatible. albumentations 0.1.12 requires imgaug<0.2.7,>=0.2.5, but you have imgaug 0.2.9 which is incompatible. WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
import os
import numpy as np
import pandas as pd
from tqdm import tqdm
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, accuracy_score
from sklearn.manifold import TSNE
import mindscope_utilities
import mindscope_utilities.visual_behavior_ophys as ophys
from allensdk.brain_observatory.behavior.behavior_project_cache import VisualBehaviorOphysProjectCache
pd.set_option('display.max_columns', 500)
The AllenSDK provides functionality for downloading tables that describe all sessions and experiments (individual imaging planes) in the Visual Behavior 2P dataset. We first download the data cache:
data_storage_directory = "/temp" # Note: this path must exist on your local drive
cache = VisualBehaviorOphysProjectCache.from_s3_cache(cache_dir=data_storage_directory)
ophys_session_table.csv: 100%|██████████| 227k/227k [00:00<00:00, 1.31MMB/s] behavior_session_table.csv: 100%|██████████| 1.21M/1.21M [00:00<00:00, 6.28MMB/s] ophys_experiment_table.csv: 100%|██████████| 610k/610k [00:00<00:00, 3.25MMB/s] ophys_cells_table.csv: 100%|██████████| 4.29M/4.29M [00:00<00:00, 12.4MMB/s]
Ophys_session_table
contains metadata describing imaging sessions. If more than one plane was imaged during a session, one ophys session id will be associated multiple ophys experiment ids. Each ophys session id will also have a unique behavior session id.Behavior_session_table
contains metadata describing behavioral sessions, which may or may not be during imaging. Behavior session ids that do not have ophys session ids were training sessions.Ophys_experiment_table
contains metadata describing imaging experiments (aka imaging planes). When mesoscope is used, one ophys session may contain up to 8 unique experiments (two visual areas by four imaging depths). Some imaging planes may not be released due to quality control issues, thus each ophys session id is associated with anywhere from one to eight unique experiment ids. Ophys experiment ids are unique and do not repeat across sessions. To find the same imaging plane that was matched across multiple sessions, use the ophys_container_id
column that can be found in both ophys_session_table
and ophys_experiment_table
.Then we can access the session and experiment tables directly.
Note that a 'session' is a single behavioral session. Sessions that are performed on the mesoscope will have multiple (up to 8) 'experiments' associated with them, where an experiment is a distinct imaging plane.
session_table = cache.get_ophys_session_table()
experiment_table = cache.get_ophys_experiment_table()
We can then view the contents of the session table. Note that this contains a lot of useful metadata about each session. One of the columns, ophys_experiment_id
provides a list of the experiments (aka imaging planes) that are associated with each session.
session_table.head()
equipment_name | full_genotype | mouse_id | reporter_line | driver_line | sex | age_in_days | cre_line | indicator | session_number | prior_exposures_to_session_type | prior_exposures_to_image_set | prior_exposures_to_omissions | behavior_session_id | ophys_experiment_id | ophys_container_id | project_code | date_of_acquisition | session_type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ophys_session_id | |||||||||||||||||||
951410079 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 206.0 | Sst-IRES-Cre | GCaMP6f | 1.0 | 0.0 | 65.0 | 0.0 | 951520319 | [951980471, 951980473, 951980475, 951980479, 9... | [1018028360, 1018028345, 1018028357, 101802834... | VisualBehaviorMultiscope | 2019-09-20 09:45:29.897856 | OPHYS_1_images_A |
952430817 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 209.0 | Sst-IRES-Cre | GCaMP6f | 2.0 | 0.0 | 66.0 | 1.0 | 952554548 | [953659743, 953659745, 953659749, 953659752] | [1018028357, 1018028345, 1018028339, 1018028354] | VisualBehaviorMultiscope | 2019-09-23 08:13:07.627573 | OPHYS_2_images_A_passive |
954954402 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 210.0 | Sst-IRES-Cre | GCaMP6f | 3.0 | 0.0 | 67.0 | 2.0 | 953982960 | [958527464, 958527471, 958527474, 958527479, 9... | [1018028360, 1018028342, 1018028357, 101802835... | VisualBehaviorMultiscope | 2019-09-24 16:00:00.000000 | OPHYS_3_images_A |
955775716 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 212.0 | Sst-IRES-Cre | GCaMP6f | 3.0 | 1.0 | 68.0 | 3.0 | 956010809 | [956941841, 956941844, 956941846] | [1018028342, 1018028339, 1018028345] | VisualBehaviorMultiscope | 2019-09-26 08:44:37.199778 | OPHYS_3_images_A |
957020350 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 213.0 | Sst-IRES-Cre | GCaMP6f | 4.0 | 0.0 | 0.0 | 4.0 | 957032492 | [957759562, 957759564, 957759566, 957759570, 9... | [1018028354, 1018028345, 1018028360, 101802834... | VisualBehaviorMultiscope | 2019-09-27 08:28:05.415005 | OPHYS_4_images_B |
The experiment table has one row per experiment. Note that the ophys_session_id
column links each experiment to its associated session in the session_table.
experiment_table.head()
equipment_name | full_genotype | mouse_id | reporter_line | driver_line | sex | age_in_days | cre_line | indicator | session_number | prior_exposures_to_session_type | prior_exposures_to_image_set | prior_exposures_to_omissions | ophys_session_id | behavior_session_id | ophys_container_id | project_code | imaging_depth | targeted_structure | date_of_acquisition | session_type | experience_level | passive | image_set | file_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ophys_experiment_id | |||||||||||||||||||||||||
951980486 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 206.0 | Sst-IRES-Cre | GCaMP6f | 1.0 | 0.0 | 65.0 | 0.0 | 951410079 | 951520319 | 1018028360 | VisualBehaviorMultiscope | 300 | VISl | 2019-09-20 09:45:29.897856 | OPHYS_1_images_A | Familiar | False | A | 1085400869 |
951980473 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 206.0 | Sst-IRES-Cre | GCaMP6f | 1.0 | 0.0 | 65.0 | 0.0 | 951410079 | 951520319 | 1018028345 | VisualBehaviorMultiscope | 225 | VISp | 2019-09-20 09:45:29.897856 | OPHYS_1_images_A | Familiar | False | A | 1085400919 |
951980481 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 206.0 | Sst-IRES-Cre | GCaMP6f | 1.0 | 0.0 | 65.0 | 0.0 | 951410079 | 951520319 | 1018028357 | VisualBehaviorMultiscope | 225 | VISl | 2019-09-20 09:45:29.897856 | OPHYS_1_images_A | Familiar | False | A | 1085400972 |
951980471 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 206.0 | Sst-IRES-Cre | GCaMP6f | 1.0 | 0.0 | 65.0 | 0.0 | 951410079 | 951520319 | 1018028342 | VisualBehaviorMultiscope | 150 | VISp | 2019-09-20 09:45:29.897856 | OPHYS_1_images_A | Familiar | False | A | 1085394308 |
951980475 | MESO.1 | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | 457841 | Ai148(TIT2L-GC6f-ICL-tTA2) | [Sst-IRES-Cre] | F | 206.0 | Sst-IRES-Cre | GCaMP6f | 1.0 | 0.0 | 65.0 | 0.0 | 951410079 | 951520319 | 1018028339 | VisualBehaviorMultiscope | 75 | VISp | 2019-09-20 09:45:29.897856 | OPHYS_1_images_A | Familiar | False | A | 1085400920 |
We are going to select one session from this table, session 854060305. This is a session with Sst-IRES-Cre mouse, which expressed GCaMP6f in Sst+ inhibitory interneurons. There were 6 simultaneously acquired imaging planes for this session. We can view metadata for this session as follows:
ophys_session_id = 854060305
session_table.loc[ophys_session_id]
equipment_name MESO.1 full_genotype Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt mouse_id 440631 reporter_line Ai148(TIT2L-GC6f-ICL-tTA2) driver_line [Sst-IRES-Cre] sex M age_in_days 129.0 cre_line Sst-IRES-Cre indicator GCaMP6f session_number 6.0 prior_exposures_to_session_type 0.0 prior_exposures_to_image_set 2.0 prior_exposures_to_omissions 6.0 behavior_session_id 854283407 ophys_experiment_id [854759890, 854759894, 854759896, 854759898, 8... ophys_container_id [1018028153, 1018028144, 1018028141, 101802813... project_code VisualBehaviorMultiscope date_of_acquisition 2019-04-19 08:37:15.454259 session_type OPHYS_6_images_B Name: 854060305, dtype: object
Each session consists of one or more 'experiments', in which each experiment is a single imaging plane
Each mesoscope session has up to 8 experiments associated with the session. We will load all sessions into a dictionary with the experiment IDs as the keys
The first time that this cell is run, the associated NWB files will be downloaded to your local data_storage_directory
. Subsequent runs of this cell will be faster since the data will already be cached locally.
experiments = {}
ophys_experiment_ids = session_table.loc[ophys_session_id]['ophys_experiment_id']
for ophys_experiment_id in ophys_experiment_ids:
experiments[ophys_experiment_id] = cache.get_behavior_ophys_experiment(ophys_experiment_id)
behavior_ophys_experiment_854759890.nwb: 100%|██████████| 233M/233M [00:14<00:00, 15.6MMB/s] /usr/local/lib/python3.7/dist-packages/hdmf/utils.py:577: FutureWarning: DynamicTable.__init__: Using positional arguments for this method is discouraged and will be deprecated in a future major release. Please use keyword arguments to ensure future compatibility. warnings.warn(msg, FutureWarning) /usr/local/lib/python3.7/dist-packages/pynwb/ophys.py:363: UserWarning: The second dimension of data does not match the length of rois. Your data may be transposed. warnings.warn("The second dimension of data does not match the length of rois. Your data may be " behavior_ophys_experiment_854759894.nwb: 100%|██████████| 255M/255M [00:08<00:00, 31.2MMB/s] behavior_ophys_experiment_854759896.nwb: 100%|██████████| 240M/240M [00:08<00:00, 29.2MMB/s] behavior_ophys_experiment_854759898.nwb: 100%|██████████| 259M/259M [00:08<00:00, 32.3MMB/s] behavior_ophys_experiment_854759900.nwb: 100%|██████████| 242M/242M [00:07<00:00, 31.6MMB/s] behavior_ophys_experiment_854759903.nwb: 100%|██████████| 254M/254M [00:08<00:00, 29.9MMB/s]
We can view the cell_specimen_table
for one experiment, which contains information about each identified cell in that experiment
experiment = experiments[ophys_experiment_ids[1]]
experiment.cell_specimen_table.head()
cell_roi_id | height | mask_image_plane | max_correction_down | max_correction_left | max_correction_right | max_correction_up | valid_roi | width | x | y | roi_mask | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
cell_specimen_id | ||||||||||||
1086557083 | 1080855636 | 17 | 0 | 5.0 | 7.0 | 4.0 | 7.0 | True | 19 | 173 | 384 | [[False, False, False, False, False, False, Fa... |
1086557639 | 1080855643 | 16 | 0 | 5.0 | 7.0 | 4.0 | 7.0 | True | 14 | 363 | 447 | [[False, False, False, False, False, False, Fa... |
1086559064 | 1080855660 | 19 | 1 | 5.0 | 7.0 | 4.0 | 7.0 | True | 17 | 24 | 221 | [[False, False, False, False, False, False, Fa... |
1086558114 | 1080855673 | 18 | 0 | 5.0 | 7.0 | 4.0 | 7.0 | True | 13 | 74 | 305 | [[False, False, False, False, False, False, Fa... |
1086558224 | 1080855678 | 19 | 0 | 5.0 | 7.0 | 4.0 | 7.0 | True | 18 | 478 | 284 | [[False, False, False, False, False, False, Fa... |
We can then visualize the max projection and one of the identified ROIs
fig, ax = plt.subplots(1, 2, figsize=(15, 8), sharex=True, sharey=True)
ax[0].imshow(experiment.max_projection, cmap='gray')
ax[0].set_title('max projection')
cell_specimen_id = experiment.cell_specimen_table.index[2]
ax[1].imshow(experiment.cell_specimen_table.loc[cell_specimen_id]['roi_mask'])
ax[1].set_title('ROI mask for cell_specimen_id = {}'.format(cell_specimen_id))
fig.show()
The cell below will load the neural data into memory in the pandas 'tidy' format by iterating over each of the 6 experiments and using some helpful tools from the visual_behavior_ophys
module of the mindscope_utilities
package that was imported above as ophys
.
It will also include a subset of metadata from ophys_experiment_table
to facilitate splitting by depth, structure (aka cortical area), cre line (aka cell class), etc.
Note that 'tidy' data means that each row represents only one observation. Observations are stacked vertically. Thus, the timestamps
colums will repeat for every cell in the dataset.
neural_data = []
for ophys_experiment_id in tqdm(experiments.keys()): #tqdm is a package that shows progress bars for items that are iterated over
this_experiment = experiments[ophys_experiment_id]
this_experiment_neural_data = ophys.build_tidy_cell_df(this_experiment)
# add some columns with metadata for the experiment
metadata_keys = [
'ophys_experiment_id',
'ophys_session_id',
'targeted_structure',
'imaging_depth',
'equipment_name',
'cre_line',
'mouse_id',
'sex',
]
for metadata_key in metadata_keys:
this_experiment_neural_data[metadata_key] = this_experiment.metadata[metadata_key]
# append the data for this experiment to a list
neural_data.append(this_experiment_neural_data)
# concatate the list of dataframes into a single dataframe
neural_data = pd.concat(neural_data)
100%|██████████| 6/6 [00:02<00:00, 2.37it/s]
We can then look at some attributes of the neural_data
dataframe we have created.
It is ~2.5 million rows long:
len(neural_data)
2561543
It is so long because has one row for each timestamp for each cell.
Below are the first 5 entries. Again, note that the tidy
format means that each row has only one observation, which represents a single GCaMP6 fluorescnce value for a single neuron.
neural_data.head()
timestamps | dff | events | filtered_events | cell_roi_id | cell_specimen_id | ophys_experiment_id | ophys_session_id | targeted_structure | imaging_depth | equipment_name | cre_line | mouse_id | sex | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 10.52216 | 0.400583 | 0.0 | 0.0 | 1080852071 | 1086550481 | 854759890 | 854060305 | VISp | 275 | MESO.1 | Sst-IRES-Cre | 440631 | M |
1 | 10.61538 | 0.126125 | 0.0 | 0.0 | 1080852071 | 1086550481 | 854759890 | 854060305 | VISp | 275 | MESO.1 | Sst-IRES-Cre | 440631 | M |
2 | 10.70860 | -0.083087 | 0.0 | 0.0 | 1080852071 | 1086550481 | 854759890 | 854060305 | VISp | 275 | MESO.1 | Sst-IRES-Cre | 440631 | M |
3 | 10.80182 | 0.158960 | 0.0 | 0.0 | 1080852071 | 1086550481 | 854759890 | 854060305 | VISp | 275 | MESO.1 | Sst-IRES-Cre | 440631 | M |
4 | 10.89504 | 0.301507 | 0.0 | 0.0 | 1080852071 | 1086550481 | 854759890 | 854060305 | VISp | 275 | MESO.1 | Sst-IRES-Cre | 440631 | M |
cell_roi_id
column contains unique roi ids for all cells in a given experiment, which do not repeat across ophys sessions.cell_specimen_id
column contains unique ids for cells that were matched across ophys sessions. Thus, a cell that was imaged in more than one session has multiple roi ids but one cell specimen id.We can get the unique Cell IDs in our dataset as follows:
cell_ids = neural_data['cell_specimen_id'].unique()
print('there are {} unique cells'.format(len(cell_ids)))
print('cell ids are: {}'.format(cell_ids))
there are 53 unique cells cell ids are: [1086550481 1086551114 1086551301 1086557083 1086557639 1086559064 1086558114 1086558224 1086558510 1086559206 1086557304 1086557208 1086560061 1086559681 1086559885 1086559968 1086557470 1086547796 1086547993 1086548118 1086554566 1086556653 1086558574 1086552296 1086558071 1086556532 1086555222 1086558701 1086557434 1086556317 1086555835 1086549726 1086553836 1086551540 1086551151 1086550544 1086552709 1086553271 1086553602 1086555553 1086548072 1086553899 1086547630 1086549303 1086549491 1086549813 1086549949 1086548658 1086548969 1086551457 1086551645 1086550990 1086551209]
If we wanted to get the timeseries for one cell, we could query the neural_data
dataframe. For example, to get the full timeseries for the cell with cell_specimen_id = 1086557208
:
single_cell_timeseries = neural_data.query('cell_specimen_id == 1086557208')
single_cell_timeseries.head()
timestamps | dff | events | filtered_events | cell_roi_id | cell_specimen_id | ophys_experiment_id | ophys_session_id | targeted_structure | imaging_depth | equipment_name | cre_line | mouse_id | sex | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 10.52216 | 0.218961 | 0.0 | 0.0 | 1080855724 | 1086557208 | 854759894 | 854060305 | VISp | 179 | MESO.1 | Sst-IRES-Cre | 440631 | M |
1 | 10.61538 | 0.232865 | 0.0 | 0.0 | 1080855724 | 1086557208 | 854759894 | 854060305 | VISp | 179 | MESO.1 | Sst-IRES-Cre | 440631 | M |
2 | 10.70860 | -0.050186 | 0.0 | 0.0 | 1080855724 | 1086557208 | 854759894 | 854060305 | VISp | 179 | MESO.1 | Sst-IRES-Cre | 440631 | M |
3 | 10.80182 | 0.239468 | 0.0 | 0.0 | 1080855724 | 1086557208 | 854759894 | 854060305 | VISp | 179 | MESO.1 | Sst-IRES-Cre | 440631 | M |
4 | 10.89504 | 0.226356 | 0.0 | 0.0 | 1080855724 | 1086557208 | 854759894 | 854060305 | VISp | 179 | MESO.1 | Sst-IRES-Cre | 440631 | M |
Each cell has three types of traces:
dff
column is the Calcium fluorescence signal, normalized to background fluorescence.events
column is deconvolved events from dff trace, which approximates neural firing rate and removes the slow decay of the Calcium signal (for more details, you can read EVENT DETECTION section in Visual Behavior whitepaper).filtered_events
column is events smoothed with a half-gaussian kernel.We can then plot DeltaF/F for this cell for the full experiment as follows:
fig, ax = plt.subplots(figsize=(15,5))
single_cell_timeseries.plot(
x = 'timestamps',
y = 'dff',
ax = ax
)
fig.show()
The stimulus table is shared across all experiments (imaging planes) in a session. We can therefore use the stimulus table for just one experiment.
We are going to drop the image_set
column because it is not informative for our purposes. We can then view the first 10 rows of the stimulus table.
stimulus_table = experiments[ophys_experiment_ids[0]].stimulus_presentations.drop(columns = ['image_set']) # dropping the 'image_set' column to avoid confusion. Image_set column contains a unique string for set of images presented in a session.
stimulus_table.head(10)
start_time | stop_time | duration | image_name | image_index | is_change | omitted | start_frame | end_frame | |
---|---|---|---|---|---|---|---|---|---|
stimulus_presentations_id | |||||||||
0 | 310.55053 | 310.80074 | 0.25021 | im000 | 0 | False | False | 17986 | 18001.0 |
1 | 311.30115 | 311.55135 | 0.25020 | im000 | 0 | False | False | 18031 | 18046.0 |
2 | 312.05179 | 312.30200 | 0.25021 | im000 | 0 | False | False | 18076 | 18091.0 |
3 | 312.80242 | 313.05262 | 0.25020 | im000 | 0 | False | False | 18121 | 18136.0 |
4 | 313.55303 | 313.80324 | 0.25021 | im000 | 0 | False | False | 18166 | 18181.0 |
5 | 314.30362 | 314.55385 | 0.25023 | im000 | 0 | False | False | 18211 | 18226.0 |
6 | 315.05426 | 315.30446 | 0.25020 | im000 | 0 | False | False | 18256 | 18271.0 |
7 | 315.80487 | 316.05507 | 0.25020 | im000 | 0 | False | False | 18301 | 18316.0 |
8 | 316.55547 | 316.80569 | 0.25022 | im000 | 0 | False | False | 18346 | 18361.0 |
9 | 317.30610 | 317.55627 | 0.25017 | im000 | 0 | False | False | 18391 | 18406.0 |
stimulus_templates
attribute¶Note that the unwarped
column contains the image before the application of a spherical warp. All of the pixels labeled 'NaN' will be off-screen (not visible to the mouse) after the warp is applied.
All experiments in a given session will share the same stimulus_templates
experiment = experiments[ophys_experiment_ids[0]]
experiment.stimulus_templates
unwarped | warped | |
---|---|---|
image_name | ||
im000 | [[nan, nan, nan, nan, nan, nan, nan, nan, nan,... | [[122, 122, 123, 125, 126, 127, 128, 129, 130,... |
im106 | [[nan, nan, nan, nan, nan, nan, nan, nan, nan,... | [[108, 109, 106, 103, 102, 104, 107, 112, 117,... |
im075 | [[nan, nan, nan, nan, nan, nan, nan, nan, nan,... | [[120, 121, 121, 121, 122, 123, 123, 122, 121,... |
im073 | [[nan, nan, nan, nan, nan, nan, nan, nan, nan,... | [[120, 120, 118, 116, 116, 119, 121, 120, 117,... |
im045 | [[nan, nan, nan, nan, nan, nan, nan, nan, nan,... | [[10, 13, 6, 0, 0, 8, 15, 13, 6, 2, 4, 9, 12, ... |
im054 | [[nan, nan, nan, nan, nan, nan, nan, nan, nan,... | [[124, 125, 127, 130, 133, 134, 136, 138, 140,... |
im031 | [[nan, nan, nan, nan, nan, nan, nan, nan, nan,... | [[233, 234, 244, 253, 253, 244, 237, 239, 246,... |
im035 | [[nan, nan, nan, nan, nan, nan, nan, nan, nan,... | [[178, 181, 189, 198, 200, 198, 196, 199, 205,... |
fig, ax = plt.subplots(2, 4, figsize=(20, 8), sharex=True, sharey=True)
for ii, image_name in enumerate(experiment.stimulus_templates.index):
ax.flatten()[ii].imshow(experiment.stimulus_templates.loc[image_name]['unwarped'], cmap='gray')
ax.flatten()[ii].set_title(image_name)
fig.tight_layout()
fig.show()