1 |
|
---|
2 |
|
---|
3 |
"""jpier_met_plot2""" |
---|
4 |
|
---|
5 |
import os, sys |
---|
6 |
import datetime, time, 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 'jpier_met_plot2 ...' |
---|
20 |
prev_month, this_month, next_month = procutil.find_months(procutil.this_month()) |
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 |
ncFile1='/seacoos/data/nccoos/level1/jpier/met/jpier_met_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
25 |
ncFile2='/seacoos/data/nccoos/level1/jpier/met/jpier_met_'+this_month.strftime('%Y_%m')+'.nc' |
---|
26 |
|
---|
27 |
|
---|
28 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
29 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
30 |
|
---|
31 |
print ' ... loading data for graph from ...' |
---|
32 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
33 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
34 |
|
---|
35 |
if have_ncFile1 and have_ncFile2: |
---|
36 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
37 |
elif not have_ncFile1 and have_ncFile2: |
---|
38 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
39 |
elif have_ncFile1 and not have_ncFile2: |
---|
40 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
41 |
else: |
---|
42 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
43 |
exit() |
---|
44 |
|
---|
45 |
ncvars = nc.variables() |
---|
46 |
|
---|
47 |
es = nc.var('time')[:] |
---|
48 |
units = nc.var('time').units |
---|
49 |
dt = [procutil.es2dt(e) for e in es] |
---|
50 |
|
---|
51 |
dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt] |
---|
52 |
|
---|
53 |
dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt] |
---|
54 |
dn = date2num(dt) |
---|
55 |
ws = nc.var('wspd')[:] |
---|
56 |
wd = nc.var('wdir')[:] |
---|
57 |
u = nc.var('wspd')[:] |
---|
58 |
v = nc.var('wspd')[:] |
---|
59 |
|
---|
60 |
i = 0 |
---|
61 |
for val in ws: |
---|
62 |
u[i] = -1.*procutil.wind_vector2u(ws[i],wd[i]) |
---|
63 |
v[i] = -1.*procutil.wind_vector2v(ws[i],wd[i]) |
---|
64 |
i += 1 |
---|
65 |
nc.close() |
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|
69 |
dt1 = dt[-1] |
---|
70 |
dt2 = dt_local[-1] |
---|
71 |
|
---|
72 |
diff = abs(dt1 - dt2) |
---|
73 |
if diff.days>0: |
---|
74 |
last_dt_str = dt1.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dt2.strftime("%H:%M %Z, %b %d") + ')' |
---|
75 |
else: |
---|
76 |
last_dt_str = dt1.strftime("%H:%M %Z") + ' (' + dt2.strftime("%H:%M %Z") + ')' \ |
---|
77 |
+ dt2.strftime(" on %b %d, %Y") |
---|
78 |
|
---|
79 |
fig = figure(figsize=(10, 8)) |
---|
80 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.1, hspace=0.1) |
---|
81 |
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 |
print ' ... Last 30 days' |
---|
86 |
|
---|
87 |
ax = fig.add_subplot(4,1,1) |
---|
88 |
axs = [ax] |
---|
89 |
|
---|
90 |
|
---|
91 |
wd = numpy.ma.masked_where(numpy.isnan(wd), wd) |
---|
92 |
|
---|
93 |
|
---|
94 |
l1, = ax.plot_date(dt, wd, fmt='b-') |
---|
95 |
l1.set_label('Wind from Direction') |
---|
96 |
|
---|
97 |
ax.set_ylabel('Dir (true N)') |
---|
98 |
ax.set_ylim(0.,360.) |
---|
99 |
|
---|
100 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
101 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
102 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
103 |
ax.set_xticklabels([]) |
---|
104 |
|
---|
105 |
|
---|
106 |
ax.xaxis.set_label_position('top') |
---|
107 |
ax.set_xlabel('JPIER Met -- Last 30 days from ' + last_dt_str) |
---|
108 |
|
---|
109 |
|
---|
110 |
ls1 = l1.get_label() |
---|
111 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
112 |
ltext = leg.get_texts() |
---|
113 |
llines = leg.get_lines() |
---|
114 |
frame = leg.get_frame() |
---|
115 |
frame.set_facecolor('0.80') |
---|
116 |
frame.set_alpha(0.5) |
---|
117 |
setp(ltext, fontsize='small') |
---|
118 |
setp(llines, linewidth=1.5) |
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|
123 |
ax = fig.add_subplot(4,1,2) |
---|
124 |
axs.append(ax) |
---|
125 |
|
---|
126 |
|
---|
127 |
ws = numpy.ma.masked_where(numpy.isnan(ws), ws) |
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 |
l1, = ax.plot_date(dt, ws, fmt='b-') |
---|
132 |
l1.set_label('Wind Speed') |
---|
133 |
|
---|
134 |
|
---|
135 |
ax.set_ylabel('Speed (m/s)') |
---|
136 |
ax.set_ylim(0.,20.) |
---|
137 |
|
---|
138 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
139 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
140 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
141 |
ax.set_xticklabels([]) |
---|
142 |
|
---|
143 |
|
---|
144 |
ax2 = twinx(ax) |
---|
145 |
ax2.yaxis.tick_right() |
---|
146 |
|
---|
147 |
k = [procutil.meters_sec2knots(val) for val in ax.get_ylim()] |
---|
148 |
ax2.set_ylim(k) |
---|
149 |
ax2.set_ylabel('Speed (knots)') |
---|
150 |
|
---|
151 |
|
---|
152 |
ls1 = l1.get_label() |
---|
153 |
leg = ax.legend((l1,), (ls1,), loc='upper left') |
---|
154 |
ltext = leg.get_texts() |
---|
155 |
llines = leg.get_lines() |
---|
156 |
frame = leg.get_frame() |
---|
157 |
frame.set_facecolor('0.80') |
---|
158 |
frame.set_alpha(0.5) |
---|
159 |
setp(ltext, fontsize='small') |
---|
160 |
setp(llines, linewidth=1.5) |
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|
165 |
ax = fig.add_subplot(4,1,3) |
---|
166 |
axs.append(ax) |
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 |
dt0 = numpy.zeros(len(dt)) |
---|
173 |
|
---|
174 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
175 |
ax.axhline(y=0, color='gray') |
---|
176 |
|
---|
177 |
|
---|
178 |
q1 = ax.quiver(date2num(dt), dt0, u, v, units='height', scale=40, headwidth=0, headlength=0, headaxislength=0) |
---|
179 |
qk = ax.quiverkey(q1, 0.1, 0.8, 10, r'10 m s-1') |
---|
180 |
|
---|
181 |
ax.set_ylim(-20.,20.) |
---|
182 |
ax.set_ylabel('Speed (m/s)') |
---|
183 |
|
---|
184 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
185 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
186 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
187 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
188 |
|
---|
189 |
|
---|
190 |
ax2 = twinx(ax) |
---|
191 |
ax2.yaxis.tick_right() |
---|
192 |
|
---|
193 |
k = [(val * 1.94384449) for val in ax.get_ylim()] |
---|
194 |
ax2.set_ylim(k) |
---|
195 |
ax2.set_ylabel('Speed (knots)') |
---|
196 |
|
---|
197 |
ax.set_xlabel('JPIER Met -- Last 30 days from ' + last_dt_str) |
---|
198 |
|
---|
199 |
|
---|
200 |
savefig('/home/haines/rayleigh/img/jpier_met2_last30days.png') |
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 |
print ' ... Last 7 days' |
---|
207 |
ax = axs[0] |
---|
208 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
209 |
ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) ) |
---|
210 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
211 |
ax.set_xticklabels([]) |
---|
212 |
ax.set_xlabel('JPIER Met -- Last 7 days from ' + last_dt_str) |
---|
213 |
|
---|
214 |
ax = axs[1] |
---|
215 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
216 |
ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) ) |
---|
217 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
218 |
ax.set_xticklabels([]) |
---|
219 |
|
---|
220 |
ax = axs[2] |
---|
221 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
222 |
ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) ) |
---|
223 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
224 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
225 |
ax.set_xlabel('JPIER Met -- Last 7 days from ' + last_dt_str) |
---|
226 |
|
---|
227 |
savefig('/home/haines/rayleigh/img/jpier_met2_last07days.png') |
---|
228 |
|
---|
229 |
|
---|
230 |
|
---|
231 |
|
---|
232 |
|
---|
233 |
print ' ... Last 1 days' |
---|
234 |
|
---|
235 |
ax = axs[0] |
---|
236 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
237 |
ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) ) |
---|
238 |
ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) ) |
---|
239 |
ax.set_xticklabels([]) |
---|
240 |
ax.set_xlabel('JPIER Met -- Last 24 hours from ' + last_dt_str) |
---|
241 |
|
---|
242 |
ax = axs[1] |
---|
243 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
244 |
ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) ) |
---|
245 |
ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) ) |
---|
246 |
ax.set_xticklabels([]) |
---|
247 |
|
---|
248 |
ax = axs[2] |
---|
249 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
250 |
ax.xaxis.set_major_locator( HourLocator(range(0,25,1)) ) |
---|
251 |
ax.xaxis.set_minor_locator( MinuteLocator(range(0,61,30)) ) |
---|
252 |
ax.xaxis.set_major_formatter( DateFormatter('%H') ) |
---|
253 |
ax.set_xlabel('JPIER Met -- Last 24 hours from ' + last_dt_str) |
---|
254 |
|
---|
255 |
savefig('/home/haines/rayleigh/img/jpier_met2_last01days.png') |
---|
256 |
|
---|