Debian Codegraph @

commissioning/kwfile_dict.py

raw symbols SCIP
1 import re,os,glob
2 import numpy as N
3 import pylab as P
4
5 def read_kwfile(fname):
6 """Syntax used as of r452 in commissioning tests"""
7 d={}
8 f=open(fname)
9 for line in f:
10 try:
11 kvpair=re.findall("(.*):: (.*)=(.*)$",line)[0]
12 d['name']=os.path.basename(kvpair[0])
13 key,val=kvpair[1:]
14 d[key.lower()]=val
15 except (ValueError,IndexError):
16 break
17
18 f.close()
19 return d
20
21 def accumdict(fulldict,adict):
22 if len(fulldict) == 0:
23 fulldict=fulldict.fromkeys(adict)
24 for k in fulldict:
25 fulldict[k]=[adict[k]]
26 else:
27 for k in fulldict:
28 fulldict[k].append(adict.get(k,0.0))
29 return fulldict
30
31 def setstruct(mystruct,fulldict):
32 for k in fulldict:
33 try:
34 setattr(mystruct,k,N.array([float(x) for x in fulldict[k]]))
35 except ValueError:
36 setattr(mystruct,k,N.array(fulldict[k]))
37 return mystruct
38
39 class Container(object):
40 def __init__(self,fulldict):
41 for k in fulldict:
42 try:
43 setattr(self,k,N.array([float(x) for x in fulldict[k]]))
44 except ValueError:
45 setattr(self,k,N.array(fulldict[k]))
46
47 def plot(self,label,outname):
48 P.clf()
49 P.plot(self.tra_Discrep,'.')
50 P.ylabel('(pysyn-syn)/syn')
51 P.title(label)
52 P.savefig(outname)
53
54 def getcountrate(dirname):
55 flist=glob.glob("%s/*.log"%dirname)
56 if len(flist) == 0:
57 raise ValueError("No files found")
58 crdict={}
59 for fname in flist:
60 d=read_kwfile(fname)
61 crdict=accumdict(crdict,d)
62
63 crdata=Container(crdict)
64 return crdata
65