Skip to content

Instantly share code, notes, and snippets.

@jvsoest
Created July 24, 2017 13:12
Show Gist options
  • Save jvsoest/6136be82801b0cfa159925f2f4259e1a to your computer and use it in GitHub Desktop.
Save jvsoest/6136be82801b0cfa159925f2f4259e1a to your computer and use it in GitHub Desktop.
XNAT python
###### login to XNAT and search/get files ########
import xnat
session = xnat.connect('https://xnat.bmia.nl', user='bla')
session.projects
project = session.projects['STW_STRATEGY_HN_VELLORE']
subject = project.subjects['BMIAXNAT_S08453']
experiment = subject.experiments['BMIAXNAT_E28844']
scan = experiment.scans['701']
#download the actual scan (which means zip at XNAT, download zip file)
scan.download('~/701.zip')
####### unzip #######
import zipfile
import os
zip_ref = zipfile.ZipFile('~/701.zip', 'r')
os.mkdir('~/701')
zip_ref.extractall('~/701/')
zip_ref.close()
####### read dicom ######
import dicom
dFile = dicom.read_file('~/701/test1234_20170608_/scans/701-unknown/resources/DICOM/files/1.3.6.1.4.1.40744.29.171823746954830055731259734691543906281-701-10-sktbhh.dcm')
dFile.PatientName
dFile.PatientID
dFile.StudyDate
dFile.SeriesDate
dFile.Modality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment