1 |
#!/usr/bin/env /opt/env/haines/dataproc/bin/python |
---|
2 |
# Last modified: Time-stamp: <2010-03-30 14:15:02 haines> |
---|
3 |
"""meet_all_plot_month""" |
---|
4 |
|
---|
5 |
# plot each month |
---|
6 |
|
---|
7 |
import os, sys, glob, re |
---|
8 |
import datetime, time, dateutil, dateutil.tz |
---|
9 |
import pycdf |
---|
10 |
import numpy |
---|
11 |
|
---|
12 |
sys.path.append('/opt/env/haines/dataproc/raw2proc') |
---|
13 |
del(sys) |
---|
14 |
|
---|
15 |
os.environ["MPLCONFIGDIR"]="/home/haines/.matplotlib/" |
---|
16 |
|
---|
17 |
from pylab import figure, twinx, savefig, setp, getp, cm, colorbar |
---|
18 |
from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, DateFormatter, date2num, num2date |
---|
19 |
import procutil |
---|
20 |
|
---|
21 |
print 'meet_wq_plot_month ...' |
---|
22 |
|
---|
23 |
proc_dir = '/seacoos/data/nccoos/level1/meet/wq/' |
---|
24 |
# fns = glob.glob((os.path.join(proc_dir, '*.nc'))) |
---|
25 |
fns = glob.glob((os.path.join(proc_dir, '*2009*.nc'))) |
---|
26 |
fns.sort() |
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 |
for fn in fns: |
---|
31 |
m=re.search('\d{4}_\d{2}', fn) |
---|
32 |
yyyy_mm = m.group() |
---|
33 |
prev_month, this_month, next_month = procutil.find_months(yyyy_mm) |
---|
34 |
yyyy_mm_str = this_month.strftime('%Y_%m') |
---|
35 |
|
---|
36 |
# load data |
---|
37 |
print ' ... ... read: ' + fn |
---|
38 |
nc = pycdf.CDFMF((fn,)) |
---|
39 |
ncvars = nc.variables() |
---|
40 |
# print ncvars |
---|
41 |
es = nc.var('time')[:] |
---|
42 |
units = nc.var('time').units |
---|
43 |
dt = [procutil.es2dt(e) for e in es] |
---|
44 |
# set timezone info to UTC (since data from level1 should be in UTC!!) |
---|
45 |
dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt] |
---|
46 |
# return new datetime based on computer local |
---|
47 |
dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt] |
---|
48 |
dn = date2num(dt) |
---|
49 |
|
---|
50 |
z = nc.var('z')[:] |
---|
51 |
wtemp = nc.var('wtemp')[:] |
---|
52 |
cond = nc.var('cond')[:] |
---|
53 |
turb = nc.var('turb')[:] |
---|
54 |
ph = nc.var('ph')[:] |
---|
55 |
do_mg = nc.var('do_mg')[:] |
---|
56 |
do_sat = nc.var('do_sat')[:] |
---|
57 |
batt = nc.var('battvolts')[:] |
---|
58 |
nc.close() |
---|
59 |
|
---|
60 |
fn_flow = '/seacoos/data/nccoos/level1/meet/flow/meet_flow_' + yyyy_mm_str + '.nc' |
---|
61 |
print ' ... ... read: ' + fn_flow |
---|
62 |
nc = pycdf.CDFMF((fn_flow,)) |
---|
63 |
ncvars = nc.variables() |
---|
64 |
# print ncvars |
---|
65 |
es2 = nc.var('time')[:] |
---|
66 |
units = nc.var('time').units |
---|
67 |
dt2 = [procutil.es2dt(e) for e in es2] |
---|
68 |
# set timezone info to UTC (since data from level1 should be in UTC!!) |
---|
69 |
dt2 = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt2] |
---|
70 |
dn2 = date2num(dt2) |
---|
71 |
|
---|
72 |
r2 = nc.var('rain')[:] # inches of rain in past 15 min |
---|
73 |
have_sontek = False # don't plot sontek |
---|
74 |
# have_sontek = 'sontek_wl' in ncvars.keys() or 'sontek_flow' in ncvars.keys() |
---|
75 |
pwl2 = nc.var('press_wl')[:] # feet |
---|
76 |
pfl2 = nc.var('press_flow')[:] # cfs |
---|
77 |
|
---|
78 |
if have_sontek: |
---|
79 |
swl2 = nc.var('sontek_wl')[:] # feet |
---|
80 |
sfl2 = nc.var('sontek_flow')[:] # cfs |
---|
81 |
|
---|
82 |
nc.close() |
---|
83 |
|
---|
84 |
# last dt in data for labels |
---|
85 |
dtu = dt[-1] |
---|
86 |
dtl = dt_local[-1] |
---|
87 |
|
---|
88 |
diff = abs(dtu - dtl) |
---|
89 |
if diff.days>0: |
---|
90 |
last_dt_str = dtu.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dtl.strftime("%H:%M %Z, %b %d") + ')' |
---|
91 |
else: |
---|
92 |
last_dt_str = dtu.strftime("%H:%M %Z") + ' (' + dtl.strftime("%H:%M %Z") + ')' \ |
---|
93 |
+ dtl.strftime(" on %b %d, %Y") |
---|
94 |
|
---|
95 |
####################################### |
---|
96 |
# Plot month all wq (plus flow) the timeseries data |
---|
97 |
####################################### |
---|
98 |
|
---|
99 |
fig = figure(figsize=(10, 9)) |
---|
100 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) |
---|
101 |
|
---|
102 |
ax = fig.add_subplot(6,1,1) |
---|
103 |
axs = [ax] |
---|
104 |
|
---|
105 |
# ax.plot returns a list of lines, so unpack tuple |
---|
106 |
(x, y) = procutil.addnan(dt, wtemp) |
---|
107 |
ibad = y <= -6999. |
---|
108 |
y[ibad] = numpy.nan |
---|
109 |
# if all are NaN's then pyplot throws an error for autoscale |
---|
110 |
# for some reason setting one value in the timeseries to a real value |
---|
111 |
# fixes this. |
---|
112 |
if numpy.isnan(y).all(): |
---|
113 |
y[-1]=0. |
---|
114 |
|
---|
115 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
116 |
l1.set_label('Water Temperature') |
---|
117 |
|
---|
118 |
ax.set_ylabel('TEMP\n (deg C)') |
---|
119 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
120 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
121 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
122 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
123 |
ax.set_xticklabels([]) |
---|
124 |
|
---|
125 |
# right-hand side scale |
---|
126 |
ax2 = twinx(ax) |
---|
127 |
ax2.yaxis.tick_right() |
---|
128 |
# convert (lhs) deg C to (rhs) deg F |
---|
129 |
f = [procutil.celsius2fahrenheit(val) for val in ax.get_ylim()] |
---|
130 |
ax2.set_ylim(f) |
---|
131 |
ax2.set_ylabel('(deg F)') |
---|
132 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
133 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
134 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
135 |
ax2.set_xticklabels([]) |
---|
136 |
|
---|
137 |
# this only moves the label not the tick labels |
---|
138 |
ax.xaxis.set_label_position('top') |
---|
139 |
ax.set_xlabel('MEET Water Quality -- ' + yyyy_mm_str) |
---|
140 |
|
---|
141 |
# legend |
---|
142 |
ls1 = l1.get_label() |
---|
143 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
144 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
145 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
146 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
147 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
148 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
149 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
150 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
151 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
152 |
|
---|
153 |
####################################### |
---|
154 |
# |
---|
155 |
ax = fig.add_subplot(6,1,2) |
---|
156 |
axs.append(ax) |
---|
157 |
|
---|
158 |
# ax.plot returns a list of lines, so unpack tuple |
---|
159 |
(x, y) = procutil.addnan(dt, cond) |
---|
160 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
161 |
l1.set_label('Specific Conductivity') |
---|
162 |
|
---|
163 |
ax.set_ylabel('Cond\n (mS/cm)') |
---|
164 |
# ax.set_ylim(0,10) |
---|
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.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
169 |
ax.set_xticklabels([]) |
---|
170 |
|
---|
171 |
# legend |
---|
172 |
ls1 = l1.get_label() |
---|
173 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
174 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
175 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
176 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
177 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
178 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
179 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
180 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
181 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
182 |
|
---|
183 |
####################################### |
---|
184 |
# |
---|
185 |
ax = fig.add_subplot(6,1,3) |
---|
186 |
axs.append(ax) |
---|
187 |
|
---|
188 |
# ax.plot returns a list of lines, so unpack tuple |
---|
189 |
(x, y) = procutil.addnan(dt, do_mg) |
---|
190 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
191 |
l1.set_label('Dissolved Oxygen (DO)') |
---|
192 |
|
---|
193 |
ax.set_ylabel('DO \n(mg/l)') |
---|
194 |
# ax.set_ylim(20,120) |
---|
195 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
196 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
197 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
198 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
199 |
ax.set_xticklabels([]) |
---|
200 |
|
---|
201 |
# right-hand side scale |
---|
202 |
ax2 = twinx(ax) |
---|
203 |
ax2.yaxis.tick_right() |
---|
204 |
(x, y) = procutil.addnan(dt, do_sat) |
---|
205 |
l2, = ax2.plot_date(x, y, fmt='c-') |
---|
206 |
l2.set_label('Percent Air Saturation') |
---|
207 |
# convert (lhs) deg C to (rhs) deg F |
---|
208 |
# ax2.set_ylim(0,200) |
---|
209 |
ax2.set_ylabel('DO (%)') |
---|
210 |
# ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
211 |
# ax2.set_xticklabels([]) |
---|
212 |
|
---|
213 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
214 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
215 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
216 |
ax2.set_xticklabels([]) |
---|
217 |
|
---|
218 |
# legend |
---|
219 |
ls1 = l1.get_label() |
---|
220 |
ls2 = l2.get_label() |
---|
221 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
222 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
223 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
224 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
225 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
226 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
227 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
228 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
229 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
230 |
####################################### |
---|
231 |
# |
---|
232 |
ax = fig.add_subplot(6,1,4) |
---|
233 |
axs.append(ax) |
---|
234 |
|
---|
235 |
# ax.plot returns a list of lines, so unpack tuple |
---|
236 |
(x, y) = procutil.addnan(dt, ph) |
---|
237 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
238 |
l1.set_label('pH') |
---|
239 |
|
---|
240 |
ax.set_ylabel('pH') |
---|
241 |
# ax.set_ylim(6, 12) |
---|
242 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
243 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
244 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
245 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
246 |
ax.set_xticklabels([]) |
---|
247 |
|
---|
248 |
# legend |
---|
249 |
ls1 = l1.get_label() |
---|
250 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
251 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
252 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
253 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
254 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
255 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
256 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
257 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
258 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
259 |
|
---|
260 |
####################################### |
---|
261 |
# |
---|
262 |
ax = fig.add_subplot(6,1,5) |
---|
263 |
axs.append(ax) |
---|
264 |
|
---|
265 |
# ax.plot returns a list of lines, so unpack tuple |
---|
266 |
(x, y) = procutil.addnan(dt, turb) |
---|
267 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
268 |
l1.set_label('Turbidity') |
---|
269 |
|
---|
270 |
ax.set_ylabel('Turb \n(NTU)') |
---|
271 |
# ax.set_ylim(0,100) |
---|
272 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
273 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
274 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
275 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
276 |
ax.set_xticklabels([]) |
---|
277 |
|
---|
278 |
# legend |
---|
279 |
ls1 = l1.get_label() |
---|
280 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
281 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
282 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
283 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
284 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
285 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
286 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
287 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
288 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
289 |
|
---|
290 |
####################################### |
---|
291 |
# |
---|
292 |
ax = fig.add_subplot(6,1,6) |
---|
293 |
axs.append(ax) |
---|
294 |
|
---|
295 |
# ax.plot returns a list of lines, so unpack tuple |
---|
296 |
(x, y) = procutil.addnan(dt2, pfl2) |
---|
297 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
298 |
l1.set_label('Derived from pressure') |
---|
299 |
|
---|
300 |
# right-hand side scale |
---|
301 |
ax2 = twinx(ax) |
---|
302 |
ax2.yaxis.tick_right() |
---|
303 |
|
---|
304 |
(x, y) = procutil.addnan(dt2, r2) |
---|
305 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
306 |
l2.set_label('Precipitation') |
---|
307 |
|
---|
308 |
ax2.set_ylim(0, 1.) |
---|
309 |
ax2.set_ylabel('Rain\n (in)') |
---|
310 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
311 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
312 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
313 |
ax2.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
314 |
ax2.set_xticklabels([]) |
---|
315 |
|
---|
316 |
ax.set_ylim(0,350) |
---|
317 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
318 |
(axmin, axmax) = ax.get_xlim() |
---|
319 |
ax.plot_date((axmin, axmax), (0,0), fmt='k--') |
---|
320 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
321 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
322 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
323 |
|
---|
324 |
ax.set_xlabel('MEET Water Quality -- ' + yyyy_mm_str) |
---|
325 |
|
---|
326 |
# legend |
---|
327 |
ls1 = l1.get_label() |
---|
328 |
ls2 = l2.get_label() |
---|
329 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
330 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
331 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
332 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
333 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
334 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
335 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
336 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
337 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
338 |
|
---|
339 |
# save figure |
---|
340 |
ofn = '/home/haines/rayleigh/img/meet/meet_wq_'+yyyy_mm_str+'.png' |
---|
341 |
print '... ... write: %s' % (ofn,) |
---|
342 |
savefig(ofn) |
---|
343 |
|
---|
344 |
del(fig) |
---|
345 |
|
---|
346 |
####################################### |
---|
347 |
# Plot month all rain flow the timeseries data |
---|
348 |
####################################### |
---|
349 |
|
---|
350 |
fig = figure(figsize=(10, 8)) |
---|
351 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) |
---|
352 |
|
---|
353 |
ax = fig.add_subplot(4,1,1) |
---|
354 |
axs = [ax] |
---|
355 |
|
---|
356 |
# ax.plot returns a list of lines, so unpack tuple |
---|
357 |
(x, y) = procutil.addnan(dt2, r2) |
---|
358 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
359 |
l1.set_label('Precipitation') |
---|
360 |
|
---|
361 |
ax.set_ylabel('Rain (in)') |
---|
362 |
ax.set_ylim(0,1.) |
---|
363 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
364 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
365 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
366 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
367 |
ax.set_xticklabels([]) |
---|
368 |
|
---|
369 |
# right-hand side scale |
---|
370 |
ax2 = twinx(ax) |
---|
371 |
ax2.yaxis.tick_right() |
---|
372 |
# convert (lhs) inches to (rhs) mm |
---|
373 |
f = [procutil.inches2millimeters(val) for val in ax.get_ylim()] |
---|
374 |
ax2.set_ylim(f) |
---|
375 |
ax2.set_ylabel('Rain (mm)') |
---|
376 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
377 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
378 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
379 |
ax2.set_xticklabels([]) |
---|
380 |
|
---|
381 |
# this only moves the label not the tick labels |
---|
382 |
ax.xaxis.set_label_position('top') |
---|
383 |
ax.set_xlabel('MEET Stream Flow -- ' + yyyy_mm_str) |
---|
384 |
|
---|
385 |
# legend |
---|
386 |
ls1 = l1.get_label() |
---|
387 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
388 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
389 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
390 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
391 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
392 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
393 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
394 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
395 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
396 |
|
---|
397 |
####################################### |
---|
398 |
# |
---|
399 |
ax = fig.add_subplot(4,1,2) |
---|
400 |
axs.append(ax) |
---|
401 |
|
---|
402 |
# ax.plot returns a list of lines, so unpack tuple |
---|
403 |
(x, y) = procutil.addnan(dt2, pwl2) |
---|
404 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
405 |
l1.set_label('Derived from pressure') |
---|
406 |
if have_sontek: |
---|
407 |
(x, y) = procutil.addnan(dt2, swl2) |
---|
408 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
409 |
l2.set_label('From Acoustic Sounding') |
---|
410 |
|
---|
411 |
ax.set_ylabel('Depth (ft)') |
---|
412 |
ax.set_ylim(-0.2,3) |
---|
413 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
414 |
(axmin, axmax) = ax.get_xlim() |
---|
415 |
ax.plot_date((axmin, axmax), (0,0), fmt='k--') |
---|
416 |
ax.plot_date((axmin, axmax), (2.5,2.5), fmt='k--') |
---|
417 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
418 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
419 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
420 |
ax.set_xticklabels([]) |
---|
421 |
|
---|
422 |
# right-hand side scale |
---|
423 |
ax2 = twinx(ax) |
---|
424 |
ax2.yaxis.tick_right() |
---|
425 |
# convert (lhs) feet to (rhs) meters |
---|
426 |
f = [procutil.feet2meters(val) for val in ax.get_ylim()] |
---|
427 |
ax2.set_ylim(f) |
---|
428 |
ax2.set_ylabel('Depth (m)') |
---|
429 |
ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
430 |
ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
431 |
ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
432 |
ax2.set_xticklabels([]) |
---|
433 |
|
---|
434 |
# legend |
---|
435 |
ls1 = l1.get_label() |
---|
436 |
if have_sontek: |
---|
437 |
ls2 = l2.get_label() |
---|
438 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
439 |
else: |
---|
440 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
441 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
442 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
443 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
444 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
445 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
446 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
447 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
448 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
449 |
|
---|
450 |
####################################### |
---|
451 |
# |
---|
452 |
ax = fig.add_subplot(4,1,3) |
---|
453 |
axs.append(ax) |
---|
454 |
|
---|
455 |
# ax.plot returns a list of lines, so unpack tuple |
---|
456 |
(x, y) = procutil.addnan(dt2, pfl2) |
---|
457 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
458 |
l1.set_label('Derived from pressure') |
---|
459 |
if have_sontek: |
---|
460 |
(x, y) = procutil.addnan(dt2, sfl2) |
---|
461 |
l2, = ax.plot_date(x, y, fmt='c-') |
---|
462 |
l2.set_label('Depth-avg Acoustic Profile') |
---|
463 |
|
---|
464 |
ax.set_ylabel('Flow (cfs)') |
---|
465 |
ax.set_ylim(0,350) |
---|
466 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
467 |
(axmin, axmax) = ax.get_xlim() |
---|
468 |
ax.plot_date((axmin, axmax), (0,0), fmt='k--') |
---|
469 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
470 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
471 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
472 |
ax.set_xticklabels([]) |
---|
473 |
|
---|
474 |
# legend |
---|
475 |
ls1 = l1.get_label() |
---|
476 |
if have_sontek: |
---|
477 |
ls2 = l2.get_label() |
---|
478 |
leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left') |
---|
479 |
else: |
---|
480 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
481 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
482 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
483 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
484 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
485 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
486 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
487 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
488 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
489 |
|
---|
490 |
####################################### |
---|
491 |
# |
---|
492 |
ax = fig.add_subplot(4,1,4) |
---|
493 |
axs.append(ax) |
---|
494 |
|
---|
495 |
# ax.plot returns a list of lines, so unpack tuple |
---|
496 |
(x, y) = procutil.addnan(dt, batt) |
---|
497 |
l1, = ax.plot_date(x, y, fmt='b-') |
---|
498 |
l1.set_label('Station Battery') |
---|
499 |
|
---|
500 |
ax.set_ylabel('Battery\n (volts)') |
---|
501 |
ax.set_ylim(12, 14.5) |
---|
502 |
ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1))) |
---|
503 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
504 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
505 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
506 |
|
---|
507 |
ax.set_xlabel('MEET Stream Flow -- ' + yyyy_mm_str) |
---|
508 |
|
---|
509 |
# legend |
---|
510 |
ls1 = l1.get_label() |
---|
511 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
512 |
ltext = leg.get_texts() # all the text.Text instance in the legend |
---|
513 |
llines = leg.get_lines() # all the lines.Line2D instance in the legend |
---|
514 |
frame = leg.get_frame() # the patch.Rectangle instance surrounding the legend |
---|
515 |
frame.set_facecolor('0.80') # set the frame face color to light gray |
---|
516 |
frame.set_alpha(0.5) # set alpha low to see through |
---|
517 |
setp(ltext, fontsize='small') # the legend text fontsize |
---|
518 |
setp(llines, linewidth=1.5) # the legend linewidth |
---|
519 |
# leg.draw_frame(False) # don't draw the legend frame |
---|
520 |
|
---|
521 |
# save figure |
---|
522 |
ofn = '/home/haines/rayleigh/img/meet/meet_flow_' + yyyy_mm_str + '.png' |
---|
523 |
print '... ... write: %s' % (ofn,) |
---|
524 |
savefig(ofn) |
---|
525 |
|
---|