Example behavior session¶

The following example shows how to access behavioral data for a given mouse across sessions

We will first install allensdk into your environment by running the appropriate commands below.

Install AllenSDK into your local environment¶

You can install AllenSDK with:

In [1]:
!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.

In [2]:
!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¶

In [3]:
import matplotlib.pyplot as plt
import seaborn as sns
import os
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
In [4]:
%matplotlib notebook
In [5]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
/tmp/ipykernel_2923/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

load cache, get behavior session table¶

This will set a location on your local drive to cache NWB files.
Then a table of all behavior sessions will be loaded.

In [6]:
# choose a location on your file system to cache NWB files as they are loaded:
output_dir = '/tmp/cache'
In [8]:
bc = bpc.VisualBehaviorOphysProjectCache.from_s3_cache(cache_dir=output_dir)
          
behavior_session_table = bc.get_behavior_session_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/tmpne_ij1g7/_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.66MMB/s] 
behavior_session_table.csv: 100%|██████████| 1.59M/1.59M [00:00<00:00, 6.61MMB/s]
ophys_experiment_table.csv: 100%|██████████| 657k/657k [00:00<00:00, 4.00MMB/s] 
ophys_cells_table.csv: 100%|██████████| 4.28M/4.28M [00:00<00:00, 10.6MMB/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(

view a sample of the behavior session table¶

The behavior_session_table is a Pandas DataFrame with one row for every session and a collection of informative columns. We can view 10 randomly selected rows of the table using the Pandas sample command.
It's important to note that this table contains every session, including sessions performed on a two-photon imaging rig (session_type starts with OPHYS_) and pre-imaging (aka 'training') sessions, (session_type starts with TRAINING_).

In [9]:
behavior_session_table.sample(10, random_state=42)
Out[9]:
ophys_session_id ophys_container_id mouse_id indicator full_genotype driver_line cre_line reporter_line sex age_in_days imaging_plane_group_count project_code session_type session_number image_set behavior_type experience_level prior_exposures_to_session_type prior_exposures_to_image_set prior_exposures_to_omissions date_of_acquisition equipment_name num_depths_per_area ophys_experiment_id num_targeted_structures catch_trial_count hit_trial_count go_trial_count miss_trial_count trial_count false_alarm_trial_count file_id engaged_trial_count correct_reject_trial_count
behavior_session_id
829877552 <NA> NaN 436662 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 97 <NA> VisualBehavior TRAINING_4_images_A_handoff_lapsed <NA> images_A active_behavior Training 3 8 0 2019-02-27 14:02:35.929000+00:00 BEH.F <NA> NaN <NA> 24 118 171 53 680 10 4337 364 14
880191852 <NA> NaN 453989 GCaMP6f Vip-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt [Vip-IRES-Cre] Vip-IRES-Cre Ai148(TIT2L-GC6f-ICL-tTA2) M 115 <NA> VisualBehaviorMultiscope TRAINING_2_gratings_flashed <NA> gratings active_behavior Training 13 <NA> 0 2019-06-03 12:47:43.079000+00:00 BEH.B-Box5 <NA> NaN <NA> 25 105 147 42 850 5 5619 301 20
853257103 <NA> NaN 448366 GCaMP6f Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt [Sst-IRES-Cre] Sst-IRES-Cre Ai148(TIT2L-GC6f-ICL-tTA2) M 92 <NA> VisualBehaviorMultiscope TRAINING_1_gratings <NA> gratings active_behavior Training 2 <NA> 0 2019-04-17 13:51:53.529000+00:00 BEH.F-Box6 <NA> NaN <NA> 29 77 190 113 908 8 4941 252 21
923417336 923202821 [915584942] 464207 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) F 138 <NA> VisualBehaviorTask1B OPHYS_5_images_A_passive 5 images_A passive_viewing Novel >1 0 1 5 2019-08-14 09:00:54.570000+00:00 CAM2P.3 1 [924108253] 1 51 0 356 356 407 0 -999 0 51
928279918 <NA> NaN 468866 GCaMP6f Vip-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt [Vip-IRES-Cre] Vip-IRES-Cre Ai148(TIT2L-GC6f-ICL-tTA2) F 126 <NA> VisualBehavior TRAINING_5_images_A_handoff_ready <NA> images_A active_behavior Training 0 7 0 2019-08-21 08:33:39.337000+00:00 BEH.G-Box1 <NA> NaN <NA> 29 91 201 110 660 6 5590 291 23
974888891 <NA> NaN 489066 GCaMP6f Vip-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt [Vip-IRES-Cre] Vip-IRES-Cre Ai148(TIT2L-GC6f-ICL-tTA2) F 88 <NA> VisualBehaviorTask1B TRAINING_0_gratings_autorewards_15min <NA> gratings active_behavior Training 0 <NA> 0 2019-10-31 13:42:45.933000+00:00 BEH.F-Box1 <NA> NaN <NA> 0 0 0 0 123 0 5915 78 0
951520315 <NA> NaN 480753 GCaMP6f Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt [Sst-IRES-Cre] Sst-IRES-Cre Ai148(TIT2L-GC6f-ICL-tTA2) M 93 <NA> VisualBehaviorTask1B TRAINING_2_gratings_flashed <NA> gratings active_behavior Training 5 <NA> 0 2019-09-20 10:10:14.267000+00:00 BEH.D-Box3 <NA> NaN <NA> 38 59 238 179 629 5 5262 251 33
1011563369 1011515036 [1018027796, 1018027816] 499478 GCaMP6f Vip-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt [Vip-IRES-Cre] Vip-IRES-Cre Ai148(TIT2L-GC6f-ICL-tTA2) F 147 2 VisualBehaviorMultiscope4areasx2d OPHYS_6_images_H 6 images_H active_behavior Novel >1 1 3 7 2020-03-02 08:45:16.961000+00:00 MESO.1 2 [1011771121, 1011771132] 4 39 114 280 166 605 2 -999 347 37
1000808691 <NA> NaN 498972 GCaMP6f Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt [Sst-IRES-Cre] Sst-IRES-Cre Ai148(TIT2L-GC6f-ICL-tTA2) M 106 <NA> VisualBehaviorTask1B TRAINING_0_gratings_autorewards_15min <NA> gratings active_behavior Training 0 <NA> 0 2020-01-17 15:45:47.353000+00:00 BEH.F-Box5 <NA> NaN <NA> 0 0 0 0 123 0 4216 75 0
902260156 <NA> NaN 457841 GCaMP6f Sst-IRES-Cre/wt;Ai148(TIT2L-GC6f-ICL-tTA2)/wt [Sst-IRES-Cre] Sst-IRES-Cre Ai148(TIT2L-GC6f-ICL-tTA2) F 133 <NA> VisualBehaviorMultiscope TRAINING_5_images_A_handoff_ready <NA> images_A active_behavior Training 5 23 0 2019-07-09 13:03:49.117000+00:00 BEH.G-Box5 <NA> NaN <NA> 7 43 51 8 1109 5 1974 14 2

Select one mouse¶

We'll choose one mouse id from the full list of unique mouse IDs in the dataset

In [10]:
behavior_session_table.mouse_id.unique()[:5]
Out[10]:
array(['457841', '476970', '412036', '429952', '449441'], dtype=object)

query the full behavior sessions table for all sessions that this mouse performed¶

This will return a subset of the full behavior_session_table in which the mouse_id matches our mouse_id variable (mouse 440298). The table should be returned in order of date of acquisition, but we'll use the Pandas command sort_values(by = 'date_of_acquisition') just to be sure.

What we then see is a table that has metadata for every session performed by this mouse, in sequential order. The equipment_name column tells us where the session was run on that day and the session_type column tells us the name of the session type. See the technical white paper for a description of the progression of stages.

For this mouse, we can see that it progressed through a series of training stages starting on 3/15/2019 in behavior training boxes BEH.B-Box3 and BEH.B-Box1.

On 4/1/2019, it reached the TRAINING_5_images_A_handoff_ready, which meant that it was ready for transition to an imaging rig as soon as space became available.

On 4/4/2019, it was transitioned to ophys rig CAM2P.3, where it then underwent three days of habituation without imaging. This is evidenced by the fact that the session type for 4/4/2019, 4/5/2019, and 4/8/2019 was OPHYS_0_images_A_habituation and there was no associated ophys_session_id.

The first day of imaging for this mouse was on 4/9/2019, with session_type = OPHYS_1_images_A.

Note that this mouse has two OPHYS_5_images_B_passive sessions, the first taken in order (immediately after OPHYS_4_images_B), and second taken at the end of the sequence. The first OPHYS_5_images_B_passive does not have an ophys_session_id associated with it. This is likely due to that first session failing to meet quality control standards and being excluded from the dataset. The second OPHYS_5_images_B_passive was likely a retake, taken after the first was identified as having been failed.

In general, ophys behavior sessions that do not have associated ophys_session_ids are sessions for which the ophys data has been removed do to failure to meet quality control standards.

In [11]:
# Select a mouse id
mouse_id = '445002'
this_mouse_table = behavior_session_table.query('mouse_id == @mouse_id').sort_values(by = 'date_of_acquisition')
# note that the following is functionally equivalent if you find the syntax easier to read: 
# this_mouse_table = behavior_session_table[behavior_session_table['mouse_id'] == mouse_id]
this_mouse_table
Out[11]:
ophys_session_id ophys_container_id mouse_id indicator full_genotype driver_line cre_line reporter_line sex age_in_days imaging_plane_group_count project_code session_type session_number image_set behavior_type experience_level prior_exposures_to_session_type prior_exposures_to_image_set prior_exposures_to_omissions date_of_acquisition equipment_name num_depths_per_area ophys_experiment_id num_targeted_structures catch_trial_count hit_trial_count go_trial_count miss_trial_count trial_count false_alarm_trial_count file_id engaged_trial_count correct_reject_trial_count
behavior_session_id
837658854 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 72 <NA> VisualBehavior TRAINING_0_gratings_autorewards_15min <NA> gratings active_behavior Training 0 <NA> 0 2019-03-15 14:49:24.015000+00:00 BEH.B-Box3 <NA> NaN <NA> 0 0 0 0 118 0 5235 101 0
838515247 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 75 <NA> VisualBehavior TRAINING_1_gratings <NA> gratings active_behavior Training 0 <NA> 0 2019-03-18 13:44:01.474000+00:00 BEH.B-Box1 <NA> NaN <NA> 13 106 133 27 1405 6 5236 341 7
839219841 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 76 <NA> VisualBehavior TRAINING_1_gratings <NA> gratings active_behavior Training 1 <NA> 0 2019-03-19 12:50:12.068000+00:00 BEH.B-Box1 <NA> NaN <NA> 61 48 335 287 451 1 5237 47 60
839565422 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 77 <NA> VisualBehavior TRAINING_1_gratings <NA> gratings active_behavior Training 2 <NA> 0 2019-03-20 13:16:44.461000+00:00 BEH.B-Box1 <NA> NaN <NA> 41 107 269 162 683 4 5238 386 37
839912316 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 78 <NA> VisualBehavior TRAINING_2_gratings_flashed <NA> gratings active_behavior Training 0 <NA> 0 2019-03-21 12:54:25.388000+00:00 BEH.B-Box1 <NA> NaN <NA> 20 103 174 71 966 6 5239 583 14
840581827 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 79 <NA> VisualBehavior TRAINING_2_gratings_flashed <NA> gratings active_behavior Training 1 <NA> 0 2019-03-22 12:56:37.162000+00:00 BEH.B-Box1 <NA> NaN <NA> 23 76 178 102 799 5 5240 256 18
841426832 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 82 <NA> VisualBehavior TRAINING_3_images_A_10uL_reward <NA> images_A active_behavior Training 0 0 0 2019-03-25 13:33:53.275000+00:00 BEH.B-Box1 <NA> NaN <NA> 17 94 132 38 837 3 5241 251 14
841827774 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 83 <NA> VisualBehavior TRAINING_3_images_A_10uL_reward <NA> images_A active_behavior Training 1 1 0 2019-03-26 12:43:01.470000+00:00 BEH.B-Box1 <NA> NaN <NA> 34 82 237 155 599 3 5242 312 31
842385277 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 84 <NA> VisualBehavior TRAINING_3_images_A_10uL_reward <NA> images_A active_behavior Training 2 2 0 2019-03-27 12:13:04.923000+00:00 BEH.B-Box1 <NA> NaN <NA> 37 96 246 150 580 5 5243 353 32
842819933 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 85 <NA> VisualBehavior TRAINING_4_images_A_training <NA> images_A active_behavior Training 0 3 0 2019-03-28 12:11:36.413000+00:00 BEH.B-Box1 <NA> NaN <NA> 25 112 171 59 849 7 5244 331 18
843400453 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 86 <NA> VisualBehavior TRAINING_5_images_A_epilogue <NA> images_A active_behavior Training 0 4 0 2019-03-29 13:03:16.029000+00:00 BEH.B-Box1 <NA> NaN <NA> 36 134 242 108 653 5 5245 414 31
844199758 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 89 <NA> VisualBehavior TRAINING_5_images_A_handoff_ready <NA> images_A active_behavior Training 0 5 0 2019-04-01 11:59:06.026000+00:00 BEH.B-Box1 <NA> NaN <NA> 34 101 242 141 610 4 5246 184 30
844908261 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 90 <NA> VisualBehavior TRAINING_5_images_A_handoff_ready <NA> images_A active_behavior Training 1 6 0 2019-04-02 12:34:16.170000+00:00 BEH.B-Box1 <NA> NaN <NA> 31 109 214 105 693 6 5247 378 25
845572044 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 91 <NA> VisualBehavior TRAINING_5_images_A_handoff_ready <NA> images_A active_behavior Training 2 7 0 2019-04-03 12:16:13.522000+00:00 BEH.B-Box1 <NA> NaN <NA> 41 112 285 173 516 4 5248 286 37
846331423 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 92 <NA> VisualBehavior OPHYS_0_images_A_habituation 0 images_A active_behavior Familiar 0 8 0 2019-04-04 13:13:13.399000+00:00 CAM2P.3 <NA> NaN <NA> 38 135 261 126 566 3 5249 363 35
847036328 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 93 <NA> VisualBehavior OPHYS_0_images_A_habituation 0 images_A active_behavior Familiar 1 9 0 2019-04-05 12:47:32.422000+00:00 CAM2P.3 <NA> NaN <NA> 39 127 273 146 543 5 5250 363 34
847874940 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 96 <NA> VisualBehavior OPHYS_0_images_A_habituation 0 images_A active_behavior Familiar 2 10 0 2019-04-08 13:27:21.095000+00:00 CAM2P.3 <NA> NaN <NA> 40 151 282 131 553 4 5251 386 36
848613406 848264483 [846215539] 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 97 <NA> VisualBehavior OPHYS_1_images_A 1 images_A active_behavior Familiar 0 11 0 2019-04-09 13:26:26.372000+00:00 CAM2P.3 1 [848697625] 1 35 144 228 84 632 6 -999 534 29
849147676 848894137 [846215539] 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 98 <NA> VisualBehavior OPHYS_2_images_A_passive 2 images_A passive_viewing Familiar 0 12 1 2019-04-10 13:34:39.264000+00:00 CAM2P.3 1 [849203565] 1 50 0 352 352 402 0 -999 0 50
849651275 849597937 [846215539] 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 99 <NA> VisualBehavior OPHYS_3_images_A 3 images_A active_behavior Familiar 0 13 2 2019-04-11 12:31:50.074000+00:00 CAM2P.3 1 [850479305] 1 28 117 200 83 699 2 -999 426 26
850989832 850959102 [846215539] 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 100 <NA> VisualBehavior OPHYS_4_images_B 4 images_B active_behavior Novel 1 0 0 3 2019-04-12 13:30:27.946000+00:00 CAM2P.3 1 [851060467] 1 34 154 231 77 664 7 -999 550 27
851773928 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 103 <NA> VisualBehavior OPHYS_5_images_B_passive 5 images_B passive_viewing Novel >1 0 1 4 2019-04-15 12:20:00.123000+00:00 CAM2P.3 <NA> NaN <NA> 51 0 356 356 407 0 5252 0 51
852451567 852326785 [846215539] 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 104 <NA> VisualBehavior OPHYS_6_images_B 6 images_B active_behavior Novel >1 0 2 5 2019-04-16 12:24:46.804000+00:00 CAM2P.3 1 [852691524] 1 30 161 201 40 731 7 -999 649 23
855200229 855083235 [846215539] 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 110 <NA> VisualBehavior OPHYS_5_images_B_passive 5 images_B passive_viewing Novel >1 1 3 7 2019-04-22 09:01:33.022000+00:00 CAM2P.3 1 [855582961] 1 51 0 355 355 406 0 -999 0 51

iterate over all sessions for this mouse, build a behavior_session_dict which will have one behavior session object for every session that this mouse performed, with the key being the behavior_session_id¶

Note that this could take many minutes to complete. For each session in our new table, this_mouse_table, we are pulling the behavior session NWB file from AWS, opening it as a BehaviorSession object using the AllenSDK, and also caching a copy of the NWB file in the directory specified above as output_dir. When the below cell completes, all behavior sessions for this mouse will be held in memory in the behavior_session_dict dictionary.

If you were to re-run this cell a second time, it would access your cached NWB files instead of downloading them from AWS, allowing it to run substantially faster.

It is important to note that we will only be loading the behavior data here, even for sessions that had corresponding imaging data. The get_behavior_ophys_experiment method would be used to get behavior and ophys data for ophys sessions. See additional sample notebooks for details.

In [12]:
behavior_session_ids = this_mouse_table.index.values
behavior_session_dict = {}
for behavior_session_id in behavior_session_ids:
    behavior_session_dict[behavior_session_id] = bc.get_behavior_session(behavior_session_id)
behavior_session_837658854.nwb: 100%|██████████| 51.7M/51.7M [00:02<00:00, 22.4MMB/s]
behavior_session_838515247.nwb: 100%|██████████| 66.9M/66.9M [00:02<00:00, 24.7MMB/s]
behavior_session_839219841.nwb: 100%|██████████| 66.7M/66.7M [00:02<00:00, 23.3MMB/s]
behavior_session_839565422.nwb: 100%|██████████| 66.7M/66.7M [00:02<00:00, 25.1MMB/s]
behavior_session_839912316.nwb: 100%|██████████| 68.6M/68.6M [00:03<00:00, 22.8MMB/s]
behavior_session_840581827.nwb: 100%|██████████| 68.5M/68.5M [00:02<00:00, 25.6MMB/s]
behavior_session_841426832.nwb: 100%|██████████| 189M/189M [00:07<00:00, 24.3MMB/s]
behavior_session_841827774.nwb: 100%|██████████| 189M/189M [00:07<00:00, 25.5MMB/s]
behavior_session_842385277.nwb: 100%|██████████| 189M/189M [00:08<00:00, 23.2MMB/s]
behavior_session_842819933.nwb: 100%|██████████| 189M/189M [00:07<00:00, 25.2MMB/s]
behavior_session_843400453.nwb: 100%|██████████| 196M/196M [00:08<00:00, 23.8MMB/s]
behavior_session_844199758.nwb: 100%|██████████| 196M/196M [00:08<00:00, 24.2MMB/s]
behavior_session_844908261.nwb: 100%|██████████| 196M/196M [00:07<00:00, 25.3MMB/s]
behavior_session_845572044.nwb: 100%|██████████| 196M/196M [00:07<00:00, 25.2MMB/s]
behavior_session_846331423.nwb: 100%|██████████| 196M/196M [00:08<00:00, 24.4MMB/s]
behavior_session_847036328.nwb: 100%|██████████| 196M/196M [00:08<00:00, 23.0MMB/s]
behavior_session_847874940.nwb: 100%|██████████| 196M/196M [00:09<00:00, 19.7MMB/s]
behavior_ophys_experiment_848697625.nwb: 100%|██████████| 836M/836M [00:40<00:00, 20.8MMB/s]
behavior_ophys_experiment_849203565.nwb: 100%|██████████| 908M/908M [00:34<00:00, 26.1MMB/s]
behavior_ophys_experiment_850479305.nwb: 100%|██████████| 823M/823M [00:33<00:00, 24.7MMB/s]
behavior_ophys_experiment_851060467.nwb: 100%|██████████| 847M/847M [00:31<00:00, 26.7MMB/s]
behavior_session_851773928.nwb: 100%|██████████| 244M/244M [00:09<00:00, 24.9MMB/s]
behavior_ophys_experiment_852691524.nwb: 100%|██████████| 856M/856M [00:49<00:00, 17.3MMB/s]
behavior_ophys_experiment_855582961.nwb: 100%|██████████| 989M/989M [00:59<00:00, 16.7MMB/s]

We can view all attributes of the behavior session object¶

These are all of the methods and attributes available on the BehaviorSession object. Not all are explored in this notebook.

In [13]:
behavior_session_id = behavior_session_ids[-1]
behavior_session_dict[behavior_session_id].list_data_attributes_and_methods()
Out[13]:
['behavior_session_id',
 'eye_tracking',
 'eye_tracking_rig_geometry',
 'get_performance_metrics',
 'get_reward_rate',
 'get_rolling_performance_df',
 'licks',
 'metadata',
 'raw_running_speed',
 'rewards',
 'running_speed',
 'stimulus_presentations',
 'stimulus_templates',
 'stimulus_timestamps',
 'task_parameters',
 'trials']

Note that any attribute can be followed by a ? in a Jupyter Notebook to see the docstring. For example, running the cell below will make a frame appear at the bottom of your browser with the docstring for the running_speed attribute.

In [14]:
behavior_session = behavior_session_dict[behavior_session_id]
behavior_session.running_speed?

here are some basic task parameters¶

We can see the session_type, which is OPHYS_5_images_B_passive and a number of other task parameters.

In [15]:
behavior_session_dict[behavior_session_id].task_parameters
Out[15]:
{'auto_reward_volume': 0.005,
 'blank_duration_sec': [0.5, 0.5],
 'image_set': 'images_B',
 'n_stimulus_frames': 69255,
 'omitted_flash_fraction': 0.05,
 'response_window_sec': [0.15, 0.75],
 'reward_volume': 0.007,
 'session_type': 'OPHYS_5_images_B_passive',
 'stimulus': 'images',
 'stimulus_distribution': 'geometric',
 'stimulus_duration_sec': 0.25,
 'stimulus_name': 'Natural_Images_Lum_Matched_set_ophys_6_2017',
 'task': 'change detection'}

Look at some of the attributes of the last 'handoff ready session'¶

We can filter the full table to get the last TRAINING_5_images_A_handoff_ready session. This would have been the last training session before the animal was subsequently handed off to the imaging team, after which all sessions were performed on a two-photon imaging rig.

In [16]:
behavior_session_id = this_mouse_table.query('session_type == "TRAINING_5_images_A_handoff_ready"').index[-1]
# note that the following is functionally equivalent if you find the syntax easier to read: 
# behavior_session_id = this_mouse_table[this_mouse_table['session_type'] == "TRAINING_5_images_A_handoff_ready"].index[-1]
dataset = behavior_session_dict[behavior_session_id]

stimuli¶

One entry for every distinct stimulus. Includes onset and offset time/frame.

In [17]:
dataset.stimulus_presentations.head(5)
Out[17]:
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
0 0 initial_gray_screen_5min -99 NaN -99 300.005657 0.000000 300.005657 0 17984 False <NA> <NA> -99 0 -99 False False spontaneous
1 1 change_detection_behavior 0 im065 -99 0.250203 300.005657 300.255860 17984 17999 False False False -99 1 0 True False Natural_Images_Lum_Matched_set_training_2017
2 1 change_detection_behavior 0 im065 -99 0.250197 300.756290 301.006487 18029 18044 False False False -99 2 0 True False Natural_Images_Lum_Matched_set_training_2017
3 1 change_detection_behavior 0 im065 -99 0.250212 301.506923 301.757135 18074 18089 False False False -99 3 0 True False Natural_Images_Lum_Matched_set_training_2017
4 1 change_detection_behavior 0 im065 -99 0.250201 302.274231 302.524432 18120 18135 False False False -99 4 1 True False Natural_Images_Lum_Matched_set_training_2017

licks¶

One entry for every detected lick onset time, assigned the time of the corresponding visual stimulus frame.

In [18]:
dataset.licks.sample(5, random_state=42)
Out[18]:
timestamps frame
307 540.035981 32375
382 663.205932 39759
462 721.571564 43258
1741 2716.194032 162835
917 1293.784671 77562

rewards¶

One entry for every reward that was delivered, assigned the time of the corresponding visual stimulus frame. Autorewarded is True if the reward was delivered without requiring a preceding lick.

In [19]:
dataset.rewards.sample(5, random_state=42)
Out[19]:
volume timestamps auto_rewarded
44 0.007 1085.243146 False
4 0.005 350.593768 True
53 0.007 1273.400934 False
42 0.007 1052.365585 False
10 0.007 484.089057 False

running data¶

One entry for each read of the analog input line monitoring the encoder voltage, polled at ~60 Hz

In [20]:
dataset.running_speed.head()
Out[20]:
timestamps speed
0 0.000000 0.010719
1 0.016554 -0.034077
2 0.033231 -0.079193
3 0.049912 -0.121338
4 0.067623 -0.156735

we can make a simple plot where we combine together running, licking and stimuli¶

First, add a column to the stimulus_presentations table that assigns a unique color to every stimulus¶

In [21]:
# Get the image stimulus block
image_stimulus_presentations = dataset.stimulus_presentations[
    dataset.stimulus_presentations.stimulus_block_name.str.contains('change_detection')]
unique_stimuli = [stimulus for stimulus in image_stimulus_presentations['image_name'].unique()]
colormap = {image_name: sns.color_palette()[image_number] for image_number, image_name in enumerate(np.sort(unique_stimuli))}
image_stimulus_presentations['color'] = image_stimulus_presentations['image_name'].map(lambda image_name: colormap[image_name])

now make some simple plotting functions to plot these datastreams¶

In [22]:
def plot_running(ax, initial_time, final_time):
    '''
    a simple function to plot running speed between two specified times on a specified axis
    inputs:
        ax: axis on which to plot
        intial_time: initial time to plot from
        final_time: final time to plot to
    '''
    running_sample = dataset.running_speed.query('timestamps >= @initial_time and timestamps <= @final_time')
    ax.plot(
        running_sample['timestamps'],
        running_sample['speed']
    )

def plot_licks(ax, initial_time, final_time):
    '''
    a simple function to plot licks as dots between two specified times on a specified axis
    inputs:
        ax: axis on which to plot
        intial_time: initial time to plot from
        final_time: final time to plot to
    '''
    licking_sample = dataset.licks.query('timestamps >= @initial_time and timestamps <= @final_time')
    ax.plot(
        licking_sample['timestamps'],
        np.zeros_like(licking_sample['timestamps']),
        marker = 'o',
        color = 'black',
        linestyle = 'none'
    )
    
def plot_rewards(ax, initial_time, final_time):
    '''
    a simple function to plot rewards between two specified times as blue diamonds on a specified axis
    inputs:
        ax: axis on which to plot
        intial_time: initial time to plot from
        final_time: final time to plot to
    '''
    rewards_sample = dataset.rewards.query('timestamps >= @initial_time and timestamps <= @final_time')
    ax.plot(
        rewards_sample['timestamps'],
        np.zeros_like(rewards_sample['timestamps']),
        marker = 'd',
        color = 'blue',
        linestyle = 'none',
        markersize = 12,
        alpha = 0.5
    )
    
def plot_stimuli(ax, ti, tf, image_stim_table):
    '''
    a simple function to plot stimuli as colored vertical spans on a s
    inputs:
        ax: axis on which to plot
        intial_time: initial time to plot from
        final_time: final time to plot to
        image_stim_table: Set of image stimuli to plot.
    '''
    stimulus_presentations_sample = image_stim_table.query('end_time >= @initial_time and start_time <= @final_time')
    for idx, stimulus in stimulus_presentations_sample.iterrows():
        ax.axvspan(stimulus['start_time'], stimulus['end_time'], color=stimulus['color'], alpha=0.25)

now make the plot¶

In [23]:
initial_time = 775 # initial time for plot, in seconds
final_time = 800 # final time for plot, in seconds

plt.clf()
fig, ax = plt.subplots(figsize = (15,5))
plot_running(ax, initial_time, final_time)
plot_licks(ax, initial_time, final_time)
plot_rewards(ax, initial_time, final_time)
plot_stimuli(ax, initial_time, final_time, image_stimulus_presentations)

ax.legend(['running speed', 'licks', 'rewards'])

ax.set_ylabel('running speed (cm/s)')
ax.set_xlabel('time in session (s)')
ax.set_xlim(initial_time, final_time)
ax.set_title('a short section of the session');

Above, we can see that stimuli were being delivered at a regular cadence (250 ms on, 500 ms off). There were changes to new stimuli at t = 778.6 and t = 793.7, as indicated by the change in the color of the bars. The mouse licked inside of the required response window following both stimulus changes and received a reward coincident with the first lick following the change. The subsequent licks are likely a result of the mouse consuming the water reward. There was also a brief bout of two licks, likely representing impulsivity, at t = 786.9.

trials¶

We can view attributes of every trial here. Below is a random sample of 5 trials

In [24]:
dataset.trials.sample(5, random_state=42)
Out[24]:
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
trials_id
304 2122.312731 2132.621387 im066 im061 True 2128.355604 True False [] NaN inf NaN 0.000 False False True False False False 127593 10.308655
500 3766.808308 3774.865067 im069 im085 True 3770.615985 True False [] NaN inf NaN 0.000 False False True False False False 226045 8.056759
441 3275.262806 3275.696514 im085 im085 False NaN False False [3275.3795675365254] NaN NaN NaN 0.000 False False False False True False -99 0.433709
153 1246.511704 1253.784525 im077 im062 True 1249.518735 True False [1249.9479218395427, 1250.0646784896962, 1250.... 1249.947922 0.429187 1249.947922 0.007 True False False False False False 74907 7.272821
502 3784.139528 3791.445645 im063 im077 True 3787.179880 True False [] NaN inf NaN 0.000 False False True False False False 227038 7.306117

we can examine one trial in some detail. Let's randomly select a hit trial.¶

Some things to note:

  • The trial started at 831.2635398912244 seconds (start_time) relative to the start of the session.
  • The stimulus changed from 'im063' (intial_image_name) to 'im069' (change_image_name) at t = 834.287206646593 seconds (change_time) relative to the start of the session.
  • The animal's first lick (lick_times[0]) and response_time was at t = 834.69975263 seconds relative to the start of the session.
  • The response_latency, which is response_time - change_time, was 0.41254598174464263 seconds.
  • A reward (reward_time) was delivered at 834.6997526283376 seconds relative to the start of the session. This was coincident with the first lick.
In [25]:
dataset.trials.query('hit').sample(random_state=0).to_dict('records')
Out[25]:
[{'start_time': 831.2635398912244,
  'stop_time': 838.5529783256352,
  'initial_image_name': 'im063',
  'change_image_name': 'im069',
  'is_change': True,
  'change_time': 834.287206646593,
  'go': True,
  'catch': False,
  'lick_times': array([834.69975263, 834.81651755, 835.1001309 , 835.25021287,
         835.40033855, 835.53378616, 835.68391515, 835.83403254,
         836.01752922, 836.16765357, 836.33444306, 836.51795332,
         836.6513857 ]),
  'response_time': 834.6997526283376,
  'response_latency': 0.41254598174464263,
  'reward_time': 834.6997526283376,
  'reward_volume': 0.007,
  'hit': True,
  'false_alarm': False,
  'miss': False,
  'correct_reject': False,
  'aborted': False,
  'auto_rewarded': False,
  'change_frame': 50014,
  'trial_length': 7.28943843441084}]

One useful method is the get_performance_metrics method, which returns some summary metrics on the session, derived from the 'rolling_performance_df'¶

In [26]:
behavior_session_dict[behavior_session_id].get_performance_metrics()
Out[26]:
{'trial_count': 516,
 'go_trial_count': 285,
 'catch_trial_count': 41,
 'hit_trial_count': 112,
 'miss_trial_count': 173,
 'false_alarm_trial_count': 4,
 'correct_reject_trial_count': 37,
 'auto_reward_count': 5,
 'earned_reward_count': 112,
 'total_reward_count': 117,
 'total_reward_volume': 0.8090000000000003,
 'maximum_reward_rate': 4.538096320942588,
 'engaged_trial_count': 286,
 'mean_hit_rate': 0.5083809219533413,
 'mean_hit_rate_uncorrected': 0.5117040303377993,
 'mean_hit_rate_engaged': 0.8257788159919639,
 'mean_false_alarm_rate': 0.14930388037062595,
 'mean_false_alarm_rate_uncorrected': 0.14679636896218573,
 'mean_false_alarm_rate_engaged': 0.2690580253080253,
 'mean_dprime': 1.1510474492903155,
 'mean_dprime_engaged': 1.6017817039091784,
 'max_dprime': 2.1577849816633154,
 'max_dprime_engaged': 2.1577849816633154}

we can build out a new table that has all performance data for every session as follows:¶

This might take a minute or so. The AllenSDK will be extracting the performance data from the NWB file for every session individually.

In [27]:
behavior_performance_table = pd.DataFrame(
    [behavior_session_dict[behavior_session_id].get_performance_metrics() for behavior_session_id in behavior_session_ids]
).set_index(behavior_session_ids)
In [28]:
behavior_performance_table.head()
Out[28]:
trial_count go_trial_count catch_trial_count hit_trial_count miss_trial_count false_alarm_trial_count correct_reject_trial_count auto_reward_count earned_reward_count total_reward_count total_reward_volume maximum_reward_rate engaged_trial_count mean_hit_rate mean_hit_rate_uncorrected mean_hit_rate_engaged mean_false_alarm_rate mean_false_alarm_rate_uncorrected mean_false_alarm_rate_engaged mean_dprime mean_dprime_engaged max_dprime max_dprime_engaged
837658854 118 0 0 0 0 0 0 118 0 118 0.590 4.852157 101 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
838515247 1405 133 13 106 27 6 7 5 106 111 1.085 5.294545 346 0.808946 0.819726 0.822212 0.574381 0.624039 0.421906 0.662053 1.145407 1.832280 1.832280
839219841 451 335 61 48 287 1 60 29 48 77 0.625 5.015095 49 0.231115 0.233778 0.809956 0.059502 0.025165 0.176463 0.452645 1.875796 2.288211 2.288211
839565422 683 269 41 107 162 4 37 15 107 122 1.145 5.393113 403 0.523621 0.529213 0.877314 0.192331 0.169870 0.377171 1.208391 1.599180 2.201408 2.201408
839912316 966 174 20 103 71 6 14 10 103 113 1.080 3.833645 583 0.778670 0.785813 0.919466 0.439618 0.511879 0.586558 1.164035 1.240594 1.679661 1.644854

for convenience, we should merge this with the existing table we built for this mouse¶

In [29]:
this_mouse_table = this_mouse_table.merge(
    behavior_performance_table,
    left_index = True,
    right_index = True,
)
this_mouse_table.head()
Out[29]:
ophys_session_id ophys_container_id mouse_id indicator full_genotype driver_line cre_line reporter_line sex age_in_days imaging_plane_group_count project_code session_type session_number image_set behavior_type experience_level prior_exposures_to_session_type prior_exposures_to_image_set prior_exposures_to_omissions date_of_acquisition equipment_name num_depths_per_area ophys_experiment_id num_targeted_structures catch_trial_count_x hit_trial_count_x go_trial_count_x miss_trial_count_x trial_count_x false_alarm_trial_count_x file_id engaged_trial_count_x correct_reject_trial_count_x trial_count_y go_trial_count_y catch_trial_count_y hit_trial_count_y miss_trial_count_y false_alarm_trial_count_y correct_reject_trial_count_y auto_reward_count earned_reward_count total_reward_count total_reward_volume maximum_reward_rate engaged_trial_count_y mean_hit_rate mean_hit_rate_uncorrected mean_hit_rate_engaged mean_false_alarm_rate mean_false_alarm_rate_uncorrected mean_false_alarm_rate_engaged mean_dprime mean_dprime_engaged max_dprime max_dprime_engaged
behavior_session_id
837658854 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 72 <NA> VisualBehavior TRAINING_0_gratings_autorewards_15min <NA> gratings active_behavior Training 0 <NA> 0 2019-03-15 14:49:24.015000+00:00 BEH.B-Box3 <NA> NaN <NA> 0 0 0 0 118 0 5235 101 0 118 0 0 0 0 0 0 118 0 118 0.590 4.852157 101 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
838515247 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 75 <NA> VisualBehavior TRAINING_1_gratings <NA> gratings active_behavior Training 0 <NA> 0 2019-03-18 13:44:01.474000+00:00 BEH.B-Box1 <NA> NaN <NA> 13 106 133 27 1405 6 5236 341 7 1405 133 13 106 27 6 7 5 106 111 1.085 5.294545 346 0.808946 0.819726 0.822212 0.574381 0.624039 0.421906 0.662053 1.145407 1.832280 1.832280
839219841 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 76 <NA> VisualBehavior TRAINING_1_gratings <NA> gratings active_behavior Training 1 <NA> 0 2019-03-19 12:50:12.068000+00:00 BEH.B-Box1 <NA> NaN <NA> 61 48 335 287 451 1 5237 47 60 451 335 61 48 287 1 60 29 48 77 0.625 5.015095 49 0.231115 0.233778 0.809956 0.059502 0.025165 0.176463 0.452645 1.875796 2.288211 2.288211
839565422 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 77 <NA> VisualBehavior TRAINING_1_gratings <NA> gratings active_behavior Training 2 <NA> 0 2019-03-20 13:16:44.461000+00:00 BEH.B-Box1 <NA> NaN <NA> 41 107 269 162 683 4 5238 386 37 683 269 41 107 162 4 37 15 107 122 1.145 5.393113 403 0.523621 0.529213 0.877314 0.192331 0.169870 0.377171 1.208391 1.599180 2.201408 2.201408
839912316 <NA> NaN 445002 GCaMP6f Slc17a7-IRES2-Cre/wt;Camk2a-tTA/wt;Ai93(TITL-G... [Slc17a7-IRES2-Cre, Camk2a-tTA] Slc17a7-IRES2-Cre Ai93(TITL-GCaMP6f) M 78 <NA> VisualBehavior TRAINING_2_gratings_flashed <NA> gratings active_behavior Training 0 <NA> 0 2019-03-21 12:54:25.388000+00:00 BEH.B-Box1 <NA> NaN <NA> 20 103 174 71 966 6 5239 583 14 966 174 20 103 71 6 14 10 103 113 1.080 3.833645 583 0.778670 0.785813 0.919466 0.439618 0.511879 0.586558 1.164035 1.240594 1.679661 1.644854

Now we can plot the max_dprime value for every session¶

We can see that this particular mouse performed relatively consistently for every session as it progressed through training.

In [30]:
fig, ax = plt.subplots(figsize = (15,5))

ax.plot(
    np.arange(len(this_mouse_table)),
    this_mouse_table['max_dprime'],
    marker = 'o'
)
ax.set_xticks(range(len(this_mouse_table)))
ax.set_xticklabels(list(this_mouse_table['session_type'].values),rotation = 30, ha='right')

# make alternating black/gray vspans for visual clarity
colors = ['black', 'gray']
for ii in range(len(this_mouse_table)):
    ax.axvspan(ii - 0.5, ii + 0.5, color = colors[ii%2], alpha=0.25)

ax.set_xlim(-0.5, len(this_mouse_table) - 0.5)
ax.set_ylabel('dprime')
ax.set_xlabel('session type')
ax.set_title("Max of rolling d' for every session for mouse {}".format(mouse_id))
fig.tight_layout()
In [ ]: