-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrace-to-txt
executable file
·62 lines (49 loc) · 1.42 KB
/
trace-to-txt
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
#!/usr/bin/python
import tables as tb
import numpy as np
import os,sys
import pylab as pl
dbfile = sys.argv[1]
burn = int(sys.argv[2])
path, fname = os.path.split(dbfile)
dbname, crap = os.path.splitext(fname)
hf = tb.openFile(dbfile)
hr = hf.root.chain0.PyMCsamples
ind = np.array(np.linspace(burn, len(hr)-1, 500), dtype=int)
os.mkdir(dbname)
os.chdir(dbname)
# Write in longitude, latitude and time
indices_to_keep = hf.root.metadata.ui[:]
(indices_to_keep+1).tofile('indices_to_keep.txt', sep=',')
lpm = hf.root.metadata.logp_mesh
comps = ['lon','lat','t']
for i in xrange(3):
lpm[:,i].tofile(comps[i]+'.txt',sep=',')
try:
urb = hf.root.metadata.urb[:][indices_to_keep]
except:
urb = 0
periurb = hf.root.metadata.periurb[:][indices_to_keep]
urb_cls = 1+periurb+2.*urb
urb_cls.tofile('urb_cls.txt',sep=',')
# Write in the traces
for n in hr.colnames:
# Exclude step method tuning info
if n.find('Metropolis')>-1:
continue
col = hr.colinstances[n]
# Vector-valued variables' traces
if len(col.dtype.shape) > 0:
f = file(n+'.txt','w')
for i in ind:
col[i].tofile(f,sep=',')
if i != ind[-1]:
f.write('\n')
f.close()
# Scalar-valued variables' traces
else:
col[:][ind].tofile(n+'.txt',sep=',')
# Zip and return
os.chdir('..')
os.system('tar -cf %s.tar %s'%(dbname, dbname))
os.system('gzip %s.tar'%dbname)