1 |
|
---|
2 |
|
---|
3 |
"""swan_model_plot""" |
---|
4 |
|
---|
5 |
import os, sys |
---|
6 |
import datetime, time, dateutil.tz |
---|
7 |
import pycdf |
---|
8 |
import numpy |
---|
9 |
|
---|
10 |
sys.path.append('/opt/env/haines/dataproc/raw2proc') |
---|
11 |
del(sys) |
---|
12 |
|
---|
13 |
os.environ["MPLCONFIGDIR"]="/home/haines/.matplotlib/" |
---|
14 |
|
---|
15 |
from pylab import figure, twinx, savefig, setp, getp, cm, colorbar |
---|
16 |
import procutil |
---|
17 |
import ncutil |
---|
18 |
|
---|
19 |
print 'swan_model_plot ...' |
---|
20 |
|
---|
21 |
|
---|
22 |
ncFile1='/seacoos/data/nccoos/test_data/20101018_1800_NSNH_CG1.nc' |
---|
23 |
ncFile2='/some/other/data/file.nc' |
---|
24 |
|
---|
25 |
|
---|
26 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
27 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
28 |
|
---|
29 |
print ' ... loading data for graph from ...' |
---|
30 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
31 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
32 |
|
---|
33 |
if have_ncFile1 and have_ncFile2: |
---|
34 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
35 |
elif not have_ncFile1 and have_ncFile2: |
---|
36 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
37 |
elif have_ncFile1 and not have_ncFile2: |
---|
38 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
39 |
else: |
---|
40 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
41 |
exit() |
---|
42 |
|
---|
43 |
ncvars = nc.variables() |
---|
44 |
print ncvars |
---|
45 |
print ncvars['wndMag'] |
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
fig = figure(figsize=(8, 10)) |
---|
50 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) |
---|
51 |
|
---|
52 |
ax = fig.add_subplot(2,1,1) |
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 |
x = nc.var('x')[:] |
---|
57 |
y = nc.var('y')[:] |
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 |
wndDir = nc.var('wndDir')[:] |
---|
62 |
wndMag = nc.var('wndMag')[:] |
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 |
wdir = wndDir[0,0,:,:] |
---|
69 |
wdir = wdir.T |
---|
70 |
|
---|
71 |
wmag = wndMag[0,0,:,:] |
---|
72 |
wmag = wmag.T |
---|
73 |
|
---|
74 |
u = wmag*numpy.sin(wdir*numpy.pi/180) |
---|
75 |
v = wmag*numpy.cos(wdir*numpy.pi/180) |
---|
76 |
|
---|
77 |
|
---|
78 |
mu = numpy.ma.masked_where(u==0, u) |
---|
79 |
mv = numpy.ma.masked_where(v==0, v) |
---|
80 |
|
---|
81 |
ax.barbs(x, y, mu, mv) |
---|
82 |
|
---|
83 |
ax.set_ylabel('Latitude') |
---|
84 |
ax.set_xlabel('Longitude') |
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 |
Hs = nc.var('htsgw')[:] |
---|
89 |
Dp = nc.var('dirpw')[:] |
---|
90 |
|
---|
91 |
Hs = Hs[0,0,:,:] |
---|
92 |
Dp = Dp[0,0,:,:] |
---|
93 |
|
---|
94 |
X,Y = numpy.meshgrid(x,y) |
---|
95 |
mHs = numpy.ma.masked_where(Hs==10, Hs) |
---|
96 |
|
---|
97 |
ax = fig.add_subplot(2,1,2) |
---|
98 |
ax.pcolor(X, Y, mHs) |
---|
99 |
|
---|
100 |
|
---|
101 |
savefig('/home/haines/rayleigh/test_swan_model_plot.png') |
---|
102 |
|
---|