-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_abc_model_xml.py
80 lines (73 loc) · 3.07 KB
/
read_abc_model_xml.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Update the model in modeldir (experiment expt) using the given model
# parameters. Write out new model.xml file and updated experiment.xml
# file.
def read_abc_model_xml (modeldir,expt):
# Init params:
a=0; b=0; c=0; d=0;
A=0; B=0; C=0; T=0;
vpeak=0; vinit=0; uinit=0;
modelxml = modeldir+'/model.xml';
exptxml = modeldir+'/experiment'+repr(expt)+'.xml';
# We have to deal with the namespace used in the model.xml file.
ns = {'UL': 'http://www.shef.ac.uk/SpineMLNetworkLayer',
'LL': 'http://www.shef.ac.uk/SpineMLLowLevelNetworkLayer'}
# Parse the model to find the parameters.
import xml.etree.ElementTree as et
et.register_namespace('', "http://www.shef.ac.uk/SpineMLNetworkLayer")
et.register_namespace('LL', "http://www.shef.ac.uk/SpineMLLowLevelNetworkLayer")
tree = et.parse(modelxml)
root = tree.getroot()
for child in root.findall('./*/LL:Neuron/', ns):
nm = child.get('name')
#print 'Model file ', nm;
if nm == 'a':
a = float(child.find('*').get('value'))
elif nm == 'b':
b = float(child.find('*').get('value'))
elif nm == 'c':
c = float(child.find('*').get('value'))
elif nm == 'd':
d = float(child.find('*').get('value'))
elif nm == 'A':
A = float(child.find('*').get('value'))
elif nm == 'B':
B = float(child.find('*').get('value'))
elif nm == 'C':
C = float(child.find('*').get('value'))
elif nm == 'T':
T = float(child.find('*').get('value'))
elif nm == 'v':
vinit = float(child.find('*').get('value'))
elif nm == 'u':
uinit = float(child.find('*').get('value'))
elif nm == 'Vpeak':
vpeak = float(child.find('*').get('value'))
# Parse the expt data to find the currents and any parameter overrides
tree = et.parse(exptxml)
root = tree.getroot()
for child in root.findall('.//UL:Property', ns):
nm = child.get('name')
#print 'Expt file ', nm
if nm == 'a':
a = float(child.find('UL:FixedValue').get('value'))
elif nm == 'b':
b = float(child.find('UL:FixedValue').get('value'))
elif nm == 'c':
c = float(child.find('UL:FixedValue').get('value'))
elif nm == 'd':
d = float(child.find('UL:FixedValue').get('value'))
elif nm == 'A':
A = float(child.find('UL:FixedValue').get('value'))
elif nm == 'B':
B = float(child.find('UL:FixedValue').get('value'))
elif nm == 'C':
C = float(child.find('UL:FixedValue').get('value'))
elif nm == 'T':
T = float(child.find('UL:FixedValue').get('value'))
elif nm == 'v':
vinit = float(child.find('UL:FixedValue').get('value'))
elif nm == 'u':
uinit = float(child.find('UL:FixedValue').get('value'))
elif nm == 'Vpeak':
vpeak = float(child.find('UL:FixedValue').get('value'))
return a, b, c, d, A, B, C, T, vpeak, vinit, uinit