Example behavior and ophys data¶
The following example shows how to access behavioral data for a given recording session and how to align with corresponding neural data
We will first install allensdk into your environment by running the appropriate commands below.
Install AllenSDK into your local environment¶
You can install AllenSDK locally with:
!pip install allensdk
Requirement already satisfied: allensdk in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (2.16.2) Requirement already satisfied: psycopg2-binary in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.9.9) Requirement already satisfied: hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.* in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.11.0) Requirement already satisfied: h5py in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.10.0) Requirement already satisfied: matplotlib in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.7.4) Requirement already satisfied: numpy<1.24 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.23.5) Requirement already satisfied: pandas==1.5.3 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.5.3) Requirement already satisfied: jinja2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.1.2) Requirement already satisfied: scipy<1.11 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.10.1) Requirement already satisfied: six in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.16.0) Requirement already satisfied: pynrrd in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.0.0) Requirement already satisfied: future in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.18.3) Requirement already satisfied: requests in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.31.0) Requirement already satisfied: requests-toolbelt in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.0.0) Requirement already satisfied: simplejson in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.19.2) Requirement already satisfied: scikit-image in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.21.0) Requirement already satisfied: scikit-build in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.17.6) Requirement already satisfied: statsmodels in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.14.0) Requirement already satisfied: simpleitk in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.3.1) Requirement already satisfied: argschema in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.0.4) Requirement already satisfied: glymur in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.12.9.post1) Requirement already satisfied: xarray<2023.2.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2023.1.0) Requirement already satisfied: pynwb in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.5.0) Requirement already satisfied: tables in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.8.0) Requirement already satisfied: seaborn in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.13.0) Requirement already satisfied: aiohttp in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.9.1) Requirement already satisfied: nest-asyncio in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.5.8) Requirement already satisfied: tqdm in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (4.66.1) Requirement already satisfied: ndx-events in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.2.0) Requirement already satisfied: boto3 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.33.4) Requirement already satisfied: semver in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.0.2) Requirement already satisfied: cachetools in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (5.3.2) Requirement already satisfied: sqlalchemy in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.0.23) Requirement already satisfied: python-dateutil in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.8.2) Requirement already satisfied: pytz>=2020.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from pandas==1.5.3->allensdk) (2023.3.post1) Requirement already satisfied: importlib-resources in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (6.1.1) Requirement already satisfied: jsonschema>=2.6.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (4.20.0) Requirement already satisfied: ruamel-yaml>=0.16 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (0.18.5) Requirement already satisfied: packaging>=21.3 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from xarray<2023.2.0->allensdk) (23.2) Requirement already satisfied: attrs>=17.3.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (23.1.0) Requirement already satisfied: multidict<7.0,>=4.5 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (6.0.4) Requirement already satisfied: yarl<2.0,>=1.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (1.9.3) Requirement already satisfied: frozenlist>=1.1.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (1.4.0) Requirement already satisfied: aiosignal>=1.1.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (1.3.1) Requirement already satisfied: async-timeout<5.0,>=4.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (4.0.3) Requirement already satisfied: marshmallow<4.0,>=3.0.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from argschema->allensdk) (3.20.1) Requirement already satisfied: pyyaml in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from argschema->allensdk) (6.0.1) Requirement already satisfied: botocore<1.34.0,>=1.33.4 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from boto3->allensdk) (1.33.4) Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from boto3->allensdk) (1.0.1) Requirement already satisfied: s3transfer<0.9.0,>=0.8.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from boto3->allensdk) (0.8.2) Requirement already satisfied: lxml in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from glymur->allensdk) (4.9.3) Requirement already satisfied: MarkupSafe>=2.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jinja2->allensdk) (2.1.3) Requirement already satisfied: contourpy>=1.0.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (1.1.1) Requirement already satisfied: cycler>=0.10 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (4.45.1) Requirement already satisfied: kiwisolver>=1.0.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (1.4.5) Requirement already satisfied: pillow>=6.2.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (10.1.0) Requirement already satisfied: pyparsing>=2.3.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (3.1.1) Requirement already satisfied: setuptools in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from pynwb->allensdk) (56.0.0) Requirement already satisfied: nptyping in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from pynrrd->allensdk) (2.5.0) Requirement already satisfied: typing-extensions in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from pynrrd->allensdk) (4.8.0) Requirement already satisfied: charset-normalizer<4,>=2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from requests->allensdk) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from requests->allensdk) (3.6) Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from requests->allensdk) (1.26.18) Requirement already satisfied: certifi>=2017.4.17 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from requests->allensdk) (2023.11.17) Requirement already satisfied: distro in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-build->allensdk) (1.8.0) Requirement already satisfied: tomli in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-build->allensdk) (2.0.1) Requirement already satisfied: wheel>=0.32.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-build->allensdk) (0.42.0) Requirement already satisfied: networkx>=2.8 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (3.1) Requirement already satisfied: imageio>=2.27 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (2.33.0) Requirement already satisfied: tifffile>=2022.8.12 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (2023.7.10) Requirement already satisfied: PyWavelets>=1.1.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (1.4.1) Requirement already satisfied: lazy_loader>=0.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (0.3) Requirement already satisfied: greenlet!=0.4.17 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from sqlalchemy->allensdk) (3.0.1) Requirement already satisfied: patsy>=0.5.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from statsmodels->allensdk) (0.5.3) Requirement already satisfied: cython>=0.29.21 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from tables->allensdk) (3.0.6) Requirement already satisfied: numexpr>=2.6.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from tables->allensdk) (2.8.6) Requirement already satisfied: blosc2~=2.0.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from tables->allensdk) (2.0.0) Requirement already satisfied: py-cpuinfo in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from tables->allensdk) (9.0.0) Requirement already satisfied: msgpack in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from blosc2~=2.0.0->tables->allensdk) (1.0.7) Requirement already satisfied: zipp>=3.1.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from importlib-resources->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (3.17.0) Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jsonschema>=2.6.0->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (2023.11.1) Requirement already satisfied: pkgutil-resolve-name>=1.3.10 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jsonschema>=2.6.0->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (1.3.10) Requirement already satisfied: referencing>=0.28.4 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jsonschema>=2.6.0->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (0.31.1) Requirement already satisfied: rpds-py>=0.7.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jsonschema>=2.6.0->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (0.13.2) Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from ruamel-yaml>=0.16->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (0.2.8)
Install AllenSDK into your notebook environment (good for Google Colab)¶
You can install AllenSDK into your notebook environment by executing the cell below.
If using Google Colab, click on the RESTART RUNTIME button that appears at the end of the output when this cell is complete,. 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.
!pip install --upgrade pip
!pip install allensdk
Requirement already satisfied: pip in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (23.3.1) Requirement already satisfied: allensdk in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (2.16.2) Requirement already satisfied: psycopg2-binary in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.9.9) Requirement already satisfied: hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.* in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.11.0) Requirement already satisfied: h5py in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.10.0) Requirement already satisfied: matplotlib in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.7.4) Requirement already satisfied: numpy<1.24 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.23.5) Requirement already satisfied: pandas==1.5.3 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.5.3) Requirement already satisfied: jinja2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.1.2) Requirement already satisfied: scipy<1.11 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.10.1) Requirement already satisfied: six in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.16.0) Requirement already satisfied: pynrrd in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.0.0) Requirement already satisfied: future in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.18.3) Requirement already satisfied: requests in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.31.0) Requirement already satisfied: requests-toolbelt in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.0.0) Requirement already satisfied: simplejson in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.19.2) Requirement already satisfied: scikit-image in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.21.0) Requirement already satisfied: scikit-build in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.17.6) Requirement already satisfied: statsmodels in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.14.0) Requirement already satisfied: simpleitk in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.3.1) Requirement already satisfied: argschema in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.0.4) Requirement already satisfied: glymur in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.12.9.post1) Requirement already satisfied: xarray<2023.2.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2023.1.0) Requirement already satisfied: pynwb in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.5.0) Requirement already satisfied: tables in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.8.0) Requirement already satisfied: seaborn in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.13.0) Requirement already satisfied: aiohttp in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.9.1) Requirement already satisfied: nest-asyncio in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.5.8) Requirement already satisfied: tqdm in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (4.66.1) Requirement already satisfied: ndx-events in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (0.2.0) Requirement already satisfied: boto3 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (1.33.4) Requirement already satisfied: semver in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (3.0.2) Requirement already satisfied: cachetools in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (5.3.2) Requirement already satisfied: sqlalchemy in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.0.23) Requirement already satisfied: python-dateutil in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from allensdk) (2.8.2) Requirement already satisfied: pytz>=2020.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from pandas==1.5.3->allensdk) (2023.3.post1) Requirement already satisfied: importlib-resources in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (6.1.1) Requirement already satisfied: jsonschema>=2.6.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (4.20.0) Requirement already satisfied: ruamel-yaml>=0.16 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (0.18.5) Requirement already satisfied: packaging>=21.3 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from xarray<2023.2.0->allensdk) (23.2) Requirement already satisfied: attrs>=17.3.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (23.1.0) Requirement already satisfied: multidict<7.0,>=4.5 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (6.0.4) Requirement already satisfied: yarl<2.0,>=1.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (1.9.3) Requirement already satisfied: frozenlist>=1.1.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (1.4.0) Requirement already satisfied: aiosignal>=1.1.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (1.3.1) Requirement already satisfied: async-timeout<5.0,>=4.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from aiohttp->allensdk) (4.0.3) Requirement already satisfied: marshmallow<4.0,>=3.0.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from argschema->allensdk) (3.20.1) Requirement already satisfied: pyyaml in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from argschema->allensdk) (6.0.1) Requirement already satisfied: botocore<1.34.0,>=1.33.4 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from boto3->allensdk) (1.33.4) Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from boto3->allensdk) (1.0.1) Requirement already satisfied: s3transfer<0.9.0,>=0.8.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from boto3->allensdk) (0.8.2) Requirement already satisfied: lxml in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from glymur->allensdk) (4.9.3) Requirement already satisfied: MarkupSafe>=2.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jinja2->allensdk) (2.1.3) Requirement already satisfied: contourpy>=1.0.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (1.1.1) Requirement already satisfied: cycler>=0.10 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (4.45.1) Requirement already satisfied: kiwisolver>=1.0.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (1.4.5) Requirement already satisfied: pillow>=6.2.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (10.1.0) Requirement already satisfied: pyparsing>=2.3.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from matplotlib->allensdk) (3.1.1) Requirement already satisfied: setuptools in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from pynwb->allensdk) (56.0.0) Requirement already satisfied: nptyping in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from pynrrd->allensdk) (2.5.0) Requirement already satisfied: typing-extensions in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from pynrrd->allensdk) (4.8.0) Requirement already satisfied: charset-normalizer<4,>=2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from requests->allensdk) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from requests->allensdk) (3.6) Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from requests->allensdk) (1.26.18) Requirement already satisfied: certifi>=2017.4.17 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from requests->allensdk) (2023.11.17) Requirement already satisfied: distro in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-build->allensdk) (1.8.0) Requirement already satisfied: tomli in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-build->allensdk) (2.0.1) Requirement already satisfied: wheel>=0.32.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-build->allensdk) (0.42.0) Requirement already satisfied: networkx>=2.8 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (3.1) Requirement already satisfied: imageio>=2.27 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (2.33.0) Requirement already satisfied: tifffile>=2022.8.12 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (2023.7.10) Requirement already satisfied: PyWavelets>=1.1.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (1.4.1) Requirement already satisfied: lazy_loader>=0.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from scikit-image->allensdk) (0.3) Requirement already satisfied: greenlet!=0.4.17 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from sqlalchemy->allensdk) (3.0.1) Requirement already satisfied: patsy>=0.5.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from statsmodels->allensdk) (0.5.3) Requirement already satisfied: cython>=0.29.21 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from tables->allensdk) (3.0.6) Requirement already satisfied: numexpr>=2.6.2 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from tables->allensdk) (2.8.6) Requirement already satisfied: blosc2~=2.0.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from tables->allensdk) (2.0.0) Requirement already satisfied: py-cpuinfo in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from tables->allensdk) (9.0.0) Requirement already satisfied: msgpack in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from blosc2~=2.0.0->tables->allensdk) (1.0.7) Requirement already satisfied: zipp>=3.1.0 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from importlib-resources->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (3.17.0) Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jsonschema>=2.6.0->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (2023.11.1) Requirement already satisfied: pkgutil-resolve-name>=1.3.10 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jsonschema>=2.6.0->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (1.3.10) Requirement already satisfied: referencing>=0.28.4 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jsonschema>=2.6.0->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (0.31.1) Requirement already satisfied: rpds-py>=0.7.1 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from jsonschema>=2.6.0->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (0.13.2) Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages (from ruamel-yaml>=0.16->hdmf!=3.5.*,!=3.6.*,!=3.7.*,!=3.8.*->allensdk) (0.2.8)
Imports¶
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd
pd.set_option('display.max_columns', 500)
import allensdk.brain_observatory.behavior.behavior_project_cache as bpc
import allensdk
import pkg_resources
print('allensdk version 2.10.2 or higher is required, you have {} installed'.format(pkg_resources.get_distribution("allensdk").version))
/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 from .autonotebook import tqdm as notebook_tqdm
allensdk version 2.10.2 or higher is required, you have 2.16.2 installed
%matplotlib notebook
Make notebook use full screen width¶
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
/tmp/ipykernel_3358/3777615979.py:1: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display from IPython.core.display import display, HTML
output_dir = '/path/to/vbo'
bc = bpc.VisualBehaviorOphysProjectCache.from_s3_cache(cache_dir=output_dir)
experiment_table = bc.get_ophys_experiment_table()
/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 VisualBehaviorOphysProjectCache.construct_local_manifest() 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. To avoid this warning in the future, make sure that /tmp/tmp_nkzxk6t/_downloaded_data.json is not deleted between instantiations of this cache warnings.warn(msg, MissingLocalManifestWarning) ophys_session_table.csv: 100%|██████████| 247k/247k [00:00<00:00, 1.62MMB/s] behavior_session_table.csv: 100%|██████████| 1.59M/1.59M [00:00<00:00, 9.31MMB/s] ophys_experiment_table.csv: 100%|██████████| 657k/657k [00:00<00:00, 3.77MMB/s] ophys_cells_table.csv: 100%|██████████| 4.28M/4.28M [00:00<00:00, 12.3MMB/s] /home/runner/work/AllenSDK/AllenSDK/allensdk/brain_observatory/behavior/behavior_project_cache/behavior_project_cache.py:135: UpdatedStimulusPresentationTableWarning: As of AllenSDK version 2.16.0, the latest Visual Behavior Ophys data has been significantly updated from previous releases. Specifically the user will need to update all processing of the stimulus_presentations tables. These tables now include multiple stimulus types delineated by the columns `stimulus_block` and `stimulus_block_name`. The data that was available in previous releases are stored in the block name containing 'change_detection' and can be accessed in the pandas table by using: `stimulus_presentations[stimulus_presentations.stimulus_block_name.str.contains('change_detection')]` warnings.warn(
Look at a sample of the experiment table¶
experiment_table.sample(5, random_state=42)
behavior_session_id | ophys_session_id | ophys_container_id | mouse_id | indicator | full_genotype | driver_line | cre_line | reporter_line | sex | age_in_days | imaging_depth | targeted_structure | targeted_imaging_depth | imaging_plane_group | project_code | session_type | session_number | image_set | behavior_type | passive | experience_level | prior_exposures_to_session_type | prior_exposures_to_image_set | prior_exposures_to_omissions | date_of_acquisition | equipment_name | published_at | isi_experiment_id | file_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ophys_experiment_id | ||||||||||||||||||||||||||||||
1057725798 | 1056253022 | 1056238781 | 1052096554 | 528097 | GCaMP6f | Vip-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | [Vip-IRES-Cre] | Vip-IRES-Cre | Ai148(TIT2L-GC6f-ICL-tTA2) | F | 188 | 158 | VISp | 152 | 0 | VisualBehaviorMultiscope | OPHYS_6_images_B | 6 | B | active_behavior | False | Novel >1 | 0 | 7 | 10 | 2020-10-13 10:09:00.366000+00:00 | MESO.1 | 2021-03-25 | 1031852674 | 1932 |
891108758 | 890157940 | 889944877 | 1018028370 | 435431 | GCaMP6f | Vip-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | [Vip-IRES-Cre] | Vip-IRES-Cre | Ai148(TIT2L-GC6f-ICL-tTA2) | M | 215 | 217 | VISp | 220 | 0 | VisualBehaviorMultiscope | OPHYS_5_images_B_passive | 5 | B | passive_viewing | True | Novel >1 | 1 | 6 | 10 | 2019-06-19 10:45:53.800000+00:00 | MESO.1 | 2021-03-25 | 815343876 | 887 |
891108773 | 890157940 | 889944877 | 1018028377 | 435431 | GCaMP6f | Vip-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | [Vip-IRES-Cre] | Vip-IRES-Cre | Ai148(TIT2L-GC6f-ICL-tTA2) | M | 215 | 75 | VISl | 75 | 3 | VisualBehaviorMultiscope | OPHYS_5_images_B_passive | 5 | B | passive_viewing | True | Novel >1 | 1 | 6 | 10 | 2019-06-19 10:45:53.800000+00:00 | MESO.1 | 2021-03-25 | 815343876 | 893 |
1088351100 | 1088263239 | 1088247037 | 1086191444 | 550603 | GCaMP6f | Vip-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | [Vip-IRES-Cre] | Vip-IRES-Cre | Ai148(TIT2L-GC6f-ICL-tTA2) | F | 189 | 160 | VISl | 155 | 1 | VisualBehaviorMultiscope4areasx2d | OPHYS_2_images_G_passive | 2 | G | passive_viewing | True | Familiar | 0 | 26 | 4 | 2021-03-05 13:19:43.064000+00:00 | MESO.1 | 2021-08-12 | 1064781085 | 1740 |
975608392 | 975498864 | 975452945 | 1018028199 | 482853 | GCaMP6f | Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt | [Sst-IRES-Cre] | Sst-IRES-Cre | Ai148(TIT2L-GC6f-ICL-tTA2) | M | 124 | 150 | VISp | 146 | 1 | VisualBehaviorMultiscope | OPHYS_1_images_A | 1 | A | active_behavior | False | Familiar | 0 | 25 | 0 | 2019-11-01 14:53:10.259000+00:00 | MESO.1 | 2021-03-25 | 937755139 | 1450 |
here are all of the unique session types¶
np.sort(experiment_table['session_type'].unique())
array(['OPHYS_1_images_A', 'OPHYS_1_images_B', 'OPHYS_1_images_G', 'OPHYS_2_images_A_passive', 'OPHYS_2_images_B_passive', 'OPHYS_2_images_G_passive', 'OPHYS_3_images_A', 'OPHYS_3_images_B', 'OPHYS_3_images_G', 'OPHYS_4_images_A', 'OPHYS_4_images_B', 'OPHYS_4_images_H', 'OPHYS_5_images_A_passive', 'OPHYS_5_images_B_passive', 'OPHYS_5_images_H_passive', 'OPHYS_6_images_A', 'OPHYS_6_images_B', 'OPHYS_6_images_H'], dtype=object)
Select an OPHYS_1_images_A
experiment at random, load the experiment data¶
experiment_id = experiment_table.query('session_type == "OPHYS_1_images_A"').sample(random_state=10).index[0]
print('getting experiment data for experiment_id {}'.format(experiment_id))
experiment_dataset = bc.get_behavior_ophys_experiment(experiment_id)
getting experiment data for experiment_id 1085840400
behavior_ophys_experiment_1085840400.nwb: 100%|██████████| 503M/503M [00:21<00:00, 23.0MMB/s]
Look at the performance data¶
We can see that the d-prime metric, a measure of discrimination performance, peaked at 2.14 during this session, indicating mid-range performance.
(d' = 0 means no discrimination performance, d' is infinite for perfect performance, but is limited to about 4.5 this dataset due to trial count limitations).
experiment_dataset.get_performance_metrics()
{'trial_count': 454, 'go_trial_count': 334, 'catch_trial_count': 48, 'hit_trial_count': 33, 'miss_trial_count': 301, 'false_alarm_trial_count': 1, 'correct_reject_trial_count': 47, 'auto_reward_count': 5, 'earned_reward_count': 33, 'total_reward_count': 38, 'total_reward_volume': 0.256, 'maximum_reward_rate': 2.860105184605357, 'engaged_trial_count': 68, 'mean_hit_rate': 0.12196894640281876, 'mean_hit_rate_uncorrected': 0.1148300747554362, 'mean_hit_rate_engaged': 0.2722870777110328, 'mean_false_alarm_rate': 0.07059889644968179, 'mean_false_alarm_rate_uncorrected': 0.020957227763510482, 'mean_false_alarm_rate_engaged': 0.05736544779097969, 'mean_dprime': 0.019241657181077048, 'mean_dprime_engaged': 0.9736703202887197, 'max_dprime': 1.321681073934908, 'max_dprime_engaged': 1.3119564166604674}
We can build a trial dataframe that tells us about behavior events on every trial. This can be merged with a rolling performance dataframe, which calculates behavioral performance metrics over a rolling window of 100 trials (excluding aborted trials, or trials where the animal licks prematurely).¶
trials_df = experiment_dataset.trials.merge(
experiment_dataset.get_rolling_performance_df().fillna(method='ffill'), # performance data is NaN on aborted trials. Fill forward to populate.
left_index = True,
right_index = True
)
trials_df.head()
start_time | stop_time | initial_image_name | change_image_name | is_change | change_time | go | catch | lick_times | response_time | response_latency | reward_time | reward_volume | hit | false_alarm | miss | correct_reject | aborted | auto_rewarded | change_frame | trial_length | reward_rate | hit_rate_raw | hit_rate | false_alarm_rate_raw | false_alarm_rate | rolling_dprime | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
trials_id | |||||||||||||||||||||||||||
0 | 308.98272 | 316.25530 | im065 | im077 | True | 312.021593 | False | False | [312.48555, 312.73578, 312.90259, 313.05271, 3... | 312.48555 | 0.463957 | 312.15197 | 0.005 | False | False | False | False | False | True | 18166 | 7.27258 | NaN | NaN | NaN | NaN | NaN | NaN |
1 | 316.48885 | 316.85579 | im077 | im077 | False | NaN | False | False | [316.5389] | NaN | NaN | NaN | 0.000 | False | False | False | False | True | False | -99 | 0.36694 | NaN | NaN | NaN | NaN | NaN | NaN |
2 | 317.23947 | 318.17356 | im077 | im077 | False | NaN | False | False | [317.87332] | NaN | NaN | NaN | 0.000 | False | False | False | False | True | False | -99 | 0.93409 | NaN | NaN | NaN | NaN | NaN | NaN |
3 | 318.74067 | 328.26515 | im077 | im061 | True | 324.031413 | False | False | [324.42868, 324.56211, 324.69556, 324.84573, 3... | 324.42868 | 0.397267 | 324.14511 | 0.005 | False | False | False | False | False | True | 18886 | 9.52448 | NaN | NaN | NaN | NaN | NaN | NaN |
4 | 328.49870 | 337.30587 | im061 | im077 | True | 333.055463 | False | False | [333.48607, 333.73628, 333.90307, 334.05318, 3... | 333.48607 | 0.430607 | 333.18583 | 0.005 | False | False | False | False | False | True | 19427 | 8.80717 | NaN | NaN | NaN | NaN | NaN | NaN |
Now we can plot performance over the full experiment duration¶
Some key observations:
- The hit rate remains high for the first ~46 minutes of the session
- The false alarm rate graduall declines during the first ~25 minutes of the session.
- d' peaks when the hit rate is still high, but the false alarm rate dips
- The hit rate and d' fall off dramatically after ~46 minutes. This is likely due to the animal becoming sated and losing motivation to perform
fig, ax = plt.subplots(2, 1, figsize = (15,5), sharex=True)
ax[0].plot(
trials_df['start_time']/60.,
trials_df['hit_rate'],
color='darkgreen'
)
ax[0].plot(
trials_df['start_time']/60.,
trials_df['false_alarm_rate'],
color='darkred'
)
ax[0].legend(['rolling hit rate', 'rolling false alarm rate'])
ax[1].plot(
trials_df['start_time']/60.,
trials_df['rolling_dprime'],
color='black'
)
ax[1].set_xlabel('trial start time (minutes)')
ax[0].set_ylabel('response rate')
ax[0].set_title('hit and false alarm rates')
ax[1].set_title("d'")
fig.tight_layout()
We can also look at a dataframe of stimulus presentations. This tells us the attributes of every stimulus that was shown in the session¶
# Grab the image stimulus only
stimulus_presentations = experiment_dataset.stimulus_presentations[
experiment_dataset.stimulus_presentations.stimulus_block_name.str.contains('change_detection')]
stimulus_presentations.head()
stimulus_block | stimulus_block_name | image_index | image_name | movie_frame_index | duration | start_time | end_time | start_frame | end_frame | is_change | is_image_novel | omitted | movie_repeat | flashes_since_change | trials_id | active | is_sham_change | stimulus_name | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stimulus_presentations_id | |||||||||||||||||||
1 | 1 | change_detection_behavior | 0 | im065 | -99 | 0.25020 | 309.019143 | 309.269343 | 17986 | 18001 | False | False | False | -99 | 1 | 0 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
2 | 1 | change_detection_behavior | 0 | im065 | -99 | 0.25018 | 309.769753 | 310.019933 | 18031 | 18046 | False | False | False | -99 | 2 | 0 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
3 | 1 | change_detection_behavior | 0 | im065 | -99 | 0.25020 | 310.520343 | 310.770543 | 18076 | 18091 | False | False | False | -99 | 3 | 0 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
4 | 1 | change_detection_behavior | 0 | im065 | -99 | 0.25020 | 311.270953 | 311.521153 | 18121 | 18136 | False | False | False | -99 | 4 | 0 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
5 | 1 | change_detection_behavior | 1 | im077 | -99 | 0.25024 | 312.021593 | 312.271833 | 18166 | 18181 | True | False | False | -99 | 0 | 0 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
Also note that there is an image name called 'omitted'. This represents the time that a stimulus would have been shown, had it not been omitted from the regular stimulus cadence. They are included here for ease of analysis, but it's important to note that they are not actually stimuli. They are the lack of expected stimuli.¶
stimulus_presentations.query('image_name == "omitted"').head()
stimulus_block | stimulus_block_name | image_index | image_name | movie_frame_index | duration | start_time | end_time | start_frame | end_frame | is_change | is_image_novel | omitted | movie_repeat | flashes_since_change | trials_id | active | is_sham_change | stimulus_name | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stimulus_presentations_id | |||||||||||||||||||
17 | 1 | change_detection_behavior | 8 | omitted | -99 | 0.25 | 321.028963 | 321.278963 | 18706 | 18721 | False | <NA> | True | -99 | 11 | 3 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
25 | 1 | change_detection_behavior | 8 | omitted | -99 | 0.25 | 327.033833 | 327.283833 | 19066 | 19081 | False | <NA> | True | -99 | 3 | 3 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
37 | 1 | change_detection_behavior | 8 | omitted | -99 | 0.25 | 336.057873 | 336.307873 | 19607 | 19622 | False | <NA> | True | -99 | 3 | 4 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
63 | 1 | change_detection_behavior | 8 | omitted | -99 | 0.25 | 355.573823 | 355.823823 | 20777 | 20792 | False | <NA> | True | -99 | 4 | 7 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
66 | 1 | change_detection_behavior | 8 | omitted | -99 | 0.25 | 357.825693 | 358.075693 | 20912 | 20927 | False | <NA> | True | -99 | 6 | 8 | True | False | Natural_Images_Lum_Matched_set_training_2017 |
For plotting purposes below, let's add a column that specifies a unique color for every unique image¶
unique_stimuli = [stimulus for stimulus in stimulus_presentations['image_name'].unique() if stimulus != 'omitted']
colormap = {image_name: sns.color_palette()[image_number] for image_number, image_name in enumerate(np.sort(unique_stimuli))}
colormap['omitted'] = np.nan # assign gray to omitted
colormap
{'im061': (0.12156862745098039, 0.4666666666666667, 0.7058823529411765), 'im062': (1.0, 0.4980392156862745, 0.054901960784313725), 'im063': (0.17254901960784313, 0.6274509803921569, 0.17254901960784313), 'im065': (0.8392156862745098, 0.15294117647058825, 0.1568627450980392), 'im066': (0.5803921568627451, 0.403921568627451, 0.7411764705882353), 'im069': (0.5490196078431373, 0.33725490196078434, 0.29411764705882354), 'im077': (0.8901960784313725, 0.4666666666666667, 0.7607843137254902), 'im085': (0.4980392156862745, 0.4980392156862745, 0.4980392156862745), 'omitted': nan}
stimulus_presentations['color'] = stimulus_presentations['image_name'].map(lambda image_name: colormap[image_name])
There are also dataframes containing running speed, licks, eye tracking, and neural data:¶
running speed¶
One entry for each read of the analog input line monitoring the encoder voltage, polled at ~60 Hz.
experiment_dataset.running_speed.head()
timestamps | speed | |
---|---|---|
0 | 8.97085 | -0.027868 |
1 | 8.98751 | 0.056828 |
2 | 9.00421 | 0.121953 |
3 | 9.02091 | 0.154047 |
4 | 9.03756 | 0.148629 |
licks¶
One entry for every detected lick onset time, assigned the time of the corresponding visual stimulus frame.
experiment_dataset.licks.head()
timestamps | frame | |
---|---|---|
0 | 10.88909 | 115 |
1 | 13.17429 | 252 |
2 | 13.25767 | 257 |
3 | 13.35777 | 263 |
4 | 13.47453 | 270 |
eye tracking data¶
One entry containing ellipse fit parameters for the eye, pupil and corneal reflection for every frame of the eye tracking video stream.
experiment_dataset.eye_tracking.head()
timestamps | cr_area | eye_area | pupil_area | likely_blink | pupil_area_raw | cr_area_raw | eye_area_raw | cr_center_x | cr_center_y | cr_width | cr_height | cr_phi | eye_center_x | eye_center_y | eye_width | eye_height | eye_phi | pupil_center_x | pupil_center_y | pupil_width | pupil_height | pupil_phi | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
frame | |||||||||||||||||||||||
0 | 0.12895 | 120.778985 | 52646.046976 | 9467.868055 | False | 9467.868055 | 120.778985 | 52646.046976 | 304.855877 | 238.850452 | 5.860480 | 6.560068 | 0.041264 | 321.614711 | 229.150072 | 148.455382 | 112.880766 | -0.040543 | 284.593634 | 219.583658 | 54.897322 | 46.068901 | -0.741087 |
1 | 0.15369 | 115.944914 | 52448.649649 | 10145.403510 | False | 10145.403510 | 115.944914 | 52448.649649 | 304.125448 | 240.159601 | 5.672125 | 6.506629 | -0.276873 | 320.796911 | 229.198209 | 148.349421 | 112.537842 | -0.036200 | 282.597206 | 216.890346 | 56.827654 | 43.674891 | -0.650310 |
2 | 0.17215 | 120.194858 | 52110.324268 | 10430.167825 | False | 10430.167825 | 120.194858 | 52110.324268 | 304.436750 | 242.135068 | 5.949392 | 6.430776 | -0.445424 | 319.853374 | 231.950317 | 148.468978 | 111.721867 | -0.046359 | 283.692110 | 223.351216 | 47.981925 | 57.619663 | 0.643652 |
3 | 0.21069 | 112.516058 | 51693.903652 | 10825.284266 | False | 10825.284266 | 112.516058 | 51693.903652 | 304.122429 | 241.159250 | 6.291358 | 5.692725 | -0.182573 | 321.063479 | 230.763062 | 148.371626 | 110.901802 | -0.042321 | 282.785915 | 222.177822 | 46.984507 | 58.700894 | 0.606463 |
4 | 0.24880 | 112.314878 | 52186.596867 | 10278.561636 | False | 10278.561636 | 112.314878 | 52186.596867 | 304.529129 | 239.723128 | 5.795130 | 6.169134 | -0.171360 | 321.497389 | 228.294415 | 148.304450 | 112.009517 | -0.038966 | 283.189635 | 219.170357 | 47.385991 | 57.199369 | 0.654353 |
and deltaF/F values¶
One row per cell, with each containing an array of deltaF/F values.
experiment_dataset.dff_traces.head()
cell_roi_id | dff | |
---|---|---|
cell_specimen_id | ||
1120118128 | 1115339979 | [2.7728134118137593, 2.7377723001149357, 1.332... |
1120118208 | 1115339983 | [0.3466408785876189, 0.4530561213911281, 0.347... |
1120118626 | 1115340014 | [0.6086096210226783, 0.65493126738475, 0.73593... |
1120118698 | 1115340017 | [0.9173731088455804, 0.282220484734575, 0.3718... |
1120118967 | 1115340030 | [0.30710398969593, 0.44648909591684693, 0.0910... |
we can convert the dff_traces to long-form (aka "tidy") as follows:¶
def get_cell_timeseries_dict(dataset, cell_specimen_id):
'''
for a given cell_specimen ID, this function creates a dictionary with the following keys
* timestamps: ophys timestamps
* cell_roi_id
* cell_specimen_id
* dff
This is useful for generating a tidy dataframe
arguments:
session object
cell_specimen_id
returns
dict
'''
cell_dict = {
'timestamps': dataset.ophys_timestamps,
'cell_roi_id': [dataset.dff_traces.loc[cell_specimen_id]['cell_roi_id']] * len(dataset.ophys_timestamps),
'cell_specimen_id': [cell_specimen_id] * len(dataset.ophys_timestamps),
'dff': dataset.dff_traces.loc[cell_specimen_id]['dff'],
}
return cell_dict
experiment_dataset.tidy_dff_traces = pd.concat(
[pd.DataFrame(get_cell_timeseries_dict(experiment_dataset, cell_specimen_id)) for cell_specimen_id in experiment_dataset.dff_traces.reset_index()['cell_specimen_id']]
).reset_index(drop=True)
experiment_dataset.tidy_dff_traces.sample(5, random_state=42)
timestamps | cell_roi_id | cell_specimen_id | dff | |
---|---|---|---|---|
1921565 | 3958.76075 | 1115340271 | 1120124601 | 0.188913 |
889288 | 2057.48015 | 1115340119 | 1120121117 | -0.185857 |
6029601 | 579.51961 | 1115340543 | 1120133281 | -0.015155 |
1249765 | 4223.62711 | 1115340151 | 1120122063 | 0.018350 |
598198 | 1873.98465 | 1115340091 | 1120120317 | 0.042340 |
We can look at a few trials in some detail First define a function to plot a number of data streams
each stimulus as a colored vertical bar
running speed
licks/rewards
pupil area
neural responses (dF/F)
def plot_stimuli(trial, ax):
'''
plot stimuli as colored bars on specified axis
'''
# Fixup type for use in query.
stimulus_presentations['omitted'] = stimulus_presentations['omitted'].astype('bool')
stimuli = stimulus_presentations.query('end_time >= {} and start_time <= {} and not omitted'.format(float(trial['start_time']), float(trial['stop_time'])))
for idx, stimulus in stimuli.iterrows():
ax.axvspan(stimulus['start_time'], stimulus['end_time'], color=stimulus['color'], alpha=0.5)
def plot_running(trial, ax):
'''
plot running speed for trial on specified axes
'''
trial_running_speed = experiment_dataset.running_speed.query('timestamps >= {} and timestamps <= {} '.format(float(trial['start_time']), float(trial['stop_time'])))
ax.plot(
trial_running_speed['timestamps'],
trial_running_speed['speed'],
color='black'
)
ax.set_title('running speed')
ax.set_ylabel('speed (cm/s)')
def plot_licks(trial, ax):
'''
plot licks as black dots on specified axis
'''
trial_licks = experiment_dataset.licks.query('timestamps >= {} and timestamps <= {} '.format(float(trial['start_time']), float(trial['stop_time'])))
ax.plot(
trial_licks['timestamps'],
np.zeros_like(trial_licks['timestamps']),
marker = 'o',
linestyle = 'none',
color='black'
)
def plot_rewards(trial, ax):
'''
plot rewards as blue diamonds on specified axis
'''
trial_rewards = experiment_dataset.rewards.query('timestamps >= {} and timestamps <= {} '.format(float(trial['start_time']), float(trial['stop_time'])))
ax.plot(
trial_rewards['timestamps'],
np.zeros_like(trial_rewards['timestamps']),
marker = 'd',
linestyle = 'none',
color='blue',
markersize = 10,
alpha = 0.25
)
def plot_pupil(trial, ax):
'''
plot pupil area on specified axis
'''
trial_eye_tracking = experiment_dataset.eye_tracking.query('timestamps >= {} and timestamps <= {} '.format(float(trial['start_time']), float(trial['stop_time'])))
ax.plot(
trial_eye_tracking['timestamps'],
trial_eye_tracking['pupil_area'],
color='black'
)
ax.set_title('pupil area')
ax.set_ylabel('pupil area\n')
def plot_dff(trial, ax):
'''
plot each cell's dff response for a given trial
'''
trial_dff_traces = experiment_dataset.tidy_dff_traces.query('timestamps >= {} and timestamps <= {} '.format(float(trial['start_time']), float(trial['stop_time'])))
for cell_specimen_id in experiment_dataset.tidy_dff_traces['cell_specimen_id'].unique():
ax.plot(
trial_dff_traces.query('cell_specimen_id == @cell_specimen_id')['timestamps'],
trial_dff_traces.query('cell_specimen_id == @cell_specimen_id')['dff']
)
ax.set_title('deltaF/F responses')
ax.set_ylabel('dF/F')
def make_trial_plot(trial):
'''
combine all plots for a given trial
'''
fig, axes = plt.subplots(4, 1, figsize = (15, 8), sharex=True)
for ax in axes:
plot_stimuli(trial, ax)
plot_running(trial, axes[0])
plot_licks(trial, axes[1])
plot_rewards(trial, axes[1])
axes[1].set_title('licks and rewards')
axes[1].set_yticks([])
axes[1].legend(['licks','rewards'])
plot_pupil(trial, axes[2])
plot_dff(trial, axes[3])
axes[3].set_xlabel('time in session (seconds)')
fig.tight_layout()
return fig, axes
here is a hit trial¶
Notes:
- The image identity changed just after t = 2361 seconds (note the color change in the vertical spans)
- The animal was running steadily prior to the image change, then slowed to a stop after the change
- The first lick occured about 500 ms after the change, and triggered an immediate reward
- The pupil area shows some missing data - these were points that were filtered out as outliers.
- There appears to be one neuron that was responding regularly to the stimulus prior to the change.
stimulus_presentations.columns
Index(['stimulus_block', 'stimulus_block_name', 'image_index', 'image_name', 'movie_frame_index', 'duration', 'start_time', 'end_time', 'start_frame', 'end_frame', 'is_change', 'is_image_novel', 'omitted', 'movie_repeat', 'flashes_since_change', 'trials_id', 'active', 'is_sham_change', 'stimulus_name', 'color'], dtype='object')
trial = experiment_dataset.trials.query('hit').sample(random_state = 1)
fig, axes = make_trial_plot(trial)
here is a miss trial¶
Notes:
- The image identity changed just after t = 824 seconds (note the color change in the vertical spans)
- The animal was running relatively steadily during the entire trial and did not slow after the stimulus identity change
- There were no licks or rewards on this trial
- The pupil area shows some missing data - these were points that were filtered out as outliers.
- One neuron had a large response just prior to the change, but none appear to be stimulus locked on this trial
trial = experiment_dataset.trials.query('miss').sample(random_state = 2)
fig, axes = make_trial_plot(trial)
here is a false alarm trial¶
Notes:
- The image identity was consistent during the entire trial
- The animal slowed and licked partway through the trial
- There were no rewards on this trial
- The pupil area shows some missing data - these were points that were filtered out as outliers.
- There were not any neurons with obvious stimulus locked responses
trial = experiment_dataset.trials.query('false_alarm').sample(random_state = 2)
fig, axes = make_trial_plot(trial)
And finally, a correct rejection¶
Notes:
- The image identity was consistent during the entire trial
- The animal did not slow or lick during this trial
- There were no rewards on this trial
trial = experiment_dataset.trials.query('correct_reject').sample(random_state = 10)
fig, axes = make_trial_plot(trial)