1 |
|
---|
2 |
|
---|
3 |
"""morgan_avp_plot""" |
---|
4 |
|
---|
5 |
import os, sys |
---|
6 |
import datetime, time, dateutil, dateutil.tz |
---|
7 |
import pycdf |
---|
8 |
import numpy |
---|
9 |
|
---|
10 |
sys.path.append('/home/haines/nccoos/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 |
from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, DateFormatter, date2num, num2date |
---|
17 |
import procutil |
---|
18 |
|
---|
19 |
print 'morgan_avp_plot ...' |
---|
20 |
prev_month, this_month, next_month = procutil.find_months(procutil.this_month()) |
---|
21 |
|
---|
22 |
|
---|
23 |
ncFile1='/seacoos/data/nccoos/level1/morgan/avp/morgan_avp_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
24 |
ncFile2='/seacoos/data/nccoos/level1/morgan/avp/morgan_avp_'+this_month.strftime('%Y_%m')+'.nc' |
---|
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 |
|
---|
45 |
es = nc.var('time')[:] |
---|
46 |
units = nc.var('time').units |
---|
47 |
dt = [procutil.es2dt(e) for e in es] |
---|
48 |
|
---|
49 |
dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt] |
---|
50 |
|
---|
51 |
dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt] |
---|
52 |
dn = date2num(dt) |
---|
53 |
z = nc.var('z')[:] |
---|
54 |
wd = nc.var('wd')[:] |
---|
55 |
wtemp = nc.var('wtemp')[:] |
---|
56 |
salin = nc.var('salin')[:] |
---|
57 |
turb = nc.var('turb')[:] |
---|
58 |
ph = nc.var('ph')[:] |
---|
59 |
do = nc.var('do')[:] |
---|
60 |
chl = nc.var('chl')[:] |
---|
61 |
nc.close() |
---|
62 |
|
---|
63 |
|
---|
64 |
dt1 = dt[-1] |
---|
65 |
dt2 = dt_local[-1] |
---|
66 |
|
---|
67 |
diff = abs(dt1 - dt2) |
---|
68 |
if diff.days>0: |
---|
69 |
last_dt_str = dt1.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dt2.strftime("%H:%M %Z, %b %d") + ')' |
---|
70 |
else: |
---|
71 |
last_dt_str = dt1.strftime("%H:%M %Z") + ' (' + dt2.strftime("%H:%M %Z") + ')' \ |
---|
72 |
+ dt2.strftime(" on %b %d, %Y") |
---|
73 |
|
---|
74 |
fig = figure(figsize=(10, 10)) |
---|
75 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) |
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 |
print ' ... Last 30 days' |
---|
81 |
ax = fig.add_subplot(6,1,1) |
---|
82 |
axs = [ax] |
---|
83 |
|
---|
84 |
|
---|
85 |
wtm = numpy.ma.masked_where(numpy.isnan(wtemp), wtemp) |
---|
86 |
|
---|
87 |
cmin = numpy.floor(wtm.min()) |
---|
88 |
cmax = cmin+8. |
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 |
pc = ax.pcolor(dn, z, wtm.T, cmap=cm.get_cmap('jet'), vmin=cmin, vmax=cmax) |
---|
93 |
|
---|
94 |
|
---|
95 |
l,b,w,h = ax.get_position() |
---|
96 |
cax = fig.add_axes([l+0.04, b+0.02, 0.25*w, 0.03]) |
---|
97 |
|
---|
98 |
cb = colorbar(pc, cax=cax, orientation='horizontal') |
---|
99 |
cb.set_label('Water Temperature (deg C)') |
---|
100 |
cb.ax.xaxis.set_label_position('top') |
---|
101 |
cb.ax.set_xticks([0.1, 0.3, 0.5, 0.7, 0.9]) |
---|
102 |
|
---|
103 |
xtl = numpy.round(numpy.linspace(cmin, cmax, 10), decimals=1) |
---|
104 |
|
---|
105 |
cb.ax.set_xticklabels([xtl[1], xtl[3], xtl[5], xtl[7], xtl[9]]) |
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 |
ax.set_ylabel('Depth (m)') |
---|
112 |
ax.set_ylim(-4.,0.) |
---|
113 |
|
---|
114 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
115 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
116 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
117 |
ax.set_xticklabels([]) |
---|
118 |
|
---|
119 |
|
---|
120 |
ax.xaxis.set_label_position('top') |
---|
121 |
ax.set_xlabel('Morgan Bay AVP -- Last 30 days from ' + last_dt_str) |
---|
122 |
|
---|
123 |
|
---|
124 |
ax2 = twinx(ax) |
---|
125 |
ax2.yaxis.tick_right() |
---|
126 |
|
---|
127 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
128 |
ax2.set_ylim(feet) |
---|
129 |
ax2.set_ylabel('Depth (ft)') |
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 |
ax = fig.add_subplot(6,1,2) |
---|
146 |
axs.append(ax) |
---|
147 |
|
---|
148 |
|
---|
149 |
sm = numpy.ma.masked_where(numpy.isnan(salin), salin) |
---|
150 |
|
---|
151 |
cmin = numpy.floor(sm.mean()-2*sm.std()) |
---|
152 |
cmax = cmin+10. |
---|
153 |
|
---|
154 |
|
---|
155 |
pc = ax.pcolor(dn, z, sm.T, cmap=cm.get_cmap('Blues_r'), vmin=cmin, vmax=cmax) |
---|
156 |
|
---|
157 |
|
---|
158 |
l,b,w,h = ax.get_position() |
---|
159 |
cax = fig.add_axes([l+0.04, b+0.02, 0.25*w, 0.03]) |
---|
160 |
|
---|
161 |
cb = colorbar(pc, cax=cax, orientation='horizontal') |
---|
162 |
cb.set_label('Salinity (PSU)') |
---|
163 |
cb.ax.xaxis.set_label_position('top') |
---|
164 |
cb.ax.set_xticks([0.1, 0.3, 0.5, 0.7, 0.9]) |
---|
165 |
xtl = numpy.round(numpy.linspace(cmin, cmax, 10), decimals=1) |
---|
166 |
cb.ax.set_xticklabels([xtl[1], xtl[3], xtl[5], xtl[7], xtl[9]]) |
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 |
ax.set_ylabel('Depth (m)') |
---|
173 |
ax.set_ylim(-4.,0.) |
---|
174 |
|
---|
175 |
|
---|
176 |
|
---|
177 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
178 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
179 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
180 |
ax.set_xticklabels([]) |
---|
181 |
|
---|
182 |
|
---|
183 |
ax2 = twinx(ax) |
---|
184 |
ax2.yaxis.tick_right() |
---|
185 |
|
---|
186 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
187 |
ax2.set_ylim(feet) |
---|
188 |
ax2.set_ylabel('Depth (ft)') |
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 |
|
---|
196 |
|
---|
197 |
|
---|
198 |
|
---|
199 |
|
---|
200 |
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 |
ax = fig.add_subplot(6,1,3) |
---|
205 |
axs.append(ax) |
---|
206 |
|
---|
207 |
|
---|
208 |
sm = numpy.ma.masked_where(numpy.isnan(turb), turb) |
---|
209 |
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 |
cmin, cmax = (0., 10.) |
---|
214 |
|
---|
215 |
pc = ax.pcolor(dn, z, sm.T, cmap=cm.get_cmap('YlOrBr'), vmin=cmin, vmax=cmax) |
---|
216 |
|
---|
217 |
|
---|
218 |
l,b,w,h = ax.get_position() |
---|
219 |
cax = fig.add_axes([l+0.04, b+0.02, 0.25*w, 0.03]) |
---|
220 |
|
---|
221 |
cb = colorbar(pc, cax=cax, orientation='horizontal') |
---|
222 |
cb.set_label('Turbidity (NTU)') |
---|
223 |
cb.ax.xaxis.set_label_position('top') |
---|
224 |
cb.ax.set_xticks([0.1, 0.3, 0.5, 0.7, 0.9]) |
---|
225 |
xtl = numpy.round(numpy.linspace(cmin, cmax, 10), decimals=0) |
---|
226 |
cb.ax.set_xticklabels([xtl[1], xtl[3], xtl[5], xtl[7], xtl[9]]) |
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|
232 |
|
---|
233 |
ax.set_ylabel('Depth (m)') |
---|
234 |
ax.set_ylim(-4.,0.) |
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
239 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
240 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
241 |
ax.set_xticklabels([]) |
---|
242 |
|
---|
243 |
|
---|
244 |
ax2 = twinx(ax) |
---|
245 |
ax2.yaxis.tick_right() |
---|
246 |
|
---|
247 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
248 |
ax2.set_ylim(feet) |
---|
249 |
ax2.set_ylabel('Depth (ft)') |
---|
250 |
|
---|
251 |
|
---|
252 |
|
---|
253 |
ax = fig.add_subplot(6,1,4) |
---|
254 |
axs.append(ax) |
---|
255 |
|
---|
256 |
|
---|
257 |
sm = numpy.ma.masked_where(numpy.isnan(chl), chl) |
---|
258 |
|
---|
259 |
cmin = numpy.floor(sm.min()) |
---|
260 |
cmax = cmin+15. |
---|
261 |
|
---|
262 |
|
---|
263 |
pc = ax.pcolor(dn, z, sm.T, cmap=cm.get_cmap('BuGn'), vmin=cmin, vmax=cmax) |
---|
264 |
|
---|
265 |
|
---|
266 |
l,b,w,h = ax.get_position() |
---|
267 |
cax = fig.add_axes([l+0.04, b+0.02, 0.25*w, 0.03]) |
---|
268 |
|
---|
269 |
cb = colorbar(pc, cax=cax, orientation='horizontal') |
---|
270 |
cb.set_label('Chlorophyll (ug l-1)') |
---|
271 |
cb.ax.xaxis.set_label_position('top') |
---|
272 |
cb.ax.set_xticks([0.1, 0.3, 0.5, 0.7, 0.9]) |
---|
273 |
xtl = numpy.round(numpy.linspace(cmin, cmax, 10), decimals=1) |
---|
274 |
cb.ax.set_xticklabels([xtl[1], xtl[3], xtl[5], xtl[7], xtl[9]]) |
---|
275 |
|
---|
276 |
|
---|
277 |
|
---|
278 |
|
---|
279 |
|
---|
280 |
|
---|
281 |
ax.set_ylabel('Depth (m)') |
---|
282 |
ax.set_ylim(-4.,0.) |
---|
283 |
|
---|
284 |
|
---|
285 |
|
---|
286 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
287 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
288 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
289 |
ax.set_xticklabels([]) |
---|
290 |
|
---|
291 |
|
---|
292 |
ax2 = twinx(ax) |
---|
293 |
ax2.yaxis.tick_right() |
---|
294 |
|
---|
295 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
296 |
ax2.set_ylim(feet) |
---|
297 |
ax2.set_ylabel('Depth (ft)') |
---|
298 |
|
---|
299 |
|
---|
300 |
|
---|
301 |
ax = fig.add_subplot(6,1,5) |
---|
302 |
axs.append(ax) |
---|
303 |
|
---|
304 |
|
---|
305 |
sm = numpy.ma.masked_where(numpy.isnan(do), do) |
---|
306 |
|
---|
307 |
cmin, cmax = (0., 15.) |
---|
308 |
pc = ax.pcolor(dn, z, sm.T, cmap=cm.get_cmap('PiYG'), vmin=cmin, vmax=cmax) |
---|
309 |
|
---|
310 |
|
---|
311 |
l,b,w,h = ax.get_position() |
---|
312 |
cax = fig.add_axes([l+0.04, b+0.02, 0.25*w, 0.03]) |
---|
313 |
|
---|
314 |
cb = colorbar(pc, cax=cax, orientation='horizontal') |
---|
315 |
cb.set_label('Dissolved Oxygen (mg l-1)') |
---|
316 |
cb.ax.xaxis.set_label_position('top') |
---|
317 |
cb.ax.set_xticks([0.1, 0.3, 0.5, 0.7, 0.9]) |
---|
318 |
xtl = numpy.round(numpy.linspace(cmin, cmax, 10), decimals=0) |
---|
319 |
cb.ax.set_xticklabels([xtl[1], xtl[3], xtl[5], xtl[7], xtl[9]]) |
---|
320 |
|
---|
321 |
|
---|
322 |
|
---|
323 |
|
---|
324 |
|
---|
325 |
|
---|
326 |
ax.set_ylabel('Depth (m)') |
---|
327 |
ax.set_ylim(-4.,0.) |
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
332 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
333 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
334 |
ax.set_xticklabels([]) |
---|
335 |
|
---|
336 |
|
---|
337 |
ax2 = twinx(ax) |
---|
338 |
ax2.yaxis.tick_right() |
---|
339 |
|
---|
340 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
341 |
ax2.set_ylim(feet) |
---|
342 |
ax2.set_ylabel('Depth (ft)') |
---|
343 |
|
---|
344 |
|
---|
345 |
|
---|
346 |
ax = fig.add_subplot(6,1,6) |
---|
347 |
axs.append(ax) |
---|
348 |
|
---|
349 |
|
---|
350 |
sm = numpy.ma.masked_where(numpy.isnan(ph), ph) |
---|
351 |
|
---|
352 |
|
---|
353 |
|
---|
354 |
|
---|
355 |
cmin, cmax = (6., 8.) |
---|
356 |
print "%s : %g %g" % ('pH', cmin, cmax) |
---|
357 |
pc = ax.pcolor(dn, z, sm.T, cmap=cm.get_cmap('cool'), vmin=cmin, vmax=cmax) |
---|
358 |
|
---|
359 |
|
---|
360 |
l,b,w,h = ax.get_position() |
---|
361 |
cax = fig.add_axes([l+0.04, b+0.02, 0.25*w, 0.03]) |
---|
362 |
|
---|
363 |
cb = colorbar(pc, cax=cax, orientation='horizontal') |
---|
364 |
cb.set_label('pH') |
---|
365 |
cb.ax.xaxis.set_label_position('top') |
---|
366 |
cb.ax.set_xticks([0.1, 0.3, 0.5, 0.7, 0.9]) |
---|
367 |
xtl = numpy.round(numpy.linspace(cmin, cmax, 10), decimals=1) |
---|
368 |
cb.ax.set_xticklabels([xtl[1], xtl[3], xtl[5], xtl[7], xtl[9]]) |
---|
369 |
|
---|
370 |
|
---|
371 |
|
---|
372 |
|
---|
373 |
|
---|
374 |
|
---|
375 |
ax.set_ylabel('Depth (m)') |
---|
376 |
ax.set_ylim(-4.,0.) |
---|
377 |
|
---|
378 |
|
---|
379 |
|
---|
380 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
381 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
382 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
383 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
384 |
|
---|
385 |
ax.set_xlabel('Morgan Bay AVP -- Last 30 days from ' + last_dt_str) |
---|
386 |
|
---|
387 |
|
---|
388 |
ax2 = twinx(ax) |
---|
389 |
ax2.yaxis.tick_right() |
---|
390 |
|
---|
391 |
feet = [procutil.meters2feet(val) for val in ax.get_ylim()] |
---|
392 |
ax2.set_ylim(feet) |
---|
393 |
ax2.set_ylabel('Depth (ft)') |
---|
394 |
|
---|
395 |
|
---|
396 |
savefig('/home/haines/rayleigh/img/morgan_avp_last30days.png') |
---|
397 |
|
---|
398 |
|
---|
399 |
|
---|
400 |
|
---|
401 |
|
---|
402 |
print ' ... Last 7 days' |
---|
403 |
for i in [0, 1, 2, 3, 4]: |
---|
404 |
ax = axs[i] |
---|
405 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
406 |
ax.xaxis.set_major_locator( DayLocator(range(1,32,1)) ) |
---|
407 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
408 |
ax.set_xticklabels([]) |
---|
409 |
if i==0: |
---|
410 |
ax.set_xlabel('Morgan Bay AVP -- Last 7 days from ' + last_dt_str) |
---|
411 |
|
---|
412 |
|
---|
413 |
ax = axs[5] |
---|
414 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
415 |
ax.xaxis.set_major_locator( DayLocator(range(1,32,1)) ) |
---|
416 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
417 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
418 |
ax.set_xlabel('Morgan Bay AVP -- Last 7 days from ' + last_dt_str) |
---|
419 |
|
---|
420 |
savefig('/home/haines/rayleigh/img/morgan_avp_last07days.png') |
---|
421 |
|
---|
422 |
|
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 |
print ' ... Last 1 days' |
---|
427 |
|
---|
428 |
for i in [0, 1, 2, 3, 4]: |
---|
429 |
ax = axs[i] |
---|
430 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
431 |
ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) ) |
---|
432 |
ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) ) |
---|
433 |
ax.set_xticklabels([]) |
---|
434 |
if i==0: |
---|
435 |
ax.set_xlabel('Morgan Bay AVP -- Last 24 hours from ' + last_dt_str) |
---|
436 |
|
---|
437 |
ax = axs[5] |
---|
438 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
439 |
ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) ) |
---|
440 |
ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) ) |
---|
441 |
ax.xaxis.set_major_formatter( DateFormatter('%H') ) |
---|
442 |
ax.set_xlabel('Morgan Bay AVP -- Last 24 hours from ' + last_dt_str) |
---|
443 |
|
---|
444 |
savefig('/home/haines/rayleigh/img/morgan_avp_last01days.png') |
---|
445 |
|
---|