-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupload_scans.py
More file actions
executable file
·49 lines (34 loc) · 1.84 KB
/
Copy pathupload_scans.py
File metadata and controls
executable file
·49 lines (34 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# Script written by Lorena Escudero (Department of Radiology, University of Cambridge)
# to upload in batch .zip files containing scans - April 2020
#
# Usage: edit xnathost/project/user and give as input a .txt file containing a line per patient+session
# in the form 'subject_id:session_id:/path/to/scans.zip'
#
# Based on xnatpy/examples/upload_data.py
import xnat
import os
import getpass
def upload_scans(session, project_id, subject_id, experiment_id, scans_file):
xnat_project = session.projects[project_id]
# We create the subject with the following line:
xnat_subject = session.classes.SubjectData(parent=xnat_project, label=subject_id)
# And now we upload with the import_ method - the experiment will be created in this step
session.services.import_(scans_file,overwrite=None, quarantine=False, destination='/archive', trigger_pipelines=None,project=project_id, subject=subject_id, experiment=experiment_id, content_type=None)
# ---------------------------------------------------------------------------------------------------------------------
if __name__ == '__main__':
input_list = 'test_file.txt'
xnathost = 'XNATURL'
project_id = 'PROJECT'
user_id = 'USER'
pwd = getpass.getpass("Password for user name : %s = " % user_id)
with xnat.connect(xnathost, user=user_id, password=pwd) as session:
with open(input_list, 'r') as fp:
line = fp.readline()
while line:
line = line.strip()
subject_id = line.split(':')[0]
experiment_id = line.split(':')[1]
scans_file = line.split(':')[2]
upload_scans(session, project_id, subject_id, experiment_id, scans_file)
line = fp.readline()