1 |
import os,datetime,glob |
---|
2 |
import numpy as np |
---|
3 |
import matplotlib as mpl |
---|
4 |
mpl.use("Agg") |
---|
5 |
from pylab import figure, suptitle, subplot, plot, xticks, yticks, legend, xlabel, ylabel, title |
---|
6 |
import pycdf |
---|
7 |
|
---|
8 |
ncDir = '/seacoos/data/nccoos/level1/billymitchell/sodar1' |
---|
9 |
ncFileGlob = 'billymitchell_sfas_*.nc' |
---|
10 |
|
---|
11 |
pngDir = '/seacoos/data/nccoos/level1/billymitchell/sodar1/plots/meanspeed' |
---|
12 |
pngExt = 'png' |
---|
13 |
htmlExt = 'html' |
---|
14 |
|
---|
15 |
ncFilePattern = os.path.join(ncDir,ncFileGlob) |
---|
16 |
files = glob.glob(ncFilePattern) |
---|
17 |
previous = [files[-1]] + files[:-1] |
---|
18 |
next = files[1:] + [files[0]] |
---|
19 |
files = zip(previous,files,next) |
---|
20 |
|
---|
21 |
html1 = """<html> |
---|
22 |
<head> |
---|
23 |
<title> |
---|
24 |
Billy Mitchell Sodar :: """ |
---|
25 |
|
---|
26 |
html2 = """ :: Mean Speed |
---|
27 |
</title> |
---|
28 |
</head> |
---|
29 |
<body> |
---|
30 |
<form> |
---|
31 |
<a href=\"""" |
---|
32 |
|
---|
33 |
html3 = """\"><Previous</a> |
---|
34 |
<a href=\"""" |
---|
35 |
|
---|
36 |
html4 = """\">Next></a> |
---|
37 |
</form> |
---|
38 |
<br/> |
---|
39 |
<img src=\"""" |
---|
40 |
|
---|
41 |
html5 = """\"> |
---|
42 |
</body> |
---|
43 |
</html>""" |
---|
44 |
|
---|
45 |
first = True |
---|
46 |
for previous,ncFile,next in files: |
---|
47 |
print 'Processing',ncFile |
---|
48 |
ncFileName = os.path.splitext(os.path.basename(ncFile))[0] |
---|
49 |
year = ncFileName[19:23] |
---|
50 |
month = ncFileName[24:26] |
---|
51 |
month = datetime.datetime(int(year),int(month),1).strftime('%B') |
---|
52 |
if previous: |
---|
53 |
previous = os.path.splitext(os.path.basename(previous))[0] |
---|
54 |
previousYear = previous[19:23] |
---|
55 |
previousMonth = previous[24:26] |
---|
56 |
previousMonth = datetime.datetime(int(previousYear),int(previousMonth),1).strftime('%B') |
---|
57 |
previous = previous + os.extsep + htmlExt |
---|
58 |
if next: |
---|
59 |
next = os.path.splitext(os.path.basename(next))[0] |
---|
60 |
nextYear = next[19:23] |
---|
61 |
nextMonth = next[24:26] |
---|
62 |
nextMonth = datetime.datetime(int(nextYear),int(nextMonth),1).strftime('%B') |
---|
63 |
next = next + os.extsep + htmlExt |
---|
64 |
|
---|
65 |
nc = pycdf.CDF(ncFile) |
---|
66 |
|
---|
67 |
t = nc.var('time')[:] |
---|
68 |
z = nc.var('z')[:] |
---|
69 |
u = nc.var('u')[:] |
---|
70 |
v = nc.var('v')[:] |
---|
71 |
w = nc.var('w')[:] |
---|
72 |
|
---|
73 |
mu = np.ma.masked_invalid(u) |
---|
74 |
mv = np.ma.masked_invalid(v) |
---|
75 |
mw = np.ma.masked_invalid(w) |
---|
76 |
|
---|
77 |
umean = mu.mean(axis=0).data |
---|
78 |
vmean = mv.mean(axis=0).data |
---|
79 |
wmean = mw.mean(axis=0).data |
---|
80 |
|
---|
81 |
ucount = mu.count(axis=0) |
---|
82 |
vcount = mv.count(axis=0) |
---|
83 |
wcount = mw.count(axis=0) |
---|
84 |
|
---|
85 |
fig = figure() |
---|
86 |
suptitle('Billy Mitchell Sodar :: ' + month + " " + year) |
---|
87 |
|
---|
88 |
subplot(1,2,1) |
---|
89 |
plot(umean,z,label=r'$\bar{u}$') |
---|
90 |
plot(vmean,z,label=r'$\bar{v}$') |
---|
91 |
plot(wmean,z,label=r'$\bar{w}$') |
---|
92 |
legend(loc='best') |
---|
93 |
xlabel('Speed (cm/s)') |
---|
94 |
ylabel('Elevation (m)') |
---|
95 |
title('Average wind speeds') |
---|
96 |
|
---|
97 |
subplot(1,2,2) |
---|
98 |
plot((ucount * 100.0)/float(mu.shape[0]),z,label=r'$\%\ samples(u|v)$') |
---|
99 |
plot((wcount * 100.0)/float(mw.shape[0]),z,label=r'$\%\ samples(w)$') |
---|
100 |
xticks(range(0,101,10)) |
---|
101 |
legend(loc='best') |
---|
102 |
xlabel('% of samples per month') |
---|
103 |
title('Number of valid samples') |
---|
104 |
|
---|
105 |
outFile = os.path.join(pngDir,ncFileName + os.extsep + pngExt) |
---|
106 |
print 'Saving', outFile |
---|
107 |
fig.savefig(outFile) |
---|
108 |
|
---|
109 |
htmlFile = os.path.join(pngDir,ncFileName + os.extsep + htmlExt) |
---|
110 |
html = html1 + month + " " + year |
---|
111 |
html = html + html2 + previous + html3 + next + html4 |
---|
112 |
html = html + os.path.basename(outFile) + html5 |
---|
113 |
handle = open(htmlFile,'w') |
---|
114 |
handle.write(html) |
---|
115 |
handle.close() |
---|
116 |
|
---|
117 |
if first: |
---|
118 |
first = False |
---|
119 |
htmlFile = os.path.join(pngDir,"index" + os.extsep + htmlExt) |
---|
120 |
handle = open(htmlFile,'w') |
---|
121 |
handle.write(html) |
---|
122 |
handle.close() |
---|
123 |
|
---|
124 |
|
---|