source: fact/tools/pyscripts/examples/how_to_make_movies.py@ 18066

Last change on this file since 18066 was 13120, checked in by neise, 13 years ago
tidied up a bit. moved examples to examples and deleted scripts, I never used anymore
File size: 4.5 KB
Line 
1import matplotlib.pyplot as plt
2import numpy as np
3import numpy.ma as ma
4import os, sys
5
6class camplotter( object ):
7 def __init__( self ):
8 chid, y,x,ye,xe,yh,xh,softid,hardid = np.loadtxt("map_dn.txt",unpack=True)
9 self.fig = plt.figure()
10 self.xe = xe
11 self.ye = ye
12 self.H = (6,0,30./180.*3.1415926)
13
14 coor2chid = {}
15 chid2coor = []
16 for i in range ( len(chid) ):
17 coor2chid[ (x[i],y[i]) ] = chid[i]
18 chid2coor.append( (x[i],y[i]) )
19
20# print coor2chid
21# print chid2coor
22
23
24
25#########################################################################
26#########################################################################
27
28if __name__ == '__main__':
29
30 inputfname = 'nofile.npz'
31
32 if (len(sys.argv) > 1):
33 inputfname = sys.argv[1]
34 else:
35 print 'Usage ', sys.argv[0], 'input-file-path'
36 exit (0)
37
38 cplt = camplotter()
39
40 # np.savez ( filename, amplitude=maxAmp, time=maxPos, integral=integ)
41 npz = np.load( inputfname )
42 print npz.files
43
44 amp = npz['amplitude']
45 int = npz['integral']
46 tim = npz['time']
47
48 files = []
49 fig = plt.figure(figsize=(24,16))
50# plt.title('left amplitude ... right integral')
51 ax1 = fig.add_subplot(231, aspect='equal')
52 ax2 = fig.add_subplot(232, aspect='equal')
53 ax3 = fig.add_subplot(233, aspect='equal')
54 ax4 = fig.add_subplot(234)
55 ax5 = fig.add_subplot(235)
56 ax6 = fig.add_subplot(236)
57
58 ax1.grid(True)
59 ax2.grid(True)
60 ax3.grid(True)
61 ax4.grid(True)
62 ax5.grid(True)
63 ax6.grid(True)
64
65 thr = 50
66 hithr = 80
67 lothr = 40
68 print '------------ hiTHR=', hithr, 'loTHR=', lothr ,'-------------------'
69 print '------------', len(amp[:,0]), '-------------------'
70
71# for i in range(len(data[:,0])):
72 os.system("mkdir -p pngs")
73 for i in range(50):
74
75 mamp = ma.masked_less(amp[i,:], thr)
76 mx = ma.masked_where(mamp.mask == True, cplt.xe)
77 my = ma.masked_where(mamp.mask == True, cplt.ye)
78
79 core = ma.masked_less(amp[i,:], hithr)
80 edgecand = ma.masked_less(amp[i,:], lothr)
81 #edgecand = ma.masked_where(core.mask == True, edgecand)
82
83 mxc = ma.masked_where(core.mask == True, cplt.xe).compressed()
84 myc = ma.masked_where(core.mask == True, cplt.ye).compressed()
85 mxe = ma.masked_where(edgecand.mask == True, cplt.xe).compressed()
86 mye = ma.masked_where(edgecand.mask == True, cplt.ye).compressed()
87
88
89 ax1.cla()
90 ax2.cla()
91 ax3.cla()
92 ax1.scatter(cplt.xe,cplt.ye,s=65,alpha=0.75,marker=cplt.H, c=amp[i,:], edgecolors='none', label='amp')
93 #ax1.scatter(mx.compressed() , my.compressed() ,s=65,alpha=0.75,marker=cplt.H, facecolors='none', linewidths=3, edgecolors='r')
94 if ( len(mxe) > 0 ):
95 ax1.scatter(mxe , mye ,s=65,alpha=0.75,marker=cplt.H, facecolors='none', linewidths=2, edgecolors='r')
96 if ( len(mxc) > 0 ):
97 ax1.scatter(mxc , myc ,s=65,alpha=0.75,marker=cplt.H, facecolors='none', linewidths=3, edgecolors='k')
98 ax1.axis([-22,22,-22,22])
99
100 ax2.scatter(cplt.xe,cplt.ye,s=70,alpha=0.75,marker=cplt.H, c=int[i,:], edgecolors='none', label='inte')
101 ax2.axis([-22,22,-22,22])
102 ax3.scatter(cplt.xe,cplt.ye,s=70,alpha=0.75,marker=cplt.H, c=tim[i,:], edgecolors='none', label='time')
103 ax3.axis([-22,22,-22,22])
104
105 ax4.cla()
106 ax4.hist(amp[i,:], 100, facecolor='r', alpha=0.75)
107 ax4.set_yscale("log", nonposy='clip')
108
109 ax5.cla()
110 ax5.hist(int[i,:], 100, facecolor='g', alpha=0.75)
111 ax5.set_yscale("log", nonposy='clip')
112
113 ax6.cla()
114 ax6.hist(tim[i,:], 100,facecolor='b', alpha=0.75)
115 ax6.set_yscale("log", nonposy='clip')
116
117
118
119 fname = 'pngs/_tmp%03d.png'%i
120 print 'Saving frame', fname
121 fig.savefig(fname)
122
123 files.append(fname)
124
125 # in order to make a movie using mencoder -- uncomment the following two lines
126 #
127 #print 'Making movie animation.mpg - this make take a while'
128 #os.system("mencoder 'mf://pngs/_tmp*.png' -mf type=png:fps=2 -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o animation.mpg")
129
130 # in order to make an animated gif using ImageMagick -- uncomment the following two lines
131 #
132 #print 'Making animated gif animation.gif - this make take a while'
133 #os.system("convert -delay 33 -loop 0 pngs/_tmp*.png animation.gif")
134
Note: See TracBrowser for help on using the repository browser.