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

root/proc2plot/trunk/proc2plot/spin/spin_df_sodar2_plot_month.py

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

import first verison proc2plot

  • Property svn:executable set to
Line 
1 #!/usr/bin/env python
2 # Last modified:  Time-stamp: <2008-12-05 12:39:39 haines>
3 """dukeforest_sodar_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('/home/haines/nccoos/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 'dukeforest_sodar2_plot_month ...'
22
23 proc_dir = '/seacoos/data/nccoos/level1/dukeforest/sodar/'
24 fns = glob.glob((os.path.join(proc_dir, '*.nc')))
25 fns.sort()
26
27 for fn in fns:
28     m=re.search('\d{4}_\d{2}', fn)
29     yyyy_mm = m.group()
30     prev_month, this_month, next_month = procutil.find_months(yyyy_mm)
31    
32     # load data
33     print ' ... ... read: ' + fn
34     nc = pycdf.CDFMF((fn,))
35     ncvars = nc.variables()
36     # print ncvars
37     es = nc.var('time')[:]
38     units = nc.var('time').units
39     dt = [procutil.es2dt(e) for e in es]
40     # set timezone info to UTC (since data from level1 should be in UTC!!)
41     dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt]
42     # return new datetime based on computer local
43     dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt]
44     dn = date2num(dt)
45    
46     z = nc.var('z')[:]
47    
48     val1 = nc.var('val1')[:]
49     val2 = nc.var('val2')[:]
50     val3 = nc.var('val3')[:]
51    
52     spu1 = nc.var('spu1')[:]
53     spu2 = nc.var('spu2')[:]
54     spu3 = nc.var('spu3')[:]
55    
56     n1 = numpy.floor(nc.var('nois1')[:]/10.)
57     n2 = numpy.floor(nc.var('nois2')[:]/10.)
58     n3 = numpy.floor(nc.var('nois3')[:]/10.)
59    
60     s1 = numpy.floor(nc.var('snr1')[:]/10.)
61     s2 = numpy.floor(nc.var('snr2')[:]/10.)
62     s3 = numpy.floor(nc.var('snr3')[:]/10.)
63    
64     r1 = 10.*(nc.var('snr1')[:]-10.*s1)
65     r2 = 10.*(nc.var('snr2')[:]-10.*s2)
66     r3 = 10.*(nc.var('snr3')[:]-10.*s3)
67    
68     fe11 = nc.var('fe11')[:]
69     fe12 = nc.var('fe12')[:]
70     fe21 = nc.var('fe21')[:]
71     fe22 = nc.var('fe22')[:]
72
73     nc.close()
74
75     # last dt in data for labels
76     dt1 = dt[-1]
77     dt2 = dt_local[-1]
78    
79     diff = abs(dt1 - dt2)
80     if diff.days>0:
81         last_dt_str = dt1.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dt2.strftime("%H:%M %Z, %b %d") + ')'
82     else:
83         last_dt_str = dt1.strftime("%H:%M %Z") + ' (' + dt2.strftime("%H:%M %Z") + ')' \
84                       + dt2.strftime(" on %b %d, %Y")
85    
86     fig = figure(figsize=(10, 8))
87     fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1)
88    
89     #######################################
90     # Plot month
91     #######################################
92    
93     ax = fig.add_subplot(6,1,1)
94     axs = [ax]
95    
96     # ax.plot returns a list of lines, so unpack tuple
97     l1, = ax.plot_date(dt, val1, fmt='b-')
98     l1.set_label('val1 per beam')
99     l2, = ax.plot_date(dt, val2, fmt='c-')
100     l2.set_label('val2')   
101     l3, = ax.plot_date(dt, val3, fmt='g-')
102     l3.set_label('val3')
103    
104     ax.set_ylabel('Validations')
105     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
106     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
107     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
108     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
109     ax.set_xticklabels([])
110
111     # this only moves the label not the tick labels
112     ax.xaxis.set_label_position('top')
113     ax.set_xlabel('DUKEFOREST SODAR -- ' + yyyy_mm)
114    
115     # legend
116     ls1 = l1.get_label()
117     ls2 = l2.get_label()
118     ls3 = l3.get_label()
119     leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left')
120     ltext  = leg.get_texts()  # all the text.Text instance in the legend
121     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
122     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
123     frame.set_facecolor('0.80')      # set the frame face color to light gray
124     frame.set_alpha(0.5)             # set alpha low to see through
125     setp(ltext, fontsize='small')    # the legend text fontsize
126     setp(llines, linewidth=1.5)      # the legend linewidth
127     # leg.draw_frame(False)           # don't draw the legend frame
128    
129     #######################################
130     #
131     ax = fig.add_subplot(6,1,2)
132     axs.append(ax)
133
134     # ax.plot returns a list of lines, so unpack tuple
135     l1, = ax.plot_date(dt, spu1, fmt='b-')
136     l1.set_label('spu1 (<=3 OK)')
137     l2, = ax.plot_date(dt, spu2, fmt='c-')
138     l2.set_label('spu2')   
139     l3, = ax.plot_date(dt, spu3, fmt='g-')
140     l3.set_label('spu3')
141    
142     ax.set_ylabel('False\n Signal')
143     ax.set_ylim(0,10)
144     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
145     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
146     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
147     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
148     ax.set_xticklabels([])
149
150     # legend
151     ls1 = l1.get_label()
152     ls2 = l2.get_label()
153     ls3 = l3.get_label()
154     leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left')
155     ltext  = leg.get_texts()  # all the text.Text instance in the legend
156     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
157     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
158     frame.set_facecolor('0.80')      # set the frame face color to light gray
159     frame.set_alpha(0.5)             # set alpha low to see through
160     setp(ltext, fontsize='small')    # the legend text fontsize
161     setp(llines, linewidth=1.5)      # the legend linewidth
162     # leg.draw_frame(False)           # don't draw the legend frame
163    
164     #######################################
165     #
166     ax = fig.add_subplot(6,1,3)
167     axs.append(ax)
168        
169     # ax.plot returns a list of lines, so unpack tuple
170     l1, = ax.plot_date(dt, n1, fmt='b-')
171     l1.set_label('n1')
172     l2, = ax.plot_date(dt, n2, fmt='c-')
173     l2.set_label('n2')   
174     l3, = ax.plot_date(dt, n3, fmt='g-')
175     l3.set_label('n3')
176    
177     ax.set_ylabel('Ambient\n Noise')
178     ax.set_ylim(20,80)
179     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
180     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
181     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
182     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
183     ax.set_xticklabels([])
184
185     # legend
186     ls1 = l1.get_label()
187     ls2 = l2.get_label()
188     ls3 = l3.get_label()
189     leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), 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     ax = fig.add_subplot(6,1,4)
201     axs.append(ax)
202
203     # ax.plot returns a list of lines, so unpack tuple
204     l1, = ax.plot_date(dt, s1, fmt='b-')
205     l1.set_label('s1 SNR')
206     l2, = ax.plot_date(dt, s2, fmt='c-')
207     l2.set_label('s2')   
208     l3, = ax.plot_date(dt, s3, fmt='g-')
209     l3.set_label('s3')
210    
211     ax.set_ylabel('Signal to \nNoise')
212     ax.set_ylim(6, 10)
213     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
214     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
215     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
216     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
217     ax.set_xticklabels([])
218
219     # legend
220     ls1 = l1.get_label()
221     ls2 = l2.get_label()
222     ls3 = l3.get_label()
223     leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left')
224     ltext  = leg.get_texts()  # all the text.Text instance in the legend
225     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
226     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
227     frame.set_facecolor('0.80')      # set the frame face color to light gray
228     frame.set_alpha(0.5)             # set alpha low to see through
229     setp(ltext, fontsize='small')    # the legend text fontsize
230     setp(llines, linewidth=1.5)      # the legend linewidth
231     # leg.draw_frame(False)           # don't draw the legend frame
232    
233     #######################################
234     #
235     ax = fig.add_subplot(6,1,5)
236     axs.append(ax)
237    
238     # ax.plot returns a list of lines, so unpack tuple
239     l1, = ax.plot_date(dt, r1, fmt='b-')
240     l1.set_label('BW1 (<50% bad)')
241     l2, = ax.plot_date(dt, r2, fmt='c-')
242     l2.set_label('BW2')   
243     l3, = ax.plot_date(dt, r3, fmt='g-')
244     l3.set_label('BW3')
245    
246     ax.set_ylabel('Percent\n Total\n Bandwidth')
247     ax.set_ylim(0,100)
248     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
249     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
250     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
251     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
252     ax.set_xticklabels([])
253
254     # legend
255     ls1 = l1.get_label()
256     ls2 = l2.get_label()
257     ls3 = l3.get_label()
258     leg = ax.legend((l1,l2,l3), (ls1,ls2,ls3), loc='upper left')
259     ltext  = leg.get_texts()  # all the text.Text instance in the legend
260     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
261     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
262     frame.set_facecolor('0.80')      # set the frame face color to light gray
263     frame.set_alpha(0.5)             # set alpha low to see through
264     setp(ltext, fontsize='small')    # the legend text fontsize
265     setp(llines, linewidth=1.5)      # the legend linewidth
266     # leg.draw_frame(False)           # don't draw the legend frame
267    
268     #######################################
269     #
270     ax = fig.add_subplot(6,1,6)
271     axs.append(ax)
272    
273         # ax.plot returns a list of lines, so unpack tuple
274     l1, = ax.plot_date(dt, fe11, fmt='b-')
275     l1.set_label('fe11 (9 max)')
276     l2, = ax.plot_date(dt, fe12, fmt='c-')
277     l2.set_label('fe12')   
278     l3, = ax.plot_date(dt, fe21, fmt='g-')
279     l3.set_label('fe21')
280     l4, = ax.plot_date(dt, fe22, fmt='k-')
281     l4.set_label('fe22')
282    
283     ax.set_ylabel('Number of \nfreq emitted')
284     ax.set_ylim(0,10)
285     ax.set_xlim(date2num(this_month), date2num(next_month-datetime.timedelta(seconds=1)))
286     ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) )
287     ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) )
288     ax.xaxis.set_major_formatter( DateFormatter('%m/%d') )
289
290     ax.set_xlabel('DUKEFOREST SODAR -- ' + yyyy_mm)
291
292     # legend
293     ls1 = l1.get_label()
294     ls2 = l2.get_label()
295     ls3 = l3.get_label()
296     ls4 = l4.get_label()
297     leg = ax.legend((l1,l2,l3,l4), (ls1,ls2,ls3,ls4), loc='upper left')
298     ltext  = leg.get_texts()  # all the text.Text instance in the legend
299     llines = leg.get_lines()  # all the lines.Line2D instance in the legend
300     frame  = leg.get_frame()  # the patch.Rectangle instance surrounding the legend
301     frame.set_facecolor('0.80')      # set the frame face color to light gray
302     frame.set_alpha(0.5)             # set alpha low to see through
303     setp(ltext, fontsize='small')    # the legend text fontsize
304     setp(llines, linewidth=1.5)      # the legend linewidth
305     # leg.draw_frame(False)           # don't draw the legend frame
306
307     # save figure
308    
309     ofn = '/home/haines/rayleigh/img/dukeforest/dukeforest_sodar2_'+yyyy_mm+'.png'
310     print '... ... write: %s' % (ofn,)
311     savefig(ofn)
312
Note: See TracBrowser for help on using the browser.