Skip to main content
Skip table of contents

Using Jupyter

Accessing Jupyter

To access a running Jupyter notebook server, navigate to it from the top navigation menu. Click on the notebook icon and a new tab will open in your browser with JupyterLab. If no Jupyter servers are currently running, please refer to the Starting and Stopping Jupyter section for instructions on how to start a Jupyter server.

Explore XNAT Data with JupyterLab

JupyterLab is a powerful tool for exploring and analyzing XNAT data in an interactive and flexible environment. This documentation provides a comprehensive guide on leveraging JupyterLab's capabilities to efficiently navigate, manipulate, and analyze XNAT data.

Navigating the file system

When launching a Jupyter server from XNAT, a set of mounts is collected for the container running the Jupyter server, tailored to the specific XNAT context. These mounts provide access to relevant data and resources within the Jupyter container.

After you've accessed JupyterLab, start a terminal and explore these mounts:

Project Mounts

Mounts

Access

/data/projects/{projectId}/experiments/{experimentLabel}

All experiment directories are available. Experiments shared into the project are not available.

The experiment directories are organized as follows:

  • {experimentLabel}/RESOURCES.
    Will not exist if there are no experiment resources

  • {experimentLabel}/SCANS/{scanLabel}/{format}
    Example: mrSession123/SCANS/T1/DICOM/*.dcm

Read only

/data/projects/{projectId}/resources

Only if there are project resources.

Read only

/data/projects/{projectId}/subjects/{subjectLabel}

All subject resource directories are available. Only subjects with resources will have directories.

Read only

/workspace/{username}

Persistent directory for storing your Jupyter notebooks and any other intermediate work/files.

Read / write

Subject Mounts

As of XNAT 1.8.10 and JupyterHub Integration 1.1.0, resource files from shared subjects and experiments can now be mounted into your Jupyter environment. See: Understanding Data Sharing in XNAT's Security Structure

Mounts

Access

/data/projects/{projectId}/experiments/{experimentLabel}

Only experiments belonging to the specified subject are mounted. Does not support subjects and experiments shared across projects. Can only start Jupyter on a subject from the subjects primary project.

The experiment directories are organized as follows:

  • {experimentLabel}/RESOURCES.
    Will not exist if there are no experiment resources

  • {experimentLabel}/SCANS/{scanLabel}/{format}
    Example: mrSession123/SCANS/T1/DICOM/*.dcm

Read only

/data/projects/{projectId}/subjects/{subjectLabel}

Only the specified subject will be mounted and only if the subject has resource files.

Read only

/workspace/{username}

Persistent directory for storing your Jupyter notebooks and any other intermediate work/files.

Read / write

Experiment Mounts

Mounts

/data/projects/{projectId}/experiments/{experimentLabel}

Only the specified experiment will be mounted. Can only start a Jupyter server on an experiment from the experiments primary project.

The experiment directories are organized as follows:

  • {experimentLabel}/RESOURCES.
    Will not exist if there are no experiment resources

  • {experimentLabel}/SCANS/{scanLabel}/{format}
    Example: mrSession123/SCANS/T1/DICOM/*.dcm

Read only

/workspace/{username}

Persistent directory for storing your Jupyter notebooks and any other intermediate work/files.

Read / write


User Workspace Directory

Regardless of the context in which you started Jupyter, the directory /workspace/{username} serves as the root location in JupyterLab. This directory not only stores your Jupyter notebooks, which persist between sessions, but also acts as an ideal location for managing git repositories and other data related to your projects. It is recommended to use version control systems like Git to track and manage changes to your notebooks and code. This allows you to easily collaborate, revert changes, and maintain a history of your work. To facilitate the use of Git, a git-config file is created by default at /workspace/{username}/git/config.

Please exercise caution when working within this directory, as data deleted from here is not automatically backed up by XNAT. It is recommended to regularly commit and push your changes to a remote Git repository

Environmental Variables

Environmental variables are utilized by XNAT to enhance the functionality of Jupyter servers. These variables mainly serve the following purposes:

  1. Identify the XNAT context in which Jupyter was started

  2. Establishing connection with XNAT's REST API from Jupyter

To learn more about the configuration and usage of environmental variables, including details about the XNAT_HOST, XNAT_USER, and XNAT_PASS variables, please refer to the Processing URL section in the documentation. Note that while the Container Service plugin is not utilized, the same feature is implemented within the JupyterHub plugin. In case you are using the xnat-docker-compose project, it may be necessary to coordinate with your administrator to update the processing URL setting, which is a core XNAT preference.

Environmental Variable

Comments

XNAT_HOST

The URL of your XNAT

XNAT_USER

A temporary token which can be used as a username

XNAT_PASS

A temporary token which can be used as a password

XNAT_XSI_TYPE

The XSI type of the XNAT item from where we started Jupyter

XNAT_ITEM_ID

The ID of the XNAT item

XNAT_DATA

The location of the mounted XNAT data. Used by XNATpy to locate mounted XNAT data 

Exporting Notebook Results into XNAT

To save or export data generated from your notebook back into XNAT, you must currently utilize the XNAT REST API.

Sample Notebooks

Explore a collection of sample notebooks available on GitHub to kickstart your data analysis. These sample notebooks cover a wide range of use cases and techniques specifically tailored to working with XNAT data. Explore topics such as interacting with the XNAT REST API, utilizing XNATpy, converting XNAT stored searches into pandas dataframes, and leveraging pydicom with XNAT data. 

References

  1. Docker bind mounts

  2. Processing URL

  3. git-config

  4. XNATpy

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.