This textbook was written for the clinical research community at Johns Hopkins leveraging the precision medicine analytics platform (PMAP). These notebooks are available in html form on the Precision Medicine portal as well as in computational form in the CAMP-share folder on Crunchr (Crunchr.pm.jh.edu).

How to Access DICOMs from XNAT via Jupyter Notebook Tutorial

Learning Objectives

  1. Install and Connect to XNAT Session
  2. Understand Data Organzation in XNAT
  3. Visualize the data with Pydicom

Table of contents

Prerequisites to implement this notebook:

  1. IRB approved Study
  2. XNAT project provisioned Study
  3. XNAT project permissions granted and 'honest broker' step completed by CCDA

Purpose:

Currently, accessing patient DICOMs requires managing several files and loading them.
Using an XNAT Session to programmatically access DICOMs using Jupyter notebook, the user can easily directly load a file instead of having to manage the various files in the file system and loading them one-by-one.

Install and Connect to XNAT Session

Install/Import XNAT and subsequent complementary packages for viewing and analysis:

Install XNAT using pip only if not installed already

Connect to using your XNAT Session URL and XNAT User ID
Then enter XNAT password to allow access

View All Accessible Studies in XNAT

View all accessible projects in XNAT

2 Projects shown here: "Daisy" and "kaggle"

Example Dataset used: RSNA-MICCAI Brain Tumor Radiogenomic Classification

Number of all Patients within Dataset:

Access All Patients in XNAT Study

Can Access list of all Patient Numbers/Labels in respective Project
This allows the user to explore the study with its various patients and imaging series, aid their research analysis by knowing all the patients and number of patients in the study. This list can also be used to modify inclusion criteria.

Understanding Data Organization in XNAT:


XNAT has specific terminology to its Data Organization and understanding aides in research analysis of the study. The Diagram below explains the organization format.

Dataset > Patient > MR Session > Patient Metadata + Scans

Scans > T2w, T1w, FLAIR, T1wCE

Create File object for particular Subject Scan
File Object - Allows us to use, access and manipulate the particular file

ex: T2w Scan for Patient "00822"

Parameters Include:

Visualize T2w Scan and DICOM Metadata

It is crucial to visualize DICOM Data to understand the study and patient imaging series -- which allows researchers to better build their analysis. Instead of managing various files, XNAT allows one to easily view the Patient Imaging series directly in Jupyter Notebook.

Using Pydicom, we read the File Object (T2w image) and display it using matplotlib.pyplot

Accessing DICOM Metadata:
By Accesing the raw DICOM Header Metadata, researchers can better understand the study and modify inclusion/exclusion criteria. Via XNAT, the user does not have to manage metadata and can instead view it easily using the File Object

Download Patient Scans:

Users can locally download Patient Imaging Series if they need local access to the file.

download_dir requires path to file where Patient Series should be downloaded to.