Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import pyxnat
  2. import os
  3. import time
  4.  
  5. # A python 2.7 / pyxnat script for downloading the resources from an xnat project
  6.  
  7. # gather source xnat details
  8. print '** DOWNLOAD XNAT PROJECT RESOURCES **'
  9. xnat_url=raw_input("Enter the xnat url: ")
  10. project_name=raw_input("Enter the xnat project id: ")
  11. print 'Enter xnat credentials'
  12. interface = pyxnat.Interface(xnat_url)
  13. project = interface.select.project(project_name)
  14.  
  15. if project.exists():
  16. filepath=raw_input("Project found. Where do you want the files?: ")
  17. project_filepath = os.path.join(filepath, project_name)
  18. if os.path.isdir(filepath):
  19. time_start_script=time.time()
  20. for subject_id in interface.select.project(project_name).subjects().get():
  21. subject = project.subject(subject_id)
  22. subject_filepath = os.path.join(project_filepath, subject.label())
  23. print "{}".format(subject.label())
  24. time_start_subject=time.time()
  25. for experiment_id in subject.experiments().get():
  26. experiment = subject.experiment(experiment_id)
  27. experiment_filepath = os.path.join(subject_filepath, experiment.label())
  28. if experiment.scans():
  29. os.makedirs(experiment_filepath)
  30. print "\t{}".format(experiment.label())
  31. experiment.scans().download(experiment_filepath)
  32. print '\nDownload completed in {} seconds'.format(time.time()-time_start_script)
  33. else:
  34. print 'cannot find dir: {}'.format(filepath)
  35. else:
  36. print 'cannot attach to project, {} on {}'.format(project_name, xnat_url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement