-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_vars.py
executable file
·46 lines (35 loc) · 1.79 KB
/
set_vars.py
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
#!/usr/bin/env python
import sys
import pyxnat
from dax import XnatUtils
source_project = sys.argv[1]
dest_project = sys.argv[2]
subject = sys.argv[3]
xnat = XnatUtils.InterfaceTemp()
# Subject variables
source_subject = xnat.select(
'/projects/{0}/subjects/{1}'.format(source_project,subject) )
dest_subject = xnat.select(
'/projects/{0}/subjects/{1}'.format(dest_project,subject) )
dob = source_subject.attrs.get('xnat:demographicData/dob')
gender = source_subject.attrs.get('xnat:demographicData/gender')
handedness = source_subject.attrs.get('xnat:demographicData/handedness')
race = source_subject.attrs.get('xnat:demographicData/race')
#sid = source_subject.attrs.get("xnat:subjectData/fields/field[name='id']/field")
sid = source_subject.xpath("/xnat:Subject/xnat:fields/xnat:field[@name='id']/text()[2]")[0]
dest_subject.attrs.set('xnat:subjectData/demographics[@xsi:type=xnat:demographicData]/dob', dob)
dest_subject.attrs.set('xnat:subjectData/demographics[@xsi:type=xnat:demographicData]/gender', gender)
dest_subject.attrs.set('xnat:subjectData/demographics[@xsi:type=xnat:demographicData]/handedness', handedness)
dest_subject.attrs.set('xnat:subjectData/demographics[@xsi:type=xnat:demographicData]/race', race)
dest_subject.attrs.set("xnat:subjectData/fields/field[name='id']/field", sid)
# Session variables
source_session = xnat.select(
'/projects/{0}/subjects/{1}/experiments/{1}'.format(source_project,subject) )
dest_session = xnat.select(
'/projects/{0}/subjects/{1}/experiments/{1}'.format(dest_project,subject) )
sdate = source_session.attrs.get('xnat:mrSessionData/date')
stime = source_session.attrs.get('xnat:mrSessionData/time')
dest_session.attrs.set('xnat:mrSessionData/date',sdate)
dest_session.attrs.set('xnat:mrSessionData/time',stime)
# Clean up
xnat.disconnect()