root/virtexp/trunk/virtexp/tests/currents/currents.py

Revision 14 (checked in by cbc, 12 years ago)

Adding current checking script.

Line 
1 #!/usr/local/python272/bin/python
2 from glob import glob
3 from pprint import pformat
4 import cmath
5 import re
6
7 log_pattern = "/var/opt/gmc/gliders/ramses/logs/ramses_network_20111213*.log"
8 stamp_pattern = re.compile("ramses_network_(\w+)")
9 vx_pattern = re.compile("m_water_vx\(m/s\)=(\S+)")
10 vy_pattern = re.compile("m_water_vy\(m/s\)=(\S+)")
11
12 isNorth = lambda phi: (phi >= (3*cmath.pi/8))  and (phi <= (5*cmath.pi/8))
13 isSouth = lambda phi: (phi <= (-3*cmath.pi/8)) and (phi >= (-5*cmath.pi/8))
14 isNEast = lambda phi: (phi >  (cmath.pi/8))    and (phi <  (3*cmath.pi/8))
15 isNWest = lambda phi: (phi >  (5*cmath.pi/8))  and (phi <  (7*cmath.pi/8))
16 isSEast = lambda phi: (phi <  (-cmath.pi/8))   and (phi >  (-3*cmath.pi/8))
17 isSWest = lambda phi: (phi <  (-5*cmath.pi/8)) and (phi >  (-7*cmath.pi/8))
18 isEast  = lambda phi: ((phi >= 0) and (phi <=  (cmath.pi/8))) or \
19                       ((phi <= 0) and (phi >=  (-cmath.pi/8)))
20 isWest  = lambda phi: ((phi >= 0) and (phi >=  (7*cmath.pi/8))) or \
21                       ((phi <= 0) and (phi <=  (-7*cmath.pi/8)))
22
23
24 logs = glob(log_pattern)
25 logs.sort()
26 logs.reverse()
27
28 currents = []
29
30 for log in logs:
31     stamp = stamp_pattern.search(log).groups()[0]
32     handle = open(log)
33     content = handle.readlines()
34     handle.close()
35     content = zip(content[:-1],content[1:])
36     for line0,line1 in content:
37         match = vx_pattern.search(line0)
38         if match:
39             vx = match.groups()[0]
40             match = vy_pattern.search(line1)
41             if match:
42                 vy = match.groups()[0]
43                 currents.append((stamp,complex(float(vx),float(vy))))
44                 break
45
46 ccurrents = pformat(currents)
47 currents = [(stamp,cmath.polar(current)) for stamp, current in currents]
48 pcurrents = pformat(currents)
49
50 N  = [stamp for stamp,current in currents if isNorth(current[1])]
51 NE = [stamp for stamp,current in currents if isNEast(current[1])]
52 E  = [stamp for stamp,current in currents if isEast(current[1])]
53 SE = [stamp for stamp,current in currents if isSEast(current[1])]
54 S  = [stamp for stamp,current in currents if isSouth(current[1])]
55 SW = [stamp for stamp,current in currents if isSWest(current[1])]
56 W  = [stamp for stamp,current in currents if isWest(current[1])]
57 NW = [stamp for stamp,current in currents if isNWest(current[1])]
58
59 print "Number of surfacings:",len(currents)
60 print "Current distribution:"
61 print "North:     %s%%" % (float(len(N))/len(currents))
62 print "Northeast: %s%%" % (float(len(NE))/len(currents))
63 print "East:      %s%%" % (float(len(E))/len(currents))
64 print "Southeast: %s%%" % (float(len(SE))/len(currents))
65 print "South:     %s%%" % (float(len(S))/len(currents))
66 print "Southwest: %s%%" % (float(len(SW))/len(currents))
67 print "West:      %s%%" % (float(len(W))/len(currents))
68 print "Northwest: %s%%" % (float(len(NW))/len(currents))
69 print
70 print "Cartesian currents:"
71 print ccurrents
72 print
73 print "Polar currents:"
74 print pcurrents
75
Note: See TracBrowser for help on using the browser.