-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel_results.py
55 lines (48 loc) · 1.75 KB
/
model_results.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
import numpy as np
import matplotlib.pyplot as plt
import sys
import h5py
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.exit('No filename')
f = h5py.File(sys.argv[1])
grid = f['model']['grid']
grid_no = f['model']['output']['__main__']['elements']
species = f['model']['output']['__main__']['species']
res = f['trial0']['output']['__main__']['population']
shape = (res.shape[0],res.shape[-1]+1)
#region name is in -3 of every row grid_no
regions = f['model']['regions']
# for g in grid:
# print g
vols = {}
voxels = {}
for reg in regions:
vols[reg] = 0
voxels[reg] = []
for reg in regions:
for i,g in enumerate(grid):
if regions[g["region"]] in reg:
vols[reg] += g["volume"]
voxels[reg].append(i)
header = "time"
for i,specie in enumerate(species):
header += " " + specie
voli = 0
tots = []
for reg in regions:
if reg == 'default':
continue
voli += vols[reg]
for fi in f:
if 'trial' in fi:
file_dend = sys.argv[1]+'_'+fi+'_conc_'+reg
res = f[fi]['output']['__main__']['population']
shape = (res.shape[0],res.shape[-1]+1)
out = np.zeros(shape)
out[:,0] = f[fi]['output']['__main__']['times']
for i,specie in enumerate(species):
out[:,i+1] = res[:,voxels[reg],i].sum(axis=1)/vols[reg]/6.022*10
if specie == 'cAMP' or specie == 'PKAc':
print specie,out[:-1000,i+1].mean(),specie,out[:-1000,i+1].mean()**0.5
np.savetxt(file_dend,out,comments="",header=header)