1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
"""XXXX_YYYY_plot""" |
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
import os |
---|
15 |
|
---|
16 |
import datetime, time, dateutil, dateutil.tz |
---|
17 |
import pycdf |
---|
18 |
import numpy |
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 |
os.environ["MPLCONFIGDIR"]="/home/haines/.matplotlib/" |
---|
24 |
|
---|
25 |
from pylab import figure, twinx, savefig, setp, getp, cm, colorbar |
---|
26 |
from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, DateFormatter, date2num, num2date |
---|
27 |
import procutil |
---|
28 |
|
---|
29 |
def timeseries(pi, si, yyyy_mm, plot_type='latest'): |
---|
30 |
""" |
---|
31 |
""" |
---|
32 |
|
---|
33 |
|
---|
34 |
print 'XXXX_YYYY_plot ...' |
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 |
prev_month, this_month, next_month = procutil.find_months(yyyy_mm) |
---|
39 |
yyyy_mm_str = this_month.strftime('%Y_%m') |
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
ncFile1='/seacoos/data/nccoos/level1/XXXX/YYYY/XXXX_YYYY_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
46 |
ncFile2='/seacoos/data/nccoos/level1/XXXX/YYYY/XXXX_YYYY_'+this_month.strftime('%Y_%m')+'.nc' |
---|
47 |
|
---|
48 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
49 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
50 |
|
---|
51 |
print ' ... loading data for graph from ...' |
---|
52 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
53 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
54 |
|
---|
55 |
|
---|
56 |
if have_ncFile1 and have_ncFile2: |
---|
57 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
58 |
elif not have_ncFile1 and have_ncFile2: |
---|
59 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
60 |
elif have_ncFile1 and not have_ncFile2: |
---|
61 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
62 |
else: |
---|
63 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
64 |
return |
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 |
es = nc.var('time')[:] |
---|
69 |
units = nc.var('time').units |
---|
70 |
dt = [procutil.es2dt(e) for e in es] |
---|
71 |
|
---|
72 |
dt = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt] |
---|
73 |
|
---|
74 |
dt_local = [e.astimezone(dateutil.tz.tzlocal()) for e in dt] |
---|
75 |
dn = date2num(dt) |
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 |
nc.close() |
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 |
ncFile1='/seacoos/data/nccoos/level1/XXXX/flow/XXXX_flow_'+prev_month.strftime('%Y_%m')+'.nc' |
---|
93 |
ncFile2='/seacoos/data/nccoos/level1/XXXX/flow/XXXX_flow_'+this_month.strftime('%Y_%m')+'.nc' |
---|
94 |
|
---|
95 |
have_ncFile1 = os.path.exists(ncFile1) |
---|
96 |
have_ncFile2 = os.path.exists(ncFile2) |
---|
97 |
|
---|
98 |
print ' ... loading data for graph from ...' |
---|
99 |
print ' ... ... ' + ncFile1 + ' ... ' + str(have_ncFile1) |
---|
100 |
print ' ... ... ' + ncFile2 + ' ... ' + str(have_ncFile2) |
---|
101 |
|
---|
102 |
|
---|
103 |
if have_ncFile1 and have_ncFile2: |
---|
104 |
nc = pycdf.CDFMF((ncFile1, ncFile2)) |
---|
105 |
elif not have_ncFile1 and have_ncFile2: |
---|
106 |
nc = pycdf.CDFMF((ncFile2,)) |
---|
107 |
elif have_ncFile1 and not have_ncFile2: |
---|
108 |
nc = pycdf.CDFMF((ncFile1,)) |
---|
109 |
else: |
---|
110 |
print ' ... both files do not exist -- NO DATA LOADED' |
---|
111 |
return |
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 |
es2 = nc.var('time')[:] |
---|
116 |
units = nc.var('time').units |
---|
117 |
dt2 = [procutil.es2dt(e) for e in es2] |
---|
118 |
|
---|
119 |
dt2 = [e.replace(tzinfo=dateutil.tz.tzutc()) for e in dt2] |
---|
120 |
dn2 = date2num(dt2) |
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 |
nc.close() |
---|
128 |
|
---|
129 |
|
---|
130 |
dtu = dt[-1] |
---|
131 |
dtl = dt_local[-1] |
---|
132 |
|
---|
133 |
diff = abs(dtu - dtl) |
---|
134 |
if diff.days>0: |
---|
135 |
last_dt_str = dtu.strftime("%H:%M %Z on %b %d, %Y") + ' (' + dtl.strftime("%H:%M %Z, %b %d") + ')' |
---|
136 |
else: |
---|
137 |
last_dt_str = dtu.strftime("%H:%M %Z") + ' (' + dtl.strftime("%H:%M %Z") + ')' \ |
---|
138 |
+ dtl.strftime(" on %b %d, %Y") |
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 |
ofn = '/home/haines/rayleigh/img/XXXX/XXXX_YYYY_'+yyyy_mm_str+'.png' |
---|
147 |
print '... ... write: %s' % (ofn,) |
---|
148 |
savefig(ofn) |
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 |
if plot_type=='latest': |
---|
155 |
print ' ... Last 30 days' |
---|
156 |
for idx, ax in enumerate(axs): |
---|
157 |
ax.set_xlim(date2num(dt[-1])-30, date2num(dt[-1])) |
---|
158 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
159 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
160 |
ax.set_xticklabels([]) |
---|
161 |
if idx==0: |
---|
162 |
ax.set_xlabel('XXXX ZZZZ -- Last 30 days from ' + last_dt_str) |
---|
163 |
elif idx==len(axs)-1: |
---|
164 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
165 |
ax.set_xlabel('XXXX ZZZZ -- Last 30 days from ' + last_dt_str) |
---|
166 |
|
---|
167 |
savefig('/home/haines/rayleigh/img/XXXX_YYYY_last30days.png') |
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 |
if plot_type=='latest': |
---|
174 |
print ' ... Last 7 days' |
---|
175 |
for idx, ax in enumerate(axs): |
---|
176 |
ax.set_xlim(date2num(dt[-1])-7, date2num(dt[-1])) |
---|
177 |
ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) ) |
---|
178 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
179 |
ax.set_xticklabels([]) |
---|
180 |
if idx==0: |
---|
181 |
ax.set_xlabel('XXXX ZZZZ -- Last 7 days from ' + last_dt_str) |
---|
182 |
elif idx==len(axs)-1: |
---|
183 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
184 |
ax.set_xlabel('XXXX ZZZZ -- Last 7 days from ' + last_dt_str) |
---|
185 |
|
---|
186 |
savefig('/home/haines/rayleigh/img/XXXX_YYYY_last07days.png') |
---|
187 |
|
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 |
if plot_type=='latest': |
---|
193 |
print ' ... Last 1 days' |
---|
194 |
|
---|
195 |
for idx, ax in enumerate(axs): |
---|
196 |
ax.set_xlim(date2num(dt[-1])-1, date2num(dt[-1])) |
---|
197 |
ax.xaxis.set_major_locator( DayLocator(range(0,32,1)) ) |
---|
198 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,6)) ) |
---|
199 |
ax.set_xticklabels([]) |
---|
200 |
if idx==0: |
---|
201 |
ax.set_xlabel('XXXX ZZZZ -- Last 24 hours from ' + last_dt_str) |
---|
202 |
elif idx==len(axs)-1: |
---|
203 |
ax.xaxis.set_major_formatter( DateFormatter('%m/%d') ) |
---|
204 |
ax.set_xlabel('XXXX ZZZZ -- Last 24 hours from ' + last_dt_str) |
---|
205 |
|
---|
206 |
savefig('/home/haines/rayleigh/img/XXXX_YYYY_last01days.png') |
---|
207 |
|
---|
208 |
|
---|
209 |
|
---|
210 |
|
---|