Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyxnat
- import os
- import time
- # A python 2.7 / pyxnat script for downloading the resources from an xnat project
- # gather source xnat details
- print '** DOWNLOAD XNAT PROJECT RESOURCES **'
- xnat_url=raw_input("Enter the xnat url: ")
- project_name=raw_input("Enter the xnat project id: ")
- print 'Enter xnat credentials'
- interface = pyxnat.Interface(xnat_url)
- project = interface.select.project(project_name)
- if project.exists():
- filepath=raw_input("Project found. Where do you want the files?: ")
- project_filepath = os.path.join(filepath, project_name)
- if os.path.isdir(filepath):
- time_start_script=time.time()
- for subject_id in interface.select.project(project_name).subjects().get():
- subject = project.subject(subject_id)
- subject_filepath = os.path.join(project_filepath, subject.label())
- print "{}".format(subject.label())
- time_start_subject=time.time()
- for experiment_id in subject.experiments().get():
- experiment = subject.experiment(experiment_id)
- experiment_filepath = os.path.join(subject_filepath, experiment.label())
- if experiment.scans():
- os.makedirs(experiment_filepath)
- print "\t{}".format(experiment.label())
- experiment.scans().download(experiment_filepath)
- print '\nDownload completed in {} seconds'.format(time.time()-time_start_script)
- else:
- print 'cannot find dir: {}'.format(filepath)
- else:
- print 'cannot attach to project, {} on {}'.format(project_name, xnat_url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement