1 |
#!/usr/bin/env /opt/env/haines/dataproc/bin/python |
---|
2 |
# Last modified: Time-stamp: <2010-08-13 15:56:06 haines> |
---|
3 |
|
---|
4 |
""" |
---|
5 |
bogue_adcpwaves_plot |
---|
6 |
|
---|
7 |
allwaves() |
---|
8 |
swellwaves() |
---|
9 |
windwaves() |
---|
10 |
""" |
---|
11 |
|
---|
12 |
################################################# |
---|
13 |
# [1a] search and replace XXXX with platform id |
---|
14 |
# [1b] search and replace YYYY with sensor id |
---|
15 |
# [1c] search and replace ZZZZ plot titles |
---|
16 |
################################################# |
---|
17 |
|
---|
18 |
# plot each month |
---|
19 |
|
---|
20 |
import os |
---|
21 |
# import sys, glob, re |
---|
22 |
import datetime, time, dateutil, dateutil.tz |
---|
23 |
import pycdf |
---|
24 |
import numpy |
---|
25 |
|
---|
26 |
# sys.path.append('/opt/env/haines/dataproc/raw2proc') |
---|
27 |
# del(sys) |
---|
28 |
|
---|
29 |
os.environ["MPLCONFIGDIR"]="/home/haines/.matplotlib/" |
---|
30 |
|
---|
31 |
from pylab import figure, twinx, savefig, setp, getp, cm, colorbar |
---|
32 |
from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, DateFormatter, date2num, num2date |
---|
33 |
import procutil |
---|
34 |
|
---|
35 |
def swellwaves(pi, si, yyyy_mm, plot_type='latest'): |
---|
36 |
""" |
---|
37 |
""" |
---|
38 |
|
---|
39 |
print 'bogue_swellwaves_plot ...' |
---|
40 |
|
---|
41 |
# |
---|
42 |
|
---|
43 |
prev_month, this_month, next_month = procutil.find_months(yyyy_mm) |
---|
44 |
yyyy_mm_str = this_month.strftime('%Y_%m') |
---|
45 |
|
---|
46 |
################################ |
---|
47 |
# [2a] load primary data file |
---|
48 |
################################ |
---|
49 |
|
---|
50 |
ncFile1='/seacoos/data/nccoos/level1/bogue/adcpwaves/bogue_adcpwaves_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
51 |
ncFile2='/seacoos/data/nccoos/level1/bogue/adcpwaves/bogue_adcpwaves_'+this_month.strftime('%Y_%m')+'.nc' |
---|
52 |
|
---|
53 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
54 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
55 |
|
---|
56 |
print ' ... loading data for graph from ...' |
---|
57 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
58 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
59 |
|
---|
60 |
# open netcdf data |
---|
61 |
if have_ncFile1 and have_ncFile2: |
---|
62 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
63 |
elif not have_ncFile1 and have_ncFile2: |
---|
64 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
65 |
elif have_ncFile1 and not have_ncFile2: |
---|
66 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
67 |
else: |
---|
68 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
69 |
return |
---|
70 |
|
---|
71 |
# ncvars = nc.variables() |
---|
72 |
# print ncvars |
---|
73 |
es = nc.var('time')[:] |
---|
74 |
units = nc.var('time').units |
---|
75 |
dt = [procutil.es2dt(e) for e in es] |
---|
76 |
# set timezone info to UTC (since data from level1 should be in UTC!!) |
---|
77 |
dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt] |
---|
78 |
# return new datetime based on computer local |
---|
79 |
dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt] |
---|
80 |
dn = date2num(dt) |
---|
81 |
|
---|
82 |
################################ |
---|
83 |
# [2b] specify variables |
---|
84 |
################################ |
---|
85 |
Hss = nc.var('Hs_swell')[:] |
---|
86 |
Tps = nc.var('Tp_swell')[:] |
---|
87 |
Tms = nc.var('Tm_swell')[:] |
---|
88 |
# Hmax = nc.var('Hmax')[:] |
---|
89 |
Dps = nc.var('Dp_swell')[:] |
---|
90 |
Dms = nc.var('Dm_swell')[:] |
---|
91 |
|
---|
92 |
nc.close() |
---|
93 |
|
---|
94 |
|
---|
95 |
################################ |
---|
96 |
# [3a] load ancillary files if needed |
---|
97 |
################################ |
---|
98 |
|
---|
99 |
ncFile1='/seacoos/data/nccoos/level1/bogue/adcp/bogue_adcp_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
100 |
ncFile2='/seacoos/data/nccoos/level1/bogue/adcp/bogue_adcp_'+this_month.strftime('%Y_%m')+'.nc' |
---|
101 |
|
---|
102 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
103 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
104 |
|
---|
105 |
print ' ... loading data for graph from ...' |
---|
106 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
107 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
108 |
|
---|
109 |
# open netcdf data |
---|
110 |
if have_ncFile1 and have_ncFile2: |
---|
111 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
112 |
elif not have_ncFile1 and have_ncFile2: |
---|
113 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
114 |
elif have_ncFile1 and not have_ncFile2: |
---|
115 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
116 |
else: |
---|
117 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
118 |
return |
---|
119 |
|
---|
120 |
# ncvars = nc.variables() |
---|
121 |
# print ncvars |
---|
122 |
es2 = nc.var('time')[:] |
---|
123 |
units = nc.var('time').units |
---|
124 |
dt2 = [procutil.es2dt(e) for e in es2] |
---|
125 |
# set timezone info to UTC (since data from level1 should be in UTC!!) |
---|
126 |
dt2 = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt2] |
---|
127 |
dn2 = date2num(dt2) |
---|
128 |
|
---|
129 |
################################ |
---|
130 |
# [3b] specify variables |
---|
131 |
################################ |
---|
132 |
wd2 = nc.var('wd')[:] |
---|
133 |
|
---|
134 |
nc.close() |
---|
135 |
|
---|
136 |
# last dt in data for labels |
---|
137 |
dtu = dt[-1] |
---|
138 |
dtl = dt_local[-1] |
---|
139 |
|
---|
140 |
diff = abs(dtu - dtl) |
---|
141 |
if diff.days>0: |
---|
142 |
last_dt_str = dtu.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dtl.strftime("%H:%M %Z, %b %d") + ')' |
---|
143 |
else: |
---|
144 |
last_dt_str = dtu.strftime("%H:%M %Z") + ' (' + dtl.strftime("%H:%M %Z") + ')' \ |
---|
145 |
+ dtl.strftime(" on %b %d, %Y") |
---|
146 |
|
---|
147 |
####################################### |
---|
148 |
# Plot setup |
---|
149 |
####################################### |
---|
150 |
|
---|
151 |
fig = figure(figsize=(10, 8)) |
---|
152 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) |
---|
153 |
|
---|
154 |
ax = fig.add_subplot(4,1,1) |
---|
155 |
axs = [ax] |
---|
156 |
|
---|
157 |
# ax.plot returns a list of lines, so unpack tuple |
---|
158 |
(x, y) = procutil.addnan(dt2, wd2, maxdelta=2./24) |
---|
159 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
160 |
l1.set_label('Water Depth (m)') |
---|
161 |
|
---|
162 |
ax.set_ylabel('Depth (m)') |
---|
163 |
# ax.set_ylim(2.,10.) |
---|
164 |
# ax.set_xlim(dt[0], dt[-1]) # first to last regardless of what |
---|
165 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
166 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
167 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
168 |
ax.set_xticklabels([]) |
---|
169 |
|
---|
170 |
# this only moves the label not the tick labels |
---|
171 |
ax.xaxis.set_label_position('top') |
---|
172 |
ax.set_xlabel('BOGUE Swell Waves -- ' + yyyy_mm_str) |
---|
173 |
|
---|
174 |
# right-hand side scale |
---|
175 |
ax2 = twinx(ax) |
---|
176 |
ax2.yaxis.tick_right() |
---|
177 |
# convert (lhs) meters to (rhs) feet |
---|
178 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
179 |
ax2.set_ylim(feet) |
---|
180 |
ax2.set_ylabel('Depth (feet)') |
---|
181 |
|
---|
182 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
183 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
184 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
185 |
ax2.set_xticklabels([]) |
---|
186 |
|
---|
187 |
# legend |
---|
188 |
ls1 = l1.get_label() |
---|
189 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
190 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
191 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
192 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
193 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
194 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
195 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
196 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
197 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
198 |
|
---|
199 |
####################################### |
---|
200 |
# |
---|
201 |
ax = fig.add_subplot(4,1,2) |
---|
202 |
axs.append(ax) |
---|
203 |
|
---|
204 |
# ax.plot returns a list of lines, so unpack tuple |
---|
205 |
(x, y) = procutil.addnan(dt, Hss, maxdelta=2./24) |
---|
206 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
207 |
l1.set_label('Significant Swell Wave Height (Hss)') |
---|
208 |
|
---|
209 |
# (x, y) = procutil.addnan(dt, Hmax, maxdelta=2./24) |
---|
210 |
# l2, = ax.plot_date(x, y, fmt='g-') |
---|
211 |
# l2.set_label('Max Wave Height (Hmax)') |
---|
212 |
|
---|
213 |
ax.set_ylabel('WAVE\nHEIGHT (m)') |
---|
214 |
# ax.set_ylim(2.,10.) |
---|
215 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
216 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
217 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
218 |
ax.set_xticklabels([]) |
---|
219 |
|
---|
220 |
# right-hand side scale |
---|
221 |
ax2 = twinx(ax) |
---|
222 |
ax2.yaxis.tick_right() |
---|
223 |
# convert (lhs) meters to (rhs) feet |
---|
224 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
225 |
ax2.set_ylim(feet) |
---|
226 |
ax2.set_ylabel('(feet)') |
---|
227 |
|
---|
228 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
229 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
230 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
231 |
ax2.set_xticklabels([]) |
---|
232 |
|
---|
233 |
# legend |
---|
234 |
ls1 = l1.get_label() |
---|
235 |
# ls2 = l2.get_label() |
---|
236 |
# leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
237 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
238 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
239 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
240 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
241 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
242 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
243 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
244 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
245 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
246 |
|
---|
247 |
####################################### |
---|
248 |
# |
---|
249 |
ax = fig.add_subplot(4,1,3) |
---|
250 |
axs.append(ax) |
---|
251 |
|
---|
252 |
# ax.plot returns a list of lines, so unpack tuple |
---|
253 |
(x, y) = procutil.addnan(dt, Tps, maxdelta=2./24) |
---|
254 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
255 |
l1.set_label('Peak Swell Period (Tp)') |
---|
256 |
|
---|
257 |
(x, y) = procutil.addnan(dt, Tms, maxdelta=2./24) |
---|
258 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
259 |
l2.set_label('Mean Swell Period (Tm)') |
---|
260 |
|
---|
261 |
ax.set_ylabel('WAVE\nPERIOD (s)') |
---|
262 |
# ax.set_ylim(2.,10.) |
---|
263 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
264 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
265 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
266 |
ax.set_xticklabels([]) |
---|
267 |
|
---|
268 |
# legend |
---|
269 |
ls1 = l1.get_label() |
---|
270 |
ls2 = l2.get_label() |
---|
271 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
272 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
273 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
274 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
275 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
276 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
277 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
278 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
279 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
280 |
|
---|
281 |
####################################### |
---|
282 |
# |
---|
283 |
ax = fig.add_subplot(4,1,4) |
---|
284 |
axs.append(ax) |
---|
285 |
|
---|
286 |
# ax.plot returns a list of lines, so unpack tuple |
---|
287 |
(x, y) = procutil.addnan(dt, Dps, maxdelta=2./24) |
---|
288 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
289 |
l1.set_label('Peak Swell Direction (Dp)') |
---|
290 |
|
---|
291 |
(x, y) = procutil.addnan(dt, Dms, maxdelta=2./24) |
---|
292 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
293 |
l2.set_label('Mean Swell Direction (Dp)') |
---|
294 |
|
---|
295 |
ax.set_ylabel('WAVE\nDIR (deg N)') |
---|
296 |
ax.set_ylim(0.,360.) |
---|
297 |
# first to last regardless of what |
---|
298 |
# ax.set_xlim(dt[0], dt[-1]) |
---|
299 |
# last minus 30 days, |
---|
300 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
301 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
302 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
303 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
304 |
|
---|
305 |
ax.set_xlabel('BOGUE Swell Waves -- ' + yyyy_mm_str) |
---|
306 |
|
---|
307 |
# legend |
---|
308 |
ls1 = l1.get_label() |
---|
309 |
ls2 = l2.get_label() |
---|
310 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
311 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
312 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
313 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
314 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
315 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
316 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
317 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
318 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
319 |
|
---|
320 |
# save figure for this month |
---|
321 |
ofn = '/home/haines/rayleigh/img/bogue/bogue_swellwaves_'+yyyy_mm_str+'.png' |
---|
322 |
print '... ... write: %s' % (ofn,) |
---|
323 |
savefig(ofn) |
---|
324 |
|
---|
325 |
|
---|
326 |
####################################### |
---|
327 |
# Last 30 days |
---|
328 |
####################################### |
---|
329 |
if plot_type=='latest': |
---|
330 |
print ' ... Last 30 days' |
---|
331 |
for idx, ax in enumerate(axs): |
---|
332 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
333 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
334 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
335 |
ax.set_xticklabels([]) |
---|
336 |
if idx==0: |
---|
337 |
ax.set_xlabel('BOGUE Swell Waves -- Last 30 days from ' + last_dt_str) |
---|
338 |
elif idx==len(axs)-1: |
---|
339 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
340 |
ax.set_xlabel('BOGUE Swell Waves -- Last 30 days from ' + last_dt_str) |
---|
341 |
|
---|
342 |
savefig('/home/haines/rayleigh/img/bogue_swellwaves_last30days.png') |
---|
343 |
|
---|
344 |
|
---|
345 |
####################################### |
---|
346 |
# Last 7 days |
---|
347 |
####################################### |
---|
348 |
if plot_type=='latest': |
---|
349 |
print ' ... Last 7 days' |
---|
350 |
for idx, ax in enumerate(axs): |
---|
351 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
352 |
ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) ) |
---|
353 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
354 |
ax.set_xticklabels([]) |
---|
355 |
if idx==0: |
---|
356 |
ax.set_xlabel('BOGUE Swell Waves -- Last 7 days from ' + last_dt_str) |
---|
357 |
elif idx==len(axs)-1: |
---|
358 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
359 |
ax.set_xlabel('BOGUE Swell Waves -- Last 7 days from ' + last_dt_str) |
---|
360 |
|
---|
361 |
savefig('/home/haines/rayleigh/img/bogue_swellwaves_last07days.png') |
---|
362 |
|
---|
363 |
|
---|
364 |
####################################### |
---|
365 |
# Last 1 day (24hrs) |
---|
366 |
####################################### |
---|
367 |
if plot_type=='latest': |
---|
368 |
print ' ... Last 1 days' |
---|
369 |
|
---|
370 |
for idx, ax in enumerate(axs): |
---|
371 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
372 |
ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) ) |
---|
373 |
ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) ) |
---|
374 |
ax.set_xticklabels([]) |
---|
375 |
if idx==0: |
---|
376 |
ax.set_xlabel('BOGUE Swell Waves -- Last 24 hours from ' + last_dt_str) |
---|
377 |
elif idx==len(axs)-1: |
---|
378 |
ax.xaxis.set_major_formatter( DateFormatter('%H') ) |
---|
379 |
ax.set_xlabel('BOGUE Swell Waves -- Last 24 hours from ' + last_dt_str) |
---|
380 |
|
---|
381 |
savefig('/home/haines/rayleigh/img/bogue_swellwaves_last01days.png') |
---|
382 |
|
---|
383 |
|
---|
384 |
def windwaves(pi, si, yyyy_mm, plot_type='latest'): |
---|
385 |
""" |
---|
386 |
""" |
---|
387 |
|
---|
388 |
print 'bogue_windwaves_plot ...' |
---|
389 |
|
---|
390 |
# |
---|
391 |
|
---|
392 |
prev_month, this_month, next_month = procutil.find_months(yyyy_mm) |
---|
393 |
yyyy_mm_str = this_month.strftime('%Y_%m') |
---|
394 |
|
---|
395 |
################################ |
---|
396 |
# [2a] load primary data file |
---|
397 |
################################ |
---|
398 |
|
---|
399 |
ncFile1='/seacoos/data/nccoos/level1/bogue/adcpwaves/bogue_adcpwaves_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
400 |
ncFile2='/seacoos/data/nccoos/level1/bogue/adcpwaves/bogue_adcpwaves_'+this_month.strftime('%Y_%m')+'.nc' |
---|
401 |
|
---|
402 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
403 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
404 |
|
---|
405 |
print ' ... loading data for graph from ...' |
---|
406 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
407 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
408 |
|
---|
409 |
# open netcdf data |
---|
410 |
if have_ncFile1 and have_ncFile2: |
---|
411 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
412 |
elif not have_ncFile1 and have_ncFile2: |
---|
413 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
414 |
elif have_ncFile1 and not have_ncFile2: |
---|
415 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
416 |
else: |
---|
417 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
418 |
return |
---|
419 |
|
---|
420 |
# ncvars = nc.variables() |
---|
421 |
# print ncvars |
---|
422 |
es = nc.var('time')[:] |
---|
423 |
units = nc.var('time').units |
---|
424 |
dt = [procutil.es2dt(e) for e in es] |
---|
425 |
# set timezone info to UTC (since data from level1 should be in UTC!!) |
---|
426 |
dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt] |
---|
427 |
# return new datetime based on computer local |
---|
428 |
dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt] |
---|
429 |
dn = date2num(dt) |
---|
430 |
|
---|
431 |
################################ |
---|
432 |
# [2b] specify variables |
---|
433 |
################################ |
---|
434 |
Hsw = nc.var('Hs_wind')[:] |
---|
435 |
Tpw = nc.var('Tp_wind')[:] |
---|
436 |
Tmw = nc.var('Tm_wind')[:] |
---|
437 |
# Hmax = nc.var('Hmax')[:] |
---|
438 |
Dpw = nc.var('Dp_wind')[:] |
---|
439 |
Dmw = nc.var('Dm_wind')[:] |
---|
440 |
|
---|
441 |
nc.close() |
---|
442 |
|
---|
443 |
################################ |
---|
444 |
# [3a] load ancillary files if needed |
---|
445 |
################################ |
---|
446 |
|
---|
447 |
ncFile1='/seacoos/data/nccoos/level1/bogue/adcp/bogue_adcp_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
448 |
ncFile2='/seacoos/data/nccoos/level1/bogue/adcp/bogue_adcp_'+this_month.strftime('%Y_%m')+'.nc' |
---|
449 |
|
---|
450 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
451 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
452 |
|
---|
453 |
print ' ... loading data for graph from ...' |
---|
454 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
455 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
456 |
|
---|
457 |
# open netcdf data |
---|
458 |
if have_ncFile1 and have_ncFile2: |
---|
459 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
460 |
elif not have_ncFile1 and have_ncFile2: |
---|
461 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
462 |
elif have_ncFile1 and not have_ncFile2: |
---|
463 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
464 |
else: |
---|
465 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
466 |
return |
---|
467 |
|
---|
468 |
# ncvars = nc.variables() |
---|
469 |
# print ncvars |
---|
470 |
es2 = nc.var('time')[:] |
---|
471 |
units = nc.var('time').units |
---|
472 |
dt2 = [procutil.es2dt(e) for e in es2] |
---|
473 |
# set timezone info to UTC (since data from level1 should be in UTC!!) |
---|
474 |
dt2 = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt2] |
---|
475 |
dn2 = date2num(dt2) |
---|
476 |
|
---|
477 |
################################ |
---|
478 |
# [3b] specify variables |
---|
479 |
################################ |
---|
480 |
wd2 = nc.var('wd')[:] |
---|
481 |
|
---|
482 |
nc.close() |
---|
483 |
|
---|
484 |
# last dt in data for labels |
---|
485 |
dtu = dt[-1] |
---|
486 |
dtl = dt_local[-1] |
---|
487 |
|
---|
488 |
diff = abs(dtu - dtl) |
---|
489 |
if diff.days>0: |
---|
490 |
last_dt_str = dtu.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dtl.strftime("%H:%M %Z, %b %d") + ')' |
---|
491 |
else: |
---|
492 |
last_dt_str = dtu.strftime("%H:%M %Z") + ' (' + dtl.strftime("%H:%M %Z") + ')' \ |
---|
493 |
+ dtl.strftime(" on %b %d, %Y") |
---|
494 |
|
---|
495 |
####################################### |
---|
496 |
# Plot setup |
---|
497 |
####################################### |
---|
498 |
|
---|
499 |
fig = figure(figsize=(10, 8)) |
---|
500 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) |
---|
501 |
|
---|
502 |
ax = fig.add_subplot(4,1,1) |
---|
503 |
axs = [ax] |
---|
504 |
|
---|
505 |
# ax.plot returns a list of lines, so unpack tuple |
---|
506 |
(x, y) = procutil.addnan(dt2, wd2, maxdelta=2./24) |
---|
507 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
508 |
l1.set_label('Water Depth (m)') |
---|
509 |
|
---|
510 |
ax.set_ylabel('Depth (m)') |
---|
511 |
# ax.set_ylim(2.,10.) |
---|
512 |
# ax.set_xlim(dt[0], dt[-1]) # first to last regardless of what |
---|
513 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
514 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
515 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
516 |
ax.set_xticklabels([]) |
---|
517 |
|
---|
518 |
# this only moves the label not the tick labels |
---|
519 |
ax.xaxis.set_label_position('top') |
---|
520 |
ax.set_xlabel('BOGUE Wind Waves -- ' + yyyy_mm_str) |
---|
521 |
|
---|
522 |
# right-hand side scale |
---|
523 |
ax2 = twinx(ax) |
---|
524 |
ax2.yaxis.tick_right() |
---|
525 |
# convert (lhs) meters to (rhs) feet |
---|
526 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
527 |
ax2.set_ylim(feet) |
---|
528 |
ax2.set_ylabel('Depth (feet)') |
---|
529 |
|
---|
530 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
531 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
532 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
533 |
ax2.set_xticklabels([]) |
---|
534 |
|
---|
535 |
# legend |
---|
536 |
ls1 = l1.get_label() |
---|
537 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
538 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
539 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
540 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
541 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
542 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
543 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
544 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
545 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
546 |
|
---|
547 |
####################################### |
---|
548 |
# |
---|
549 |
ax = fig.add_subplot(4,1,2) |
---|
550 |
axs.append(ax) |
---|
551 |
|
---|
552 |
# ax.plot returns a list of lines, so unpack tuple |
---|
553 |
(x, y) = procutil.addnan(dt, Hsw, maxdelta=2./24) |
---|
554 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
555 |
l1.set_label('Significant Wind Wave Height (Hss)') |
---|
556 |
|
---|
557 |
# (x, y) = procutil.addnan(dt, Hmax, maxdelta=2./24) |
---|
558 |
# l2, = ax.plot_date(x, y, fmt='g-') |
---|
559 |
# l2.set_label('Max Wave Height (Hmax)') |
---|
560 |
|
---|
561 |
ax.set_ylabel('WAVE\nHEIGHT (m)') |
---|
562 |
# ax.set_ylim(2.,10.) |
---|
563 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
564 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
565 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
566 |
ax.set_xticklabels([]) |
---|
567 |
|
---|
568 |
# right-hand side scale |
---|
569 |
ax2 = twinx(ax) |
---|
570 |
ax2.yaxis.tick_right() |
---|
571 |
# convert (lhs) meters to (rhs) feet |
---|
572 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
573 |
ax2.set_ylim(feet) |
---|
574 |
ax2.set_ylabel('(feet)') |
---|
575 |
|
---|
576 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
577 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
578 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
579 |
ax2.set_xticklabels([]) |
---|
580 |
|
---|
581 |
# legend |
---|
582 |
ls1 = l1.get_label() |
---|
583 |
# ls2 = l2.get_label() |
---|
584 |
# leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
585 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
586 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
587 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
588 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
589 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
590 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
591 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
592 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
593 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
594 |
|
---|
595 |
####################################### |
---|
596 |
# |
---|
597 |
ax = fig.add_subplot(4,1,3) |
---|
598 |
axs.append(ax) |
---|
599 |
|
---|
600 |
# ax.plot returns a list of lines, so unpack tuple |
---|
601 |
(x, y) = procutil.addnan(dt, Tpw, maxdelta=2./24) |
---|
602 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
603 |
l1.set_label('Peak Wind Period (Tp)') |
---|
604 |
|
---|
605 |
(x, y) = procutil.addnan(dt, Tmw, maxdelta=2./24) |
---|
606 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
607 |
l2.set_label('Mean Wind Period (Tm)') |
---|
608 |
|
---|
609 |
ax.set_ylabel('WAVE\nPERIOD (s)') |
---|
610 |
# ax.set_ylim(2.,10.) |
---|
611 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
612 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
613 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
614 |
ax.set_xticklabels([]) |
---|
615 |
|
---|
616 |
# legend |
---|
617 |
ls1 = l1.get_label() |
---|
618 |
ls2 = l2.get_label() |
---|
619 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
620 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
621 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
622 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
623 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
624 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
625 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
626 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
627 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
628 |
|
---|
629 |
####################################### |
---|
630 |
# |
---|
631 |
ax = fig.add_subplot(4,1,4) |
---|
632 |
axs.append(ax) |
---|
633 |
|
---|
634 |
# ax.plot returns a list of lines, so unpack tuple |
---|
635 |
(x, y) = procutil.addnan(dt, Dpw, maxdelta=2./24) |
---|
636 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
637 |
l1.set_label('Peak Wind Direction (Dp)') |
---|
638 |
|
---|
639 |
(x, y) = procutil.addnan(dt, Dmw, maxdelta=2./24) |
---|
640 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
641 |
l2.set_label('Mean Wind Direction (Dp)') |
---|
642 |
|
---|
643 |
ax.set_ylabel('WAVE\nDIR (deg N)') |
---|
644 |
ax.set_ylim(0.,360.) |
---|
645 |
# first to last regardless of what |
---|
646 |
# ax.set_xlim(dt[0], dt[-1]) |
---|
647 |
# last minus 30 days, |
---|
648 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
649 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
650 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
651 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
652 |
|
---|
653 |
ax.set_xlabel('BOGUE Wind Waves -- ' + yyyy_mm_str) |
---|
654 |
|
---|
655 |
# legend |
---|
656 |
ls1 = l1.get_label() |
---|
657 |
ls2 = l2.get_label() |
---|
658 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
659 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
660 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
661 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
662 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
663 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
664 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
665 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
666 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
667 |
|
---|
668 |
# save figure for this month |
---|
669 |
ofn = '/home/haines/rayleigh/img/bogue/bogue_windwaves_'+yyyy_mm_str+'.png' |
---|
670 |
print '... ... write: %s' % (ofn,) |
---|
671 |
savefig(ofn) |
---|
672 |
|
---|
673 |
|
---|
674 |
####################################### |
---|
675 |
# Last 30 days |
---|
676 |
####################################### |
---|
677 |
if plot_type=='latest': |
---|
678 |
print ' ... Last 30 days' |
---|
679 |
for idx, ax in enumerate(axs): |
---|
680 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
681 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
682 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
683 |
ax.set_xticklabels([]) |
---|
684 |
if idx==0: |
---|
685 |
ax.set_xlabel('BOGUE Wind Waves -- Last 30 days from ' + last_dt_str) |
---|
686 |
elif idx==len(axs)-1: |
---|
687 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
688 |
ax.set_xlabel('BOGUE Wind Waves -- Last 30 days from ' + last_dt_str) |
---|
689 |
|
---|
690 |
savefig('/home/haines/rayleigh/img/bogue_windwaves_last30days.png') |
---|
691 |
|
---|
692 |
|
---|
693 |
####################################### |
---|
694 |
# Last 7 days |
---|
695 |
####################################### |
---|
696 |
if plot_type=='latest': |
---|
697 |
print ' ... Last 7 days' |
---|
698 |
for idx, ax in enumerate(axs): |
---|
699 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
700 |
ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) ) |
---|
701 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
702 |
ax.set_xticklabels([]) |
---|
703 |
if idx==0: |
---|
704 |
ax.set_xlabel('BOGUE Wind Waves -- Last 7 days from ' + last_dt_str) |
---|
705 |
elif idx==len(axs)-1: |
---|
706 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
707 |
ax.set_xlabel('BOGUE Wind Waves -- Last 7 days from ' + last_dt_str) |
---|
708 |
|
---|
709 |
savefig('/home/haines/rayleigh/img/bogue_windwaves_last07days.png') |
---|
710 |
|
---|
711 |
|
---|
712 |
####################################### |
---|
713 |
# Last 1 day (24hrs) |
---|
714 |
####################################### |
---|
715 |
if plot_type=='latest': |
---|
716 |
print ' ... Last 1 days' |
---|
717 |
|
---|
718 |
for idx, ax in enumerate(axs): |
---|
719 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
720 |
ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) ) |
---|
721 |
ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) ) |
---|
722 |
ax.set_xticklabels([]) |
---|
723 |
if idx==0: |
---|
724 |
ax.set_xlabel('BOGUE Wind Waves -- Last 24 hours from ' + last_dt_str) |
---|
725 |
elif idx==len(axs)-1: |
---|
726 |
ax.xaxis.set_major_formatter( DateFormatter('%H') ) |
---|
727 |
ax.set_xlabel('BOGUE Wind Waves -- Last 24 hours from ' + last_dt_str) |
---|
728 |
|
---|
729 |
savefig('/home/haines/rayleigh/img/bogue_windwaves_last01days.png') |
---|
730 |
|
---|
731 |
|
---|
732 |
|
---|
733 |
|
---|
734 |
def allwaves(pi, si, yyyy_mm, plot_type='latest'): |
---|
735 |
print 'bogue_allwaves_plot ...' |
---|
736 |
|
---|
737 |
prev_month, this_month, next_month = procutil.find_months(yyyy_mm) |
---|
738 |
yyyy_mm_str = this_month.strftime('%Y_%m') |
---|
739 |
|
---|
740 |
################################ |
---|
741 |
# [2a] load primary data file |
---|
742 |
################################ |
---|
743 |
|
---|
744 |
ncFile1='/seacoos/data/nccoos/level1/bogue/adcpwaves/bogue_adcpwaves_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
745 |
ncFile2='/seacoos/data/nccoos/level1/bogue/adcpwaves/bogue_adcpwaves_'+this_month.strftime('%Y_%m')+'.nc' |
---|
746 |
|
---|
747 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
748 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
749 |
|
---|
750 |
print ' ... loading data for graph from ...' |
---|
751 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
752 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
753 |
|
---|
754 |
# open netcdf data |
---|
755 |
if have_ncFile1 and have_ncFile2: |
---|
756 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
757 |
elif not have_ncFile1 and have_ncFile2: |
---|
758 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
759 |
elif have_ncFile1 and not have_ncFile2: |
---|
760 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
761 |
else: |
---|
762 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
763 |
return |
---|
764 |
|
---|
765 |
# ncvars = nc.variables() |
---|
766 |
# print ncvars |
---|
767 |
es = nc.var('time')[:] |
---|
768 |
units = nc.var('time').units |
---|
769 |
dt = [procutil.es2dt(e) for e in es] |
---|
770 |
# set timezone info to UTC (since data from level1 should be in UTC!!) |
---|
771 |
dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt] |
---|
772 |
# return new datetime based on computer local |
---|
773 |
dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt] |
---|
774 |
dn = date2num(dt) |
---|
775 |
|
---|
776 |
################################ |
---|
777 |
# [2b] specify variables |
---|
778 |
################################ |
---|
779 |
Hs = nc.var('Hs')[:] |
---|
780 |
Tp = nc.var('Tp')[:] |
---|
781 |
Tm = nc.var('Tm')[:] |
---|
782 |
# Hmax = nc.var('Hmax')[:] |
---|
783 |
Dp = nc.var('Dp')[:] |
---|
784 |
Dm = nc.var('Dm')[:] |
---|
785 |
|
---|
786 |
nc.close() |
---|
787 |
|
---|
788 |
################################ |
---|
789 |
# [3a] load ancillary files if needed |
---|
790 |
################################ |
---|
791 |
|
---|
792 |
ncFile1='/seacoos/data/nccoos/level1/bogue/adcp/bogue_adcp_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
793 |
ncFile2='/seacoos/data/nccoos/level1/bogue/adcp/bogue_adcp_'+this_month.strftime('%Y_%m')+'.nc' |
---|
794 |
|
---|
795 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
796 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
797 |
|
---|
798 |
print ' ... loading data for graph from ...' |
---|
799 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
800 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
801 |
|
---|
802 |
# open netcdf data |
---|
803 |
if have_ncFile1 and have_ncFile2: |
---|
804 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
805 |
elif not have_ncFile1 and have_ncFile2: |
---|
806 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
807 |
elif have_ncFile1 and not have_ncFile2: |
---|
808 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
809 |
else: |
---|
810 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
811 |
return |
---|
812 |
|
---|
813 |
# ncvars = nc.variables() |
---|
814 |
# print ncvars |
---|
815 |
es2 = nc.var('time')[:] |
---|
816 |
units = nc.var('time').units |
---|
817 |
dt2 = [procutil.es2dt(e) for e in es2] |
---|
818 |
# set timezone info to UTC (since data from level1 should be in UTC!!) |
---|
819 |
dt2 = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt2] |
---|
820 |
dn2 = date2num(dt2) |
---|
821 |
|
---|
822 |
################################ |
---|
823 |
# [3b] specify variables |
---|
824 |
################################ |
---|
825 |
wd2 = nc.var('wd')[:] |
---|
826 |
|
---|
827 |
nc.close() |
---|
828 |
|
---|
829 |
# last dt in data for labels |
---|
830 |
dtu = dt[-1] |
---|
831 |
dtl = dt_local[-1] |
---|
832 |
|
---|
833 |
diff = abs(dtu - dtl) |
---|
834 |
if diff.days>0: |
---|
835 |
last_dt_str = dtu.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dtl.strftime("%H:%M %Z, %b %d") + ')' |
---|
836 |
else: |
---|
837 |
last_dt_str = dtu.strftime("%H:%M %Z") + ' (' + dtl.strftime("%H:%M %Z") + ')' \ |
---|
838 |
+ dtl.strftime(" on %b %d, %Y") |
---|
839 |
|
---|
840 |
####################################### |
---|
841 |
# Plot setup |
---|
842 |
####################################### |
---|
843 |
|
---|
844 |
fig = figure(figsize=(10, 8)) |
---|
845 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) |
---|
846 |
|
---|
847 |
ax = fig.add_subplot(4,1,1) |
---|
848 |
axs = [ax] |
---|
849 |
|
---|
850 |
# ax.plot returns a list of lines, so unpack tuple |
---|
851 |
(x, y) = procutil.addnan(dt2, wd2, maxdelta=2./24) |
---|
852 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
853 |
l1.set_label('Water Depth (m)') |
---|
854 |
|
---|
855 |
ax.set_ylabel('Depth (m)') |
---|
856 |
# ax.set_ylim(2.,10.) |
---|
857 |
# ax.set_xlim(dt[0], dt[-1]) # first to last regardless of what |
---|
858 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
859 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
860 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
861 |
ax.set_xticklabels([]) |
---|
862 |
|
---|
863 |
# this only moves the label not the tick labels |
---|
864 |
ax.xaxis.set_label_position('top') |
---|
865 |
ax.set_xlabel('BOGUE Wind Waves -- ' + yyyy_mm_str) |
---|
866 |
|
---|
867 |
# right-hand side scale |
---|
868 |
ax2 = twinx(ax) |
---|
869 |
ax2.yaxis.tick_right() |
---|
870 |
# convert (lhs) meters to (rhs) feet |
---|
871 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
872 |
ax2.set_ylim(feet) |
---|
873 |
ax2.set_ylabel('Depth (feet)') |
---|
874 |
|
---|
875 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
876 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
877 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
878 |
ax2.set_xticklabels([]) |
---|
879 |
|
---|
880 |
# legend |
---|
881 |
ls1 = l1.get_label() |
---|
882 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
883 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
884 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
885 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
886 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
887 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
888 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
889 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
890 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
891 |
|
---|
892 |
####################################### |
---|
893 |
# |
---|
894 |
ax = fig.add_subplot(4,1,2) |
---|
895 |
axs.append(ax) |
---|
896 |
|
---|
897 |
# ax.plot returns a list of lines, so unpack tuple |
---|
898 |
(x, y) = procutil.addnan(dt, Hs, maxdelta=2./24) |
---|
899 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
900 |
l1.set_label('Significant Wave Height (Hs)') |
---|
901 |
|
---|
902 |
# (x, y) = procutil.addnan(dt, Hmax, maxdelta=2./24) |
---|
903 |
# l2, = ax.plot_date(x, y, fmt='g-') |
---|
904 |
# l2.set_label('Max Wave Height (Hmax)') |
---|
905 |
|
---|
906 |
ax.set_ylabel('WAVE\nHEIGHT (m)') |
---|
907 |
# ax.set_ylim(2.,10.) |
---|
908 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
909 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
910 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
911 |
ax.set_xticklabels([]) |
---|
912 |
|
---|
913 |
# right-hand side scale |
---|
914 |
ax2 = twinx(ax) |
---|
915 |
ax2.yaxis.tick_right() |
---|
916 |
# convert (lhs) meters to (rhs) feet |
---|
917 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
918 |
ax2.set_ylim(feet) |
---|
919 |
ax2.set_ylabel('(feet)') |
---|
920 |
|
---|
921 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
922 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
923 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
924 |
ax2.set_xticklabels([]) |
---|
925 |
|
---|
926 |
# legend |
---|
927 |
ls1 = l1.get_label() |
---|
928 |
# ls2 = l2.get_label() |
---|
929 |
# leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
930 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
931 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
932 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
933 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
934 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
935 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
936 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
937 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
938 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
939 |
|
---|
940 |
####################################### |
---|
941 |
# |
---|
942 |
ax = fig.add_subplot(4,1,3) |
---|
943 |
axs.append(ax) |
---|
944 |
|
---|
945 |
# ax.plot returns a list of lines, so unpack tuple |
---|
946 |
(x, y) = procutil.addnan(dt, Tp, maxdelta=2./24) |
---|
947 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
948 |
l1.set_label('Peak Period (Tp)') |
---|
949 |
|
---|
950 |
(x, y) = procutil.addnan(dt, Tm, maxdelta=2./24) |
---|
951 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
952 |
l2.set_label('Mean Period (Tm)') |
---|
953 |
|
---|
954 |
ax.set_ylabel('WAVE\nPERIOD (s)') |
---|
955 |
# ax.set_ylim(2.,10.) |
---|
956 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
957 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
958 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
959 |
ax.set_xticklabels([]) |
---|
960 |
|
---|
961 |
# legend |
---|
962 |
ls1 = l1.get_label() |
---|
963 |
ls2 = l2.get_label() |
---|
964 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
965 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
966 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
967 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
968 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
969 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
970 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
971 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
972 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
973 |
|
---|
974 |
####################################### |
---|
975 |
# |
---|
976 |
ax = fig.add_subplot(4,1,4) |
---|
977 |
axs.append(ax) |
---|
978 |
|
---|
979 |
# ax.plot returns a list of lines, so unpack tuple |
---|
980 |
(x, y) = procutil.addnan(dt, Dp, maxdelta=2./24) |
---|
981 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
982 |
l1.set_label('Peak Direction (Dp)') |
---|
983 |
|
---|
984 |
(x, y) = procutil.addnan(dt, Dm, maxdelta=2./24) |
---|
985 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
986 |
l2.set_label('Mean Direction (Dp)') |
---|
987 |
|
---|
988 |
ax.set_ylabel('WAVE\nDIR (deg N)') |
---|
989 |
ax.set_ylim(0.,360.) |
---|
990 |
# first to last regardless of what |
---|
991 |
# ax.set_xlim(dt[0], dt[-1]) |
---|
992 |
# last minus 30 days, |
---|
993 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
994 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
995 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
996 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
997 |
|
---|
998 |
ax.set_xlabel('BOGUE Waves -- ' + yyyy_mm_str) |
---|
999 |
|
---|
1000 |
# legend |
---|
1001 |
ls1 = l1.get_label() |
---|
1002 |
ls2 = l2.get_label() |
---|
1003 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
1004 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
1005 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
1006 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
1007 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
1008 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
1009 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
1010 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
1011 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
1012 |
|
---|
1013 |
# save figure for this month |
---|
1014 |
ofn = '/home/haines/rayleigh/img/bogue/bogue_allwaves_'+yyyy_mm_str+'.png' |
---|
1015 |
print '... ... write: %s' % (ofn,) |
---|
1016 |
savefig(ofn) |
---|
1017 |
|
---|
1018 |
|
---|
1019 |
####################################### |
---|
1020 |
# Last 30 days |
---|
1021 |
####################################### |
---|
1022 |
if plot_type=='latest': |
---|
1023 |
print ' ... Last 30 days' |
---|
1024 |
for idx, ax in enumerate(axs): |
---|
1025 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
1026 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
1027 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
1028 |
ax.set_xticklabels([]) |
---|
1029 |
if idx==0: |
---|
1030 |
ax.set_xlabel('BOGUE All Waves -- Last 30 days from ' + last_dt_str) |
---|
1031 |
elif idx==len(axs)-1: |
---|
1032 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
1033 |
ax.set_xlabel('BOGUE All Waves -- Last 30 days from ' + last_dt_str) |
---|
1034 |
|
---|
1035 |
savefig('/home/haines/rayleigh/img/bogue_allwaves_last30days.png') |
---|
1036 |
|
---|
1037 |
|
---|
1038 |
####################################### |
---|
1039 |
# Last 7 days |
---|
1040 |
####################################### |
---|
1041 |
if plot_type=='latest': |
---|
1042 |
print ' ... Last 7 days' |
---|
1043 |
for idx, ax in enumerate(axs): |
---|
1044 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
1045 |
ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) ) |
---|
1046 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
1047 |
ax.set_xticklabels([]) |
---|
1048 |
if idx==0: |
---|
1049 |
ax.set_xlabel('BOGUE All Waves -- Last 7 days from ' + last_dt_str) |
---|
1050 |
elif idx==len(axs)-1: |
---|
1051 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
1052 |
ax.set_xlabel('BOGUE All Waves -- Last 7 days from ' + last_dt_str) |
---|
1053 |
|
---|
1054 |
savefig('/home/haines/rayleigh/img/bogue_allwaves_last07days.png') |
---|
1055 |
|
---|
1056 |
|
---|
1057 |
####################################### |
---|
1058 |
# Last 1 day (24hrs) |
---|
1059 |
####################################### |
---|
1060 |
if plot_type=='latest': |
---|
1061 |
print ' ... Last 1 days' |
---|
1062 |
|
---|
1063 |
for idx, ax in enumerate(axs): |
---|
1064 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
1065 |
ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) ) |
---|
1066 |
ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) ) |
---|
1067 |
ax.set_xticklabels([]) |
---|
1068 |
if idx==0: |
---|
1069 |
ax.set_xlabel('BOGUE All Waves -- Last 24 hours from ' + last_dt_str) |
---|
1070 |
elif idx==len(axs)-1: |
---|
1071 |
ax.xaxis.set_major_formatter( DateFormatter('%H') ) |
---|
1072 |
ax.set_xlabel('BOGUE All Waves -- Last 24 hours from ' + last_dt_str) |
---|
1073 |
|
---|
1074 |
savefig('/home/haines/rayleigh/img/bogue_allwaves_last01days.png') |
---|
1075 |
|
---|
1076 |
|
---|
1077 |
|
---|
1078 |
|
---|