Salut,

J'aimerais faire une video avec une sequence d'image quiver sous python. J'ai entendu parle de matplotlib.animation et j'ai ecris ce bout de code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
 
#!/usr/bin/python
# the Scientific Python netCDF 3 interface
from Scientific.IO.NetCDF import NetCDFFile as Dataset
import matplotlib
matplotlib.use("Agg") # to avoid some DISPLAY issues on compute nodes, we do not need display anyways
from pylab import*
import pylab
import numpy
import scipy.interpolate
import matplotlib.colors
import sys
import matplotlib.pyplot as plt
import matplotlib.animation as animation
 
# Time to start...
 
 
# What figures to plot:
lfig1 = True
lfig2 = True
lfig3 = True
 
 
 
params2 = {'backend': 'eps',
          'axes.labelsize': 10,
          'text.fontsize': 20,
          'xtick.labelsize': 26,
          'ytick.labelsize': 26,
          'text.fontsize': 20,
          'xtick.labelsize': 12,
          'ytick.labelsize': 12,
          'legend.pad': 0.5,          # empty space around the legend box
          'legend.fontsize': 16,
           'lines.markersize': 3,
          'font.size': 10,
          'figure.figsize': (9,6)}
 
rcParams.update(params2)
rcParams['text.usetex']=True
rcParams['ps.usedistiller']='xpdf'
 
 
# Getting netcdf files to read from command-line arguments
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
nb_arg = len(sys.argv) ; # number of "command-line" arguments
if nb_arg < 2 or nb_arg > 3:
    print 'Usage: '+sys.argv[0]+' <file_to_be_read.nc> (<land_sea_mask.nc>) \n'
    sys.exit(0)
 
cf_in  = sys.argv[1] ; # the file we read temperature from
 
# if 3rd argument present that must be the land-sea mask file:
cf_lsm = ''
if nb_arg == 3: cf_lsm = sys.argv[2]
 
 
 
 
# Opening the Netcdf file for reading relevant variables
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
vlin3 = np.zeros((163,141))
vlin4 = np.zeros((163,141))
vlin5 = np.zeros((163,141))
tmpvlin5 = np.zeros((163,141))
vlin6 = np.zeros((163,141))
 
 
 
 
id_in = Dataset(cf_in)
print 'File ', cf_in, 'is open...\n'
 
 
 
vlon1 = id_in.variables['vz'][:][:][:]; # extracting longitude 3D array
vlon2 = id_in.variables['vy'][:][:][:]; # extracting longitude 3D array
vlon3 = id_in.variables['G1'][:][:][:]; # extracting longitude 3D array
vlon4 = id_in.variables['G2'][:][:][:]; # extracting longitude 3D array
 
 
#vlon3 =id_in.variables['Fi_low2'][:][:];
tt0=495
 
 
 
 # Plot data
 
fig1 = figure()
 
#manage axis
extraticks=[-0.5, 0.5]
plt.xticks(list(plt.xticks()[0]) + extraticks)
axis([-0.5, 0.5, 0,1.0]) ; # X-Y axis bound: 
 
xlabel('$z/ \delta$',fontsize=15)
ylabel(' $y/ \delta$',fontsize=15)
 
u= np.linspace(-0.15, 0.15, num=141)/0.3 #horizontal
v=np.linspace(0, 0.3, num=163)/0.3
 
vlin3 = np.zeros((163,141))
vlin4 = np.zeros((163,141)) 
 
 
tt =tt0
dt = 1
 
 
 
for l in range(141):
 for l2 in range(163):  
   if l%2==0:
     if l2%2==0:
        vlin3[l2,l] = vlon1[l,l2,tt]
        vlin4[l2,l] = vlon2[l,l2,tt]       
 
Q = quiver(u, v, vlin3,  vlin4, scale=2.5)
 
nt =0;
 
def updatefig(nt):
    global Q
 
    for l in range(141):
      for l2 in range(163):  
       if l%2==0:
         if l2%2==0:
           vlin3[l2,l] = vlon1[l,l2,tt+nt]
           vlin4[l2,l] = vlon2[l,l2,tt+nt]      
 
 
    Q.set_UVC(vlin3,vlin4) 
 
 
 
ani = animation.FuncAnimation(fig1, updatefig, frames=10)
ani.save('movie.mp4')
 
 
print 'end',
lors de l'execution j'ai ce long message d'erreur:

./anim1.py fit.nc
File fit.nc is open...

sh: 1: dvipng: not found
Traceback (most recent call last):
File "./anim1.py", line 141, in <module>
ani.save('movie.mp4')
File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 121, in save
self._draw_next_frame(data, blit=False)
File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 197, in _draw_next_frame
self._post_draw(framedata, blit)
File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 222, in _post_draw
self._fig.canvas.draw_idle()
File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1743, in draw_idle
self.draw(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 421, in draw
self.figure.draw(self.renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 898, in draw
func(*args)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 1997, in draw
a.draw(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1045, in draw
tick.draw(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 239, in draw
self.label1.draw(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/text.py", line 571, in draw
self._fontproperties, angle)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py", line 215, in draw_tex
Z = texmanager.get_grey(s, size, self.dpi)
File "/usr/lib/pymodules/python2.7/matplotlib/texmanager.py", line 513, in get_grey
pngfile = self.make_png(tex, fontsize, dpi)
File "/usr/lib/pymodules/python2.7/matplotlib/texmanager.py", line 459, in make_png
\n\n'% dvifile + report)
RuntimeError: dvipng was not able to process the following file:
/home/dekou/.matplotlib/tex.cache/f533a84a7a09fdac5295b4336e5d0ef2.dvi
Here is the full report generated by dvipng:


Avez vous une idee de la cause de cette erreur?