NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/proc2plot/trunk/proc2plot/scratch/test_crow_flow_plot.py

Revision 329 (checked in by haines, 14 years ago)

import first verison proc2plot

  • Property svn:executable set to
Line 
1 #!/usr/bin/env /opt/env/haines/dataproc/bin/python
2 # Last modified:  Time-stamp: <2009-09-16 14:03:50 haines>
3 """crow_all_plot"""
4
5 import os, sys, glob, re
6 import datetime, time, dateutil, dateutil.tz
7 import pycdf
8 import numpy
9
10 sys.path.append('/opt/env/haines/dataproc/raw2proc')
11 del(sys)
12
13 os.environ["MPLCONFIGDIR"]="/home/haines/.matplotlib/"
14
15 from pylab import figure, twinx, savefig, setp, getp, cm, colorbar
16 from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, DateFormatter, date2num, num2date
17 import procutil
18
19 print 'crow_all_plot ...'
20
21 proc_dir = '/seacoos/data/nccoos/level1/crow/wq/'
22 # fns = glob.glob((os.path.join(proc_dir, '*.nc')))
23 fns = glob.glob((os.path.join(proc_dir, '*2009*.nc')))
24 fns.sort()
25
26 for fn in fns:
27     m=re.search('\d{4}_\d{2}', fn)
28     yyyy_mm = m.group()
29     prev_month, this_month, next_month = procutil.find_months(yyyy_mm)
30     yyyy_mm_str = this_month.strftime('%Y_%m')
31    
32 prev_month, this_month, next_month = procutil.find_months(procutil.this_month())
33 #ncFile1='/seacoos/data/nccoos/level1/meet/wq/meet_wq_2009_08.nc'
34 #ncFile2='/seacoos/data/nccoos/level1/meet/wq/meet_wq_2008_09.nc'
35
36 datadir = '/seacoos/data/nccoos/level1'
37 platform = 'meet'
38 package = 'wq'
39
40 ncFile1 = os.path.join(datadir, platform, package, platform+'_'+package+'_'+prev_month.strftime('%Y_%m')+'.nc')
41 ncFile2 = os.path.join(datadir, platform, package, platform+'_'+package+'_'+this_month.strftime('%Y_%m')+'.nc')
42
43 # load data
44
45 have_ncFile1 = os.path.exists(ncFile1)
46 have_ncFile2 = os.path.exists(ncFile2)
47
48 print ' ... loading data for graph from ...'
49 print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1)
50 print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2)
51
52 if have_ncFile1 and have_ncFile2:
53     nc = pycdf.CDFMF((ncFile1, ncFile2))
54 elif not have_ncFile1 and have_ncFile2:
55     nc = pycdf.CDFMF((ncFile2,))
56 elif have_ncFile1 and not have_ncFile2:
57     nc = pycdf.CDFMF((ncFile1,))
58 else:
59     print ' ... both files do not exist -- NO DATA LOADED'
60     print ' ... NO PLOTS CREATED'
61     exit()
62
63
64     # get variable names
65     ncvars = nc.variables()
66     # print ncvars
67     es = nc.var('time')[:]
68     units = nc.var('time').units
69     dt = [procutil.es2dt(e) for e in es]
70     # set timezone info to UTC (since data from level1 should be in UTC!!)
71     dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt]
72     # return new datetime based on computer local
73     dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt]
74     dn = date2num(dt)
75    
76     z = nc.var('z')[:]
77     wtemp = nc.var('wtemp')[:]
78     cond = nc.var('cond')[:]
79     turb = nc.var('turb')[:]
80     ph = nc.var('ph')[:]
81     do_mg = nc.var('do_mg')[:]
82     do_sat = nc.var('do_sat')[:]
83     batt = nc.var('battvolts')[:]
84     nc.close()
85
86 package = 'flow'
87 ncFile1 = os.path.join(datadir, platform, package, platform+'_'+package+'_'+prev_month.strftime('%Y_%m')+'.nc')
88 ncFile2 = os.path.join(datadir, platform, package, platform+'_'+package+'_'+this_month.strftime('%Y_%m')+'.nc')
89
90 # load data
91
92 have_ncFile1 = os.path.exists(ncFile1)
93 have_ncFile2 = os.path.exists(ncFile2)
94
95 print ' ... loading data for graph from ...'
96 print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1)
97 print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2)
98
99 if have_ncFile1 and have_ncFile2:
100     nc = pycdf.CDFMF((ncFile1, ncFile2))
101 elif not have_ncFile1 and have_ncFile2:
102     nc = pycdf.CDFMF((ncFile2,))
103 elif have_ncFile1 and not have_ncFile2:
104     nc = pycdf.CDFMF((ncFile1,))
105 else:
106     print ' ... both files do not exist -- NO DATA LOADED'
107
108     # get variable names
109     ncvars = nc.variables()
110     # print ncvars
111     es2 = nc.var('time')[:]
112     units = nc.var('time').units
113     dt2 = [procutil.es2dt(e) for e in es2]
114     # set timezone info to UTC (since data from level1 should be in UTC!!)
115     dt2 = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt2]
116     dn2 = date2num(dt2)
117    
118     r2 = nc.var('rain')[:] # inches of rain in past 15 min
119     have_sontek = 'sontek_wl' in ncvars.keys() or 'sontek_flow' in ncvars.keys()
120     have_press = 'press_wl' in ncvars.keys() or 'press_flow' in ncvars.keys()
121    
122     if have_press:
123         pwl2 = nc.var('press_wl')[:] # feet
124         pfl2 = nc.var('press_flow')[:] # cfs
125     
126     if have_sontek:
127         swl2 = nc.var('sontek_wl')[:] # feet
128         sfl2 = nc.var('sontek_flow')[:] # cfs
129     
130     nc.close()
131
132     # last dt in data for labels
133     dtu = dt[-1]
134     dtl = dt_local[-1]
135    
136     diff = abs(dtu - dtl)
137     if diff.days>0:
138         last_dt_str = dtu.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dtl.strftime("%H:%M %Z, %b %d") + ')'
139     else:
140         last_dt_str = dtu.strftime("%H:%M %Z") + ' (' + dtl.strftime("%H:%M %Z") + ')' \
141                       + dtl.strftime(" on %b %d, %Y")
142        
143     #######################################
144     # Plot month all wq (plus flow) the timeseries data
145     #######################################
146
147     fig = figure(figsize=(10, 9))
148     fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1)
149    
150     ax = fig.add_subplot(6,1,1)
151     axs = [ax]
152    
153     # ax.plot returns a list of lines, so unpack tuple
154     (x, y) = procutil.addnan(dt, wtemp)
155     ibad = y <= -6999.
156     y[ibad] = numpy.nan
157     # if all are NaN's then pyplot throws an error for autoscale
158     # for some reason setting one value in the timeseries to a real value
159     # fixes this.
160     if numpy.isnan(y).all():
161         y[-1]=0.
162        
163     l1, = ax.plot_date(x, y, fmt='b-')
164     l1.set_label('Water Temperature')
165    
166     ax.set_ylabel('TEMP\n (deg C)')
167     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
168     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
169     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
170     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
171     ax.set_xticklabels([])
172
173     # right-hand side scale
174     ax2 = twinx(ax)
175     ax2.yaxis.tick_right()
176     # convert (lhs) deg C to (rhs) deg F
177     f = [procutil.celsius2fahrenheit(val) for val in ax.get_ylim()]
178     ax2.set_ylim(f)
179     ax2.set_ylabel('(deg F)')
180
181     ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
182     ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
183     ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
184     ax2.set_xticklabels([])
185
186     # this only moves the label not the tick labels
187     ax.xaxis.set_label_position('top')
188     ax.set_xlabel('CROW Water Quality -- ' + yyyy_mm_str)
189    
190     # legend
191     ls1 = l1.get_label()
192     leg = ax.legend((l1,), (ls1,), loc='upper left')
193     ltext  = leg.get_texts()  # all the text.Text instance in the legend
194     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
195     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
196     frame.set_facecolor('0.80')      # set the frame face color to light gray
197     frame.set_alpha(0.5)             # set alpha low to see through
198     setp(ltext, fontsize='small')    # the legend text fontsize
199     setp(llines, linewidth=1.5)      # the legend linewidth
200     # leg.draw_frame(False)           # don't draw the legend frame
201     
202     #######################################
203     #
204     ax = fig.add_subplot(6,1,2)
205     axs.append(ax)
206
207     # ax.plot returns a list of lines, so unpack tuple
208     (x, y) = procutil.addnan(dt, cond)
209     l1, = ax.plot_date(x, y, fmt='b-')
210     l1.set_label('Specific Conductivity')
211    
212     ax.set_ylabel('Cond\n (mS/cm)')
213     # ax.set_ylim(0,10)
214     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
215     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
216     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
217     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
218     ax.set_xticklabels([])
219
220     # legend
221     ls1 = l1.get_label()
222     leg = ax.legend((l1,), (ls1,), loc='upper left')
223     ltext  = leg.get_texts()  # all the text.Text instance in the legend
224     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
225     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
226     frame.set_facecolor('0.80')      # set the frame face color to light gray
227     frame.set_alpha(0.5)             # set alpha low to see through
228     setp(ltext, fontsize='small')    # the legend text fontsize
229     setp(llines, linewidth=1.5)      # the legend linewidth
230     # leg.draw_frame(False)           # don't draw the legend frame
231     
232     #######################################
233     #
234     ax = fig.add_subplot(6,1,3)
235     axs.append(ax)
236        
237     # ax.plot returns a list of lines, so unpack tuple
238     (x, y) = procutil.addnan(dt, do_mg)
239     l1, = ax.plot_date(x, y, fmt='b-')
240     l1.set_label('Dissolved Oxygen (DO)')
241    
242     ax.set_ylabel('DO \n(mg/l)')
243     # ax.set_ylim(20,120)
244     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
245     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
246     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
247     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
248     ax.set_xticklabels([])
249
250     # right-hand side scale
251     ax2 = twinx(ax)
252     ax2.yaxis.tick_right()
253     (x, y) = procutil.addnan(dt, do_sat)
254     l2, = ax2.plot_date(x, y, fmt='c-')
255     l2.set_label('Percent Air Saturation')   
256     # convert (lhs) deg C to (rhs) deg F
257     # ax2.set_ylim(0,200)
258     ax2.set_ylabel('DO (%)')
259     ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
260     ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
261     ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
262     ax2.set_xticklabels([])
263    
264     # legend
265     ls1 = l1.get_label()
266     ls2 = l2.get_label()
267     leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left')
268     ltext  = leg.get_texts()  # all the text.Text instance in the legend
269     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
270     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
271     frame.set_facecolor('0.80')      # set the frame face color to light gray
272     frame.set_alpha(0.5)             # set alpha low to see through
273     setp(ltext, fontsize='small')    # the legend text fontsize
274     setp(llines, linewidth=1.5)      # the legend linewidth
275     # leg.draw_frame(False)           # don't draw the legend frame
276     #######################################
277     #
278     ax = fig.add_subplot(6,1,4)
279     axs.append(ax)
280
281     # ax.plot returns a list of lines, so unpack tuple
282     (x, y) = procutil.addnan(dt, ph)
283     l1, = ax.plot_date(x, y, fmt='b-')
284     l1.set_label('pH')
285    
286     ax.set_ylabel('pH')
287     # ax.set_ylim(6, 12)
288     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
289     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
290     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
291     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
292     ax.set_xticklabels([])
293
294     # legend
295     ls1 = l1.get_label()
296     leg = ax.legend((l1,), (ls1,), loc='upper left')
297     ltext  = leg.get_texts()  # all the text.Text instance in the legend
298     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
299     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
300     frame.set_facecolor('0.80')      # set the frame face color to light gray
301     frame.set_alpha(0.5)             # set alpha low to see through
302     setp(ltext, fontsize='small')    # the legend text fontsize
303     setp(llines, linewidth=1.5)      # the legend linewidth
304     # leg.draw_frame(False)           # don't draw the legend frame
305     
306     #######################################
307     #
308     ax = fig.add_subplot(6,1,5)
309     axs.append(ax)
310    
311     # ax.plot returns a list of lines, so unpack tuple
312     (x, y) = procutil.addnan(dt, turb)
313     l1, = ax.plot_date(x, y, fmt='b-')
314     l1.set_label('Turbidity')
315    
316     ax.set_ylabel('Turb \n(NTU)')
317     # ax.set_ylim(0,100)
318     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
319     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
320     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
321     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
322     ax.set_xticklabels([])
323
324     # legend
325     ls1 = l1.get_label()
326     leg = ax.legend((l1,), (ls1,), loc='upper left')
327     ltext  = leg.get_texts()  # all the text.Text instance in the legend
328     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
329     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
330     frame.set_facecolor('0.80')      # set the frame face color to light gray
331     frame.set_alpha(0.5)             # set alpha low to see through
332     setp(ltext, fontsize='small')    # the legend text fontsize
333     setp(llines, linewidth=1.5)      # the legend linewidth
334     # leg.draw_frame(False)           # don't draw the legend frame
335     
336     #######################################
337     #
338     ax = fig.add_subplot(6,1,6)
339     axs.append(ax)
340    
341     # ax.plot returns a list of lines, so unpack tuple
342     if have_press:
343         (x, y) = procutil.addnan(dt2, pfl2)
344         l1, = ax.plot_date(x, y, fmt='b-')
345         l1.set_label('Derived from pressure')
346         ls1 = l1.get_label()
347     if have_sontek:
348         (x, y) = procutil.addnan(dt2, sfl2)
349         l2, = ax.plot_date(x, y, fmt='c-')
350         l2.set_label('Depth-avg Acoustic Profile')   
351         ls2 = l2.get_label()
352    
353     ax.set_ylabel('Flow\n (cfs)')
354     # ax.set_ylim(0,15)
355     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
356     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
357     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
358     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
359
360     ax.set_xlabel('CROW Water Quality -- ' + yyyy_mm_str)
361
362     # legend
363     if have_press and have_sontek:
364         leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left')
365     elif have_press:
366         leg = ax.legend((l1,), (ls1,), loc='upper left')       
367     if have_sontek:
368         leg = ax.legend((l2,), (ls2,), loc='upper left')       
369
370     ltext  = leg.get_texts()  # all the text.Text instance in the legend
371     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
372     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
373     frame.set_facecolor('0.80')      # set the frame face color to light gray
374     frame.set_alpha(0.5)             # set alpha low to see through
375     setp(ltext, fontsize='small')    # the legend text fontsize
376     setp(llines, linewidth=1.5)      # the legend linewidth
377     # leg.draw_frame(False)           # don't draw the legend frame
378
379     # save figure   
380     ofn = '/home/haines/rayleigh/img/crow/crow_wq_'+yyyy_mm_str+'.png'
381     print '... ... write: %s' % (ofn,)
382     savefig(ofn)
383
384     del(fig)
385        
386     #######################################
387     # Plot month all rain flow the timeseries data
388     #######################################
389
390     fig = figure(figsize=(10, 8))
391     fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1)
392    
393     ax = fig.add_subplot(4,1,1)
394     axs = [ax]
395    
396     # ax.plot returns a list of lines, so unpack tuple
397     (x, y) = procutil.addnan(dt2, r2)
398     l1, = ax.plot_date(x, y, fmt='b-')
399     l1.set_label('Precipitation')
400    
401     ax.set_ylabel('Rain (in)')
402     # ax.set_ylim(0,30)
403     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
404     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
405     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
406     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
407     ax.set_xticklabels([])
408
409     # right-hand side scale
410     ax2 = twinx(ax)
411     ax2.yaxis.tick_right()
412     # convert (lhs) deg C to (rhs) deg F
413     f = [procutil.inches2millimeters(val) for val in ax.get_ylim()]
414     ax2.set_ylim(f)
415     ax2.set_ylabel('Rain (mm)')
416     ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
417     ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
418     ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
419     ax2.set_xticklabels([])
420
421     # this only moves the label not the tick labels
422     ax.xaxis.set_label_position('top')
423     ax.set_xlabel('CROW Stream Flow -- ' + yyyy_mm_str)
424    
425     # legend
426     ls1 = l1.get_label()
427     leg = ax.legend((l1,), (ls1,), loc='upper left')
428     ltext  = leg.get_texts()  # all the text.Text instance in the legend
429     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
430     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
431     frame.set_facecolor('0.80')      # set the frame face color to light gray
432     frame.set_alpha(0.5)             # set alpha low to see through
433     setp(ltext, fontsize='small')    # the legend text fontsize
434     setp(llines, linewidth=1.5)      # the legend linewidth
435     # leg.draw_frame(False)           # don't draw the legend frame
436     
437     #######################################
438     #
439     ax = fig.add_subplot(4,1,2)
440     axs.append(ax)
441
442     # ax.plot returns a list of lines, so unpack tuple
443     if have_press:
444         (x, y) = procutil.addnan(dt2, pwl2)
445         l1, = ax.plot_date(x, y, fmt='b-')
446         l1.set_label('Derived from pressure')
447         ls1 = l1.get_label()
448     if have_sontek:
449         (x, y) = procutil.addnan(dt2, swl2)
450         l2, = ax.plot_date(x, y, fmt='c-')
451         l2.set_label('From Acoustic Sounding')   
452         ls2 = l2.get_label()
453    
454     ax.set_ylabel('Depth (ft)')
455     # ax.set_ylim(0,15)
456     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
457     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
458     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
459     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
460     ax.set_xticklabels([])
461
462     # right-hand side scale
463     ax2 = twinx(ax)
464     ax2.yaxis.tick_right()
465     # convert (lhs) feet to (rhs) meters
466     f = [procutil.feet2meters(val) for val in ax.get_ylim()]
467     ax2.set_ylim(f)
468     ax2.set_ylabel('Depth (m)')
469     ax2.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
470     ax2.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
471     ax2.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
472     ax2.set_xticklabels([])
473
474     # legend
475     if have_press and have_sontek:
476         leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left')
477     elif have_press:
478         leg = ax.legend((l1,), (ls1,), loc='upper left')
479     elif have_sontek:
480         leg = ax.legend((l2,), (ls2,), loc='upper left')
481        
482     ltext  = leg.get_texts()  # all the text.Text instance in the legend
483     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
484     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
485     frame.set_facecolor('0.80')      # set the frame face color to light gray
486     frame.set_alpha(0.5)             # set alpha low to see through
487     setp(ltext, fontsize='small')    # the legend text fontsize
488     setp(llines, linewidth=1.5)      # the legend linewidth
489     # leg.draw_frame(False)           # don't draw the legend frame
490     
491     #######################################
492     #
493     ax = fig.add_subplot(4,1,3)
494     axs.append(ax)
495    
496     # ax.plot returns a list of lines, so unpack tuple
497     if have_press:
498         (x, y) = procutil.addnan(dt2, pfl2)
499         l1, = ax.plot_date(x, y, fmt='b-')
500         l1.set_label('Derived from pressure')
501         ls1 = l1.get_label()
502     if have_sontek:
503         (x, y) = procutil.addnan(dt2, sfl2)
504         l2, = ax.plot_date(x, y, fmt='c-')
505         l2.set_label('Depth-avg Acoustic Profile')   
506         ls2 = l2.get_label()
507    
508     ax.set_ylabel('Flow (cfs)')
509     # ax.set_ylim(0,15)
510     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
511     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
512     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
513     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
514     ax.set_xticklabels([])
515
516     # legend
517     if have_press and have_sontek:
518         leg = ax.legend((l1,l2), (ls1,ls2), loc='upper left')
519     elif have_press:
520         leg = ax.legend((l1,), (ls1,), loc='upper left')
521     elif have_sontek:
522         leg = ax.legend((l2,), (ls2,), loc='upper left')
523        
524     ltext  = leg.get_texts()  # all the text.Text instance in the legend
525     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
526     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
527     frame.set_facecolor('0.80')      # set the frame face color to light gray
528     frame.set_alpha(0.5)             # set alpha low to see through
529     setp(ltext, fontsize='small')    # the legend text fontsize
530     setp(llines, linewidth=1.5)      # the legend linewidth
531     # leg.draw_frame(False)           # don't draw the legend frame
532
533     #######################################
534     #
535     ax = fig.add_subplot(4,1,4)
536     axs.append(ax)
537
538     # ax.plot returns a list of lines, so unpack tuple
539     (x, y) = procutil.addnan(dt, batt)
540     l1, = ax.plot_date(x, y, fmt='b-')
541     l1.set_label('Station Battery')
542    
543     ax.set_ylabel('Battery\n (volts)')
544     # ax.set_ylim(6, 12)
545     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
546     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
547     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
548     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
549
550     ax.set_xlabel('CROW Stream Flow -- ' + yyyy_mm_str)
551
552     # legend
553     ls1 = l1.get_label()
554     leg = ax.legend((l1,), (ls1,), loc='upper left')
555     ltext  = leg.get_texts()  # all the text.Text instance in the legend
556     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
557     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
558     frame.set_facecolor('0.80')      # set the frame face color to light gray
559     frame.set_alpha(0.5)             # set alpha low to see through
560     setp(ltext, fontsize='small')    # the legend text fontsize
561     setp(llines, linewidth=1.5)      # the legend linewidth
562     # leg.draw_frame(False)           # don't draw the legend frame
563     
564     # save figure   
565     ofn = '/home/haines/rayleigh/img/crow/crow_flow_' + yyyy_mm_str + '.png'
566     print '... ... write: %s' % (ofn,)
567     savefig(ofn)
568
569
570
571 #######################################
572 # Last 30 days
573 #######################################
574
575 print ' ... Last 30 days'
576 ax = axs[0]
577 ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1]))
578 ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) )
579 ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) )
580 ax.set_xticklabels([])
581 ax.set_xlabel('CROW Stream Flow -- Last 30 days from ' + last_dt_str)
582
583 ax = axs[1]
584 ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1]))
585 ax.xaxis.set_major_locator( DayLocator(range(2,32,1)) )
586 ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) )
587 ax.set_xticklabels([])
588
589 ax = axs[2]
590 ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1]))
591 ax.xaxis.set_major_locator( DayLocator(range(2,32,1)) )
592 ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) )
593 ax.set_xticklabels([])
594
595 ax = axs[3]
596 ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1]))
597 ax.xaxis.set_major_locator( DayLocator(range(2,32,1)) )
598 ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) )
599 ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
600 ax.set_xlabel('CROW Stream Flow -- Last 7 days from ' + last_dt_str)
601
602 # save figure
603 savefig('/home/haines/rayleigh/img/crow_flow_last30days.png')
604
605 #######################################
606 # Last 7 days
607 #######################################
608
609 print ' ... Last 7 days'
610 ax = axs[0]
611 ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1]))
612 ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) )
613 ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) )
614 ax.set_xticklabels([])
615 ax.set_xlabel('CROW Stream Flow -- Last 7 days from ' + last_dt_str)
616
617 ax = axs[1]
618 ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1]))
619 ax.xaxis.set_major_locator( DayLocator(range(2,32,1)) )
620 ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) )
621 ax.set_xticklabels([])
622
623 ax = axs[2]
624 ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1]))
625 ax.xaxis.set_major_locator( DayLocator(range(2,32,1)) )
626 ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) )
627 ax.set_xticklabels([])
628
629 ax = axs[3]
630 ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1]))
631 ax.xaxis.set_major_locator( DayLocator(range(2,32,1)) )
632 ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) )
633 ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
634 ax.set_xlabel('CROW Stream Flow -- Last 7 days from ' + last_dt_str)
635
636 savefig('/home/haines/rayleigh/img/crow_flow_last07days.png')
637
638 #######################################
639 # Last 1 day (24hrs)
640 #######################################
641
642 print ' ... Last 1 days'
643
644 ax = axs[0]
645 ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1]))
646 ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) )
647 ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) )
648 ax.set_xticklabels([])
649 ax.set_xlabel('CROW Stream Flow -- Last 24 hours from ' + last_dt_str)
650
651 ax = axs[1]
652 ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1]))
653 ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) )
654 ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) )
655 ax.set_xticklabels([])
656
657 ax = axs[2]
658 ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1]))
659 ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) )
660 ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) )
661 ax.set_xticklabels([])
662
663 ax = axs[3]
664 ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1]))
665 ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) )
666 ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) )
667 ax.xaxis.set_major_formatter( DateFormatter('%H') )
668 ax.set_xlabel('CROW Stream Flow -- Last 24 hours from ' + last_dt_str)
669
670 savefig('/home/haines/rayleigh/img/crow_flow_last01days.png')
Note: See TracBrowser for help on using the browser.