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', |
Partager