Set up Coding Environment#

This notebook will ensure that your coding environment is set up for the interactive activities in this textbook. You do not need to worry about any of this if you’re running code on Binder (fully pre-configured) or Colab (each notebook installs what it needs automatically) – just use the rocket icon at the top of any page. You can simply ignore this page and get on with the data!

This page is for anyone setting up a local Python environment on their own machine.

Package Requirements#

To run this book’s code on your own machine, we have to ensure that your coding environment has all of the proper packages installed.

We provide separate requirements files for different lessons:

You can install requirements using:

pip install -r requirements_lessons_1-2.txt

Core packages required for Lessons 1-2:#

dandi>=0.74.0          # Includes: pynwb, h5py, hdmf
seaborn>=0.11.0        # Visualization package
remfile                # Data streaming

Packages for Lessons 3-4 (Allen Cell Types):#

allensdk>=2.11.2       # Includes: numpy<1.24, pandas, scipy, matplotlib
                       # Requires Python 3.11!

Additional packages for Greatest Hits:#

pynapple                # Neural data analysis
plotly                  # Interactive plotting
fsspec                  # File system interface

The code cells below will check for and install these packages as needed.

Core Packages#

We’ll check for the essential packages that include all necessary dependencies.

# This will ensure that the correct version of dandi is installed
try:
    import dandi
    if dandi.__version__>='0.74.0':
        print('Updated DANDI installed.')
    else:
        response = input('Old version of DANDI installed. Would you like to install a newer version of DANDI? (Y/N)')
        if response.upper() == 'Y':
            !pip install --upgrade dandi
except ImportError as e:
    !pip install dandi
Updated DANDI installed.
# Check for seaborn (visualization package)
try:
    import seaborn
    print('seaborn installed.')
except ImportError as e:
    !pip install seaborn
seaborn installed.

AllenSDK (Lessons 3 & 4 only)#

Important: The AllenSDK requires numpy<1.24, which is incompatible with Python 3.12+. If you’re using Python 3.12 or later, you’ll need to create a Python 3.11 environment.

On Binder: This is already configured for you – Binder builds a Python 3.11 environment automatically.

On your local machine: Use conda to create a Python 3.11 environment:

conda create --name nwb4edu python=3.11
conda activate nwb4edu
pip install allensdk
# Check for allensdk (Lessons 3 & 4 only)
try:
    import allensdk
    print('allensdk installed.')
    print(f'Version: {allensdk.__version__}')
except ImportError as e:
    print('allensdk is not installed.')
    print('Note: allensdk requires Python 3.11 or earlier.')
    print('See instructions above for creating a compatible environment.')
allensdk is not installed.
Note: allensdk requires Python 3.11 or earlier.
See instructions above for creating a compatible environment.

Greatest Hits Packages#

For the Greatest Hits lessons, you’ll also need these additional packages:

# Check for pynapple
try:
    import pynapple
    print('pynapple installed.')
except ImportError as e:
    !pip install pynapple
pynapple installed.
# Check for plotly
try:
    import plotly
    print('plotly installed.')
except ImportError as e:
    !pip install plotly
plotly installed.
# Check for fsspec
try:
    import fsspec
    print('fsspec installed.')
except ImportError as e:
    !pip install fsspec
fsspec installed.

Configuring for Data Streaming#

Some lessons in this book stream data directly from DANDI rather than downloading it, using the remfile package (installed via the cell below). This works out of the box in any environment – Binder, Colab, or your own machine – no special configuration needed.

# Check for remfile (required for streaming)
try:
    import remfile
    print('remfile installed.')
except ImportError as e:
    !pip install remfile
remfile installed.