app_hi_eq.html


001| from sys import argv, stdout, stderr, exc_info
002| from traceback import extract_tb
003| from os import path
004| from datetime import date, time, datetime, timedelta
005| from dates import UTC, CST, HST
006| from logger import logger, info, debug, trace
007| from PIL import Image
008| import numpy as np
009| import matplotlib.pyplot as plt
010| from matplotlib.ticker import NullLocator, MultipleLocator, NullFormatter, FormatStrFormatter
011| from matplotlib.dates import DayLocator, WeekdayLocator, MonthLocator, DateFormatter
012| from matplotlib.dates import SU, MO, TU, WE, TH, FR, SA
013| from mpl_toolkits.mplot3d import Axes3D
014| from db_hi_eq import BasePath, HtmlPath, Db2Date, Db2Str1, dbEarthquakeTable
015| from sql_store import SQL
016| ####################################################################################################
017| Log = logger('APP')
018| 
019| MonthStartDay = [None, MO, TH, TH, SU, TU, FR, SU, WE, SA, MO, TH, SA]
020| 
021| StartDate  = datetime(2018,4,28)
022| CutoffDate = datetime(2018,8,31)
023| 
024| Coords = {
025|     'kilauea': [-155.283000, +19.406000, -1.247],
026|     'puuoo':   [-155.105000, +19.388000, -0.700],
027|     'fissure8':[-154.910500, +19.461052, -0.230],
028|     'muanaloa':[-155.602778, +19.479444, -4.169],
029|     'maunakea':[-155.468066, +19.820664, -4.207],
030|     'loihi':   [-155.270000, +18.920000, +0.975, +3.975],
031| }
032| 
033| Colors ={   'M1':'#000000'
034| ,   'M2':'#0000df'
035| ,   'M3':'#009f00'
036| ,   'M4':'#ff9f3f'
037| ,   'M5':'#ff0000'
038| ,   'M6':'#bf00bf'
039| }
040| 
041| ##================================================================================================##
042| def vertical_labels (ax):
043|     for tick in ax.xaxis.get_major_ticks():
044|         tick.label1.set_rotation('vertical')
045|         tick.label1.set_size(9)
046| 
047| 
048| ##================================================================================================##
049| def chart_intervals (*args):
050|     Log.info('chart-intervals: %s' % str(args))
051|     fname = args[0] if 0 < len(args) else 'pele1.png'
052|     start = args[1] if 1 < len(args) else '6'
053|     sql = SQL['chart.intervals']
054|     # Query database for data...
055|     tbl = dbEarthquakeTable()
056|     rs = tbl.db_query(sql % tbl.name)
057|     if not rs: Log.warn('No data!'); return 'No Data!'
058|     # Process data...
059|     start = int(start)
060|     data = []
061|     prev_ts = None
062|     for r in rs[start:]:
063|         ts = Db2Date(r[0])
064|         if prev_ts:
065|             td = ts - prev_ts
066|             hrs = (float(td.days) * 24.0) + (float(td.seconds) / 3600.0)
067|             data.append(hrs)
068|         prev_ts = ts
069| 
070|     n = len(data)
071|     avg = np.mean(data)
072|     std = np.std(data)
073|     xmin, xmax = 0, n+1
074|     ymin, ymax = 12.0, 54.0
075|     wdw = 7
076| 
077|     xs = [x+1 for x in range(n)]
078|     ras = [float(sum(data[ix-wdw:ix]))/float(wdw) for ix in range(wdw,n+1)]
079|     rxs = xs[wdw-1:]
080| 
081|     fig, ax = plt.subplots()
082|     fig.suptitle('Kilauea 5.0+ Event Intervals (last %d events)' % n)
083|     ax.set_xlabel('5.0+ Events')
084|     ax.set_ylabel('Hours Between Events')
085|     ax.minorticks_on()
086| 
087|     ax.set_xlim(xmin, xmax)
088|     ax.xaxis.set_major_locator(MultipleLocator(5))
089|     ax.xaxis.set_minor_locator(MultipleLocator(1))
090|     ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
091| 
092|     ax.set_ylim(ymin, ymax)
093|     ax.yaxis.set_major_locator(MultipleLocator(6))
094|     ax.yaxis.set_minor_locator(MultipleLocator(1))
095|     ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
096| 
097|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
098|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=2, alpha=1.0)
099|     ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
100|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
101| 
102|     b1 = 'Hours preceding Event'
103|     b2 = '%d-event Rolling Avg' % wdw
104|     b3 = 'Stddev [%d:%02d] (all events)' % (int(std), int(60*(std-int(std))))
105|     b4 = 'Mean [%d:%02d] (all events)' % (int(avg), int(60*(avg-int(avg))))
106|     ax.plot(xs,data, color='#0000ff', label=b1, lw=1.0, marker='o', ms=5, alpha=1.0, zorder=8)
107|     ax.plot(rxs,ras, color='#ff0000', label=b2, lw=3.2, marker='o', ms=0, alpha=1.0, zorder=9)
108|     ax.axhspan(avg+std,avg-std, color='#ffff00', label=b3, lw=1.0, alpha=0.40, zorder=5)
109|     ax.axhline(avg, color='k', label=b4, lw=2.5, alpha=1.0, zorder=6)
110|     ax.legend(loc='upper center', bbox_to_anchor=(0.33,1.00), shadow=True)
111| 
112|     fig.set_figwidth(6.4)
113|     fig.set_figheight(4.8)
114|     fig.subplots_adjust(left=0.10, bottom=0.12, right=0.97, top=0.90)
115| 
116|     fig.savefig(path.join(HtmlPath,fname))
117|     return 'Done'
118| 
119| ##================================================================================================##
120| def chart_longitude_latitude (*args):
121|     Log.info('chart-longitude-latitude: %s' % str(args))
122|     fname = args[0] if 0 < len(args) else 'pele5.png'
123|     which = args[1] if 1 < len(args) else ''
124|     sql1 = SQL['mag.2']
125|     sql2 = SQL['mag.3']
126|     sql3 = SQL['mag.4']
127|     sql4 = SQL['mag.5']
128|     sql5 = SQL['mag.6+']
129|     dcut = '2018-05'
130|     # Query database for data...
131|     tbl = dbEarthquakeTable()
132|     rs1 = tbl.db_query(sql1 % tbl.name, [dcut])
133|     rs2 = tbl.db_query(sql2 % tbl.name, [dcut])
134|     rs3 = tbl.db_query(sql3 % tbl.name, [dcut])
135|     rs4 = tbl.db_query(sql4 % tbl.name, [dcut])
136|     rs5 = tbl.db_query(sql5 % tbl.name, [dcut])
137|     if not (rs1 and rs2 and rs3 and rs4 and rs5): Log.warn('No data!'); return 'No Data!'
138|     # Process data...
139|     if which == 'small':
140|         xmin, xmax = -155.4, -155.2
141|         ymin, ymax = +19.3, +19.5
142|         maj_tick, min_tick = 0.1, 0.01
143|     elif which == 'tiny':
144|         xmin, xmax = -155.32, -155.24
145|         ymin, ymax = +19.37, +19.45
146|         maj_tick, min_tick = 0.02, 0.005
147|     elif which == 'erz':
148|         xmin, xmax = -155.20, -154.80
149|         ymin, ymax = +19.20, +19.60
150|         maj_tick, min_tick = 0.1, 0.01
151|     else:
152|         xmin, xmax = -156.0, -154.5
153|         ymin, ymax = +18.5, +20.0
154|         maj_tick, min_tick = 0.5, 0.1
155|     xs1,ys1,_,_,_ = zip(*rs1)
156|     xs2,ys2,_,_,_ = zip(*rs2)
157|     xs3,ys3,_,_,_ = zip(*rs3)
158|     xs4,ys4,_,_,_ = zip(*rs4)
159|     xs5,ys5,_,_,_ = zip(*rs5)
160|     xs6,ys6 = zip(*[(x[0],x[1]) for x in Coords.values()])
161| 
162|     fig, ax = plt.subplots()
163|     fig.suptitle('Kilauea Events')
164|     ax.minorticks_on()
165| 
166|     ax.set_xlabel('Longitude')
167|     ax.set_xlim(xmin, xmax)
168|     ax.xaxis.set_major_locator(MultipleLocator(maj_tick))
169|     ax.xaxis.set_minor_locator(MultipleLocator(min_tick))
170|     ax.xaxis.set_major_formatter(FormatStrFormatter('%+.2f'))
171| 
172|     ax.set_ylabel('Latitude')
173|     ax.set_ylim(ymin, ymax)
174|     ax.yaxis.set_major_locator(MultipleLocator(maj_tick))
175|     ax.yaxis.set_minor_locator(MultipleLocator(min_tick))
176|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+.2f'))
177| 
178|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
179|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=2, alpha=1.0)
180|     ax.tick_params(which='major', axis='both', direction='out', color='#000000')
181|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f')
182| 
183|     ax.plot(xs1,ys1, color=Colors['M2'], label='M2.0-M2.9', lw=0, marker='+', ms=4, alpha=0.7, zorder=4)
184|     ax.plot(xs2,ys2, color=Colors['M3'], label='M3.0-M3.9', lw=0, marker='x', ms=4, alpha=0.8, zorder=5)
185|     ax.plot(xs3,ys3, color=Colors['M4'], label='M4.0-M4.9', lw=0, marker='o', ms=4, alpha=1.0, zorder=6)
186|     ax.plot(xs4,ys4, color=Colors['M5'], label='M5.0-M5.9', lw=0, marker='h', ms=6, alpha=1.0, zorder=7)
187|     ax.plot(xs5,ys5, color=Colors['M6'], label='M6.0+'    , lw=0, marker='D', ms=8, alpha=1.0, zorder=8)
188|     ax.plot(xs6,ys6, color='#000000', label='Landmarks', lw=0, marker='^', ms=9, alpha=1.0, zorder=9)
189|     if which == 'erz':
190|         ax.legend(loc='upper left', bbox_to_anchor=(-0.01,+1.01), shadow=True)
191|     else:
192|         ax.legend(loc='lower left', bbox_to_anchor=(-0.01,-0.01), shadow=True)
193| 
194|     #im = Image.open(path.join(HtmlPath,'big-island.jpg'))
195|     #Log.info(im)
196|     #am = ax.imshow(im, aspect='auto', zorder=0)
197|     #Log.info(am)
198| 
199|     fig.set_figwidth(6.4)
200|     fig.set_figheight(6.4)
201|     fig.subplots_adjust(left=0.13, bottom=0.10, right=0.96, top=0.90)
202| 
203|     fig.savefig(path.join(HtmlPath,fname))
204|     return 'Done'
205| 
206| ##================================================================================================##
207| def chart_histo_mag (*args):
208|     Log.info('chart-histo-magnitude: %s' % str(args))
209|     fname = args[0] if 0 < len(args) else 'histo_magnitude.png'
210|     sql = SQL['histo.mag']
211|     # Query database for data...
212|     tbl = dbEarthquakeTable()
213|     rs = tbl.db_query(sql % tbl.name)
214|     if not rs: Log.warn('No data!'); return 'No Data!'
215|     # Process data...
216|     data = {}
217|     for r in rs:
218|         m = ('%.2f' % r[0])[0:-1]
219|         if m not in data: data[m] = 0
220|         data[m] += 1
221|     ks = sorted(data.keys())
222|     ms = [data[m] for m in ks]
223|     ks = [float(m) for m in ks] # Need floating point X values!
224| 
225|     fig, ax = plt.subplots()
226|     fig.suptitle('Kilauea Events Histogram')
227|     ax.set_xlabel('Magnitude')
228|     ax.set_ylabel('# of Events')
229|     ax.set_yscale('log')
230| 
231|     xmin, xmax = 0.9, 7.0
232|     ax.set_xlim(xmin, xmax)
233|     ax.xaxis.set_major_locator(MultipleLocator(0.5))
234|     ax.xaxis.set_minor_locator(MultipleLocator(0.1))
235|     ax.xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
236| 
237|     ax.grid(which='major', axis='both', color='#bfbfbf', lw=1.2,ls='-',zorder=1, alpha=1.0)
238|     ax.grid(which='minor', axis='both', color='#dfdfdf', lw=0.6,ls='-',zorder=0, alpha=1.0)
239|     ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
240|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
241| 
242|     ax.bar(ks,ms, width=0.10, color='#007f00', edgecolor='#000000', alpha=1.0, zorder=8)
243| 
244|     vertical_labels(ax)
245|     fig.set_figwidth(6.4)
246|     fig.set_figheight(3.2)
247|     fig.subplots_adjust(left=0.10, bottom=0.18, right=0.97, top=0.90)
248| 
249|     fig.savefig(path.join(HtmlPath,fname))
250|     return 'Done'
251| 
252| ##================================================================================================##
253| def chart_histo_dep (*args):
254|     Log.info('chart-histo-depth: %s' % str(args))
255|     fname = args[0] if 0 < len(args) else 'histo_depth.png'
256|     sql = SQL['histo.dep']
257|     # Query database for data...
258|     tbl = dbEarthquakeTable()
259|     rs = tbl.db_query(sql % tbl.name)
260|     if not rs: Log.warn('No data!'); return 'No Data!'
261|     # Process data...
262|     data = {}
263|     for r in rs:
264|         m = int(r[0])
265|         if m not in data: data[m] = 0
266|         data[m] += 1
267|     ks = sorted(data.keys())
268|     ms = [data[m] for m in ks]
269| 
270|     fig, ax = plt.subplots()
271|     fig.suptitle('Kilauea Events Histogram')
272|     ax.set_xlabel('Depth (km)')
273|     ax.set_ylabel('# of Events')
274|     ax.set_yscale('log')
275| 
276|     xmin, xmax = -5, 50
277|     ax.set_xlim(xmin, xmax)
278|     ax.xaxis.set_major_locator(MultipleLocator(5))
279|     ax.xaxis.set_minor_locator(MultipleLocator(1))
280|     ax.xaxis.set_major_formatter(FormatStrFormatter('%+d'))
281| 
282|     ax.grid(which='major', axis='both', color='#bfbfbf', lw=1.2,ls='-',zorder=1, alpha=1.0)
283|     ax.grid(which='minor', axis='both', color='#dfdfdf', lw=0.6,ls='-',zorder=0, alpha=1.0)
284|     ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
285|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
286| 
287|     ax.bar(ks,ms, width=1.00, color='#007f00', edgecolor='#000000', alpha=1.0, zorder=8)
288| 
289|     vertical_labels(ax)
290|     fig.set_figwidth(6.4)
291|     fig.set_figheight(3.2)
292|     fig.subplots_adjust(left=0.10, bottom=0.18, right=0.97, top=0.90)
293| 
294|     fig.savefig(path.join(HtmlPath,fname))
295|     return 'Done'
296| 
297| ##================================================================================================##
298| def chart_magnitude_depth (*args):
299|     Log.info('chart-magnitude-depth: %s' % str(args))
300|     fname = args[0] if 0 < len(args) else 'pele4.png'
301|     sql = SQL['chart.4']
302|     # Query database for data...
303|     tbl = dbEarthquakeTable()
304|     rs = tbl.db_query(sql % tbl.name)
305|     if not rs: Log.warn('No data!'); return 'No Data!'
306|     # Process data...
307|     ms,ds = zip(*rs)
308|     xmin, xmax = 2.0, 7.0
309|     ymin, ymax = -4.0, 20.0
310| 
311|     fig, ax = plt.subplots()
312|     fig.suptitle('Kilauea Events')
313|     ax.set_xlabel('Magnitude')
314|     ax.set_ylabel('Depth (km)')
315|     ax.minorticks_on()
316| 
317|     ax.set_xlim(xmin, xmax)
318|     ax.xaxis.set_major_locator(MultipleLocator(0.5))
319|     ax.xaxis.set_minor_locator(MultipleLocator(0.1))
320|     ax.xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
321| 
322|     ax.set_ylim(ymin, ymax)
323|     ax.invert_yaxis()
324|     ax.yaxis.set_major_locator(MultipleLocator(2.0))
325|     ax.yaxis.set_minor_locator(MultipleLocator(1.0))
326|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+.2f'))
327| 
328|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
329|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
330|     ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
331|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
332| 
333|     ax.axhline(0.0, color='k', lw=2.5, alpha=0.5, zorder=6)
334|     ax.plot(ms,ds, color='#ff0000', lw=0, marker='x', ms=4, alpha=1.0, zorder=8)
335| 
336|     fig.set_figwidth(6.4)
337|     fig.set_figheight(4.8)
338|     fig.subplots_adjust(left=0.15, bottom=0.13, right=0.97, top=0.90)
339| 
340|     fig.savefig(path.join(HtmlPath,fname))
341|     return 'Done'
342| 
343| ##================================================================================================##
344| def chart_time_mag (*args):
345|     Log.info('chart-time-magnitude: %s' % str(args))
346|     fname  = args[0] if 0 < len(args) else 'pele2.png'
347|     fr_mon = args[1] if 1 < len(args) else '5'
348|     fr_day = args[2] if 2 < len(args) else '1'
349|     to_mon = args[3] if 3 < len(args) else '8'
350|     to_day = args[4] if 4 < len(args) else '31'
351|     mag_lo = args[5] if 5 < len(args) else '1.0'
352|     dt_fr = datetime(2018, int(fr_mon), int(fr_day))
353|     dt_to = datetime(2018, int(to_mon), int(to_day))
354|     sdt_fr = dt_fr.strftime('%Y-%m-%d')
355|     sdt_to = dt_to.strftime('%Y-%m-%d')
356|     min_mag = float(mag_lo)
357|     sql = SQL['chart.2']
358|     # Query database for data...
359|     tbl = dbEarthquakeTable()
360|     rs = tbl.db_query(sql % tbl.name, [sdt_fr, sdt_to, min_mag])
361|     if not rs: Log.warn('No data!'); return 'No Data!'
362|     # Process data...
363|     dts = [Db2Date(r[0]) for r in rs]
364|     ys1,xs1 = zip(*[(r[1],Db2Date(r[0])) for r in rs if r[2] < 0.0])
365|     ys2,xs2 = zip(*[(r[1],Db2Date(r[0])) for r in rs if 0.0 <= r[2] < 5.0])
366|     ys3,xs3 = zip(*[(r[1],Db2Date(r[0])) for r in rs if 5.0 <= r[2] < 15.0])
367|     ys4,xs4 = zip(*[(r[1],Db2Date(r[0])) for r in rs if 15.0 <= r[2] < 30.0])
368|     ys5,xs5 = zip(*[(r[1],Db2Date(r[0])) for r in rs if 30.0 <= r[2]])
369| 
370|     xmin, xmax = dt_fr, dt_to
371|     ymin, ymax = (min_mag-0.1), 7.0
372| 
373|     fig, ax = plt.subplots()
374|     fig.suptitle('Kilauea Events')
375|     ax.set_xlabel('Date')
376|     ax.set_ylabel('Magnitude')
377|     ax.minorticks_on()
378| 
379|     ax.xaxis_date()
380|     ax.set_xlim(xmin, xmax)
381|     ax.xaxis.set_major_locator(WeekdayLocator(byweekday=MonthStartDay[dt_fr.month]))
382|     ax.xaxis.set_major_formatter(DateFormatter('%m-%d'))
383|     ax.xaxis.set_minor_locator(DayLocator(interval=1))
384| 
385|     ax.set_ylim(ymin, ymax)
386|     ax.yaxis.set_major_locator(MultipleLocator(1.0))
387|     ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
388|     ax.yaxis.set_minor_locator(MultipleLocator(0.1))
389| 
390|     ax.grid(which='major', axis='both', color='#bfbfbf', lw=1.2,ls='-',zorder=1, alpha=1.0)
391|     ax.grid(which='minor', axis='both', color='#dfdfdf', lw=0.6,ls='-',zorder=0, alpha=1.0)
392|     ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
393|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
394| 
395|     ax.plot(xs1,ys1, color='#ff0000', label='< 0 km'  , lw=0.0, marker='o', ms=3, alpha=1.0, zorder=5)
396|     ax.plot(xs2,ys2, color='#ff9f3f', label='0-5 km'  , lw=0.0, marker='o', ms=3, alpha=0.8, zorder=6)
397|     ax.plot(xs3,ys3, color='#007f00', label='5-15 km' , lw=0.0, marker='o', ms=3, alpha=0.6, zorder=7)
398|     ax.plot(xs4,ys4, color='#0000ff', label='15-30 km', lw=0.0, marker='o', ms=3, alpha=0.4, zorder=8)
399|     ax.plot(xs5,ys5, color='#bf00bf', label='> 30 km' , lw=0.0, marker='o', ms=4, alpha=0.2, zorder=9)
400|     ax.legend(loc='center right', bbox_to_anchor=(1.00,1.00), ncol=3, shadow=True)
401| 
402|     vertical_labels(ax)
403|     fig.set_figwidth(12.8)
404|     fig.set_figheight(4.8)
405|     fig.subplots_adjust(left=0.05, bottom=0.15, right=0.99, top=0.90)
406| 
407|     fig.savefig(path.join(HtmlPath,fname))
408|     return 'Done'
409| 
410| ##================================================================================================##
411| def chart_time_longitude (*args):
412|     Log.info('chart-time-longitude: %s' % str(args))
413|     fname = args[0] if 0 < len(args) else 'pele6.png'
414|     sql1 = SQL['mag.2']
415|     sql2 = SQL['mag.3']
416|     sql3 = SQL['mag.4']
417|     sql4 = SQL['mag.5']
418|     sql5 = SQL['mag.6+']
419|     dcut = '2018-04-29'
420|     # Query database for data...
421|     tbl = dbEarthquakeTable()
422|     rs1 = tbl.db_query(sql1 % tbl.name, [dcut])
423|     rs2 = tbl.db_query(sql2 % tbl.name, [dcut])
424|     rs3 = tbl.db_query(sql3 % tbl.name, [dcut])
425|     rs4 = tbl.db_query(sql4 % tbl.name, [dcut])
426|     rs5 = tbl.db_query(sql5 % tbl.name, [dcut])
427|     if not (rs1 and rs2 and rs3 and rs4 and rs5): Log.warn('No data!'); return 'No Data!'
428|     # Process data...
429|     xs1 = [Db2Date(r[4]) for r in rs1]
430|     xs2 = [Db2Date(r[4]) for r in rs2]
431|     xs3 = [Db2Date(r[4]) for r in rs3]
432|     xs4 = [Db2Date(r[4]) for r in rs4]
433|     xs5 = [Db2Date(r[4]) for r in rs5]
434|     ys1 = [r[0] for r in rs1]
435|     ys2 = [r[0] for r in rs2]
436|     ys3 = [r[0] for r in rs3]
437|     ys4 = [r[0] for r in rs4]
438|     ys5 = [r[0] for r in rs5]
439|     xmin, xmax = StartDate, CutoffDate
440|     ymin, ymax = -156.0, -154.5
441| 
442|     fig, ax = plt.subplots()
443|     fig.suptitle('Kilauea Events')
444|     ax.minorticks_on()
445| 
446|     ax.set_xlabel('Date/Time')
447|     ax.xaxis_date()
448|     ax.set_xlim(xmin, xmax)
449|     ax.xaxis.set_major_locator(DayLocator(interval=7))
450|     ax.xaxis.set_major_formatter(DateFormatter('%m-%d'))
451|     ax.xaxis.set_minor_locator(DayLocator(interval=1))
452| 
453|     ax.set_ylabel('Longitude')
454|     ax.set_ylim(ymin, ymax)
455|     ax.invert_yaxis()
456|     ax.yaxis.set_major_locator(MultipleLocator(0.5))
457|     ax.yaxis.set_minor_locator(MultipleLocator(0.1))
458|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+.1f'))
459| 
460|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
461|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=2, alpha=1.0)
462|     ax.tick_params(which='major', axis='both', direction='out', color='#000000')
463|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f')
464| 
465|     ax.plot(xs1,ys1, color=Colors['M2'], label='M2.0-M2.9', lw=0, marker='o', ms=3, alpha=0.4, zorder=5)
466|     ax.plot(xs2,ys2, color=Colors['M3'], label='M3.0-M3.9', lw=0, marker='o', ms=3, alpha=0.7, zorder=6)
467|     ax.plot(xs3,ys3, color=Colors['M4'], label='M4.0-M4.9', lw=0, marker='o', ms=3, alpha=1.0, zorder=7)
468|     ax.plot(xs4,ys4, color=Colors['M5'], label='M5.0-M5.9', lw=0, marker='o', ms=4, alpha=1.0, zorder=8)
469|     ax.plot(xs5,ys5, color=Colors['M6'], label='M6.0+'    , lw=0, marker='o', ms=5, alpha=1.0, zorder=9)
470|     ax.legend(loc='center right', bbox_to_anchor=(1.00,0.02), ncol=5, shadow=True, facecolor='#ffffff', framealpha=1.0)
471| 
472|     vertical_labels(ax)
473|     fig.set_figwidth(9.6)
474|     fig.set_figheight(4.8)
475|     fig.subplots_adjust(left=0.08, bottom=0.15, right=0.99, top=0.90)
476| 
477|     fig.savefig(path.join(HtmlPath,fname))
478|     return 'Done'
479| 
480| ##================================================================================================##
481| def chart_time_latitude (*args):
482|     Log.info('chart-time-latitude: %s' % str(args))
483|     fname = args[0] if 0 < len(args) else 'pele7.png'
484|     sql1 = SQL['mag.2']
485|     sql2 = SQL['mag.3']
486|     sql3 = SQL['mag.4']
487|     sql4 = SQL['mag.5']
488|     sql5 = SQL['mag.6+']
489|     dcut = '2018-04-29'
490|     # Query database for data...
491|     tbl = dbEarthquakeTable()
492|     rs1 = tbl.db_query(sql1 % tbl.name, [dcut])
493|     rs2 = tbl.db_query(sql2 % tbl.name, [dcut])
494|     rs3 = tbl.db_query(sql3 % tbl.name, [dcut])
495|     rs4 = tbl.db_query(sql4 % tbl.name, [dcut])
496|     rs5 = tbl.db_query(sql5 % tbl.name, [dcut])
497|     if not (rs1 and rs2 and rs3 and rs4 and rs5): Log.warn('No data!'); return 'No Data!'
498|     # Process data...
499|     xs1 = [Db2Date(r[4]) for r in rs1]
500|     xs2 = [Db2Date(r[4]) for r in rs2]
501|     xs3 = [Db2Date(r[4]) for r in rs3]
502|     xs4 = [Db2Date(r[4]) for r in rs4]
503|     xs5 = [Db2Date(r[4]) for r in rs5]
504|     ys1 = [r[1] for r in rs1]
505|     ys2 = [r[1] for r in rs2]
506|     ys3 = [r[1] for r in rs3]
507|     ys4 = [r[1] for r in rs4]
508|     ys5 = [r[1] for r in rs5]
509|     xmin, xmax = StartDate, CutoffDate
510|     ymin, ymax = +19.00, +20.00
511| 
512|     fig, ax = plt.subplots()
513|     fig.suptitle('Kilauea Events')
514|     ax.minorticks_on()
515| 
516|     ax.set_xlabel('Date/Time')
517|     ax.xaxis_date()
518|     ax.set_xlim(xmin, xmax)
519|     ax.xaxis.set_major_locator(DayLocator(interval=7))
520|     ax.xaxis.set_major_formatter(DateFormatter('%m-%d'))
521|     ax.xaxis.set_minor_locator(DayLocator(interval=1))
522| 
523|     ax.set_ylabel('Latitude')
524|     ax.set_ylim(ymin, ymax)
525|     ax.yaxis.set_major_locator(MultipleLocator(0.5))
526|     ax.yaxis.set_minor_locator(MultipleLocator(0.1))
527|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+.1f'))
528| 
529|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
530|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=2, alpha=1.0)
531|     ax.tick_params(which='major', axis='both', direction='out', color='#000000')
532|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f')
533| 
534|     ax.plot(xs1,ys1, color=Colors['M2'], label='M2.0-M2.9', lw=0, marker='o', ms=3, alpha=0.4, zorder=5)
535|     ax.plot(xs2,ys2, color=Colors['M3'], label='M3.0-M3.9', lw=0, marker='o', ms=3, alpha=0.7, zorder=6)
536|     ax.plot(xs3,ys3, color=Colors['M4'], label='M4.0-M4.9', lw=0, marker='o', ms=3, alpha=1.0, zorder=7)
537|     ax.plot(xs4,ys4, color=Colors['M5'], label='M5.0-M5.9', lw=0, marker='o', ms=4, alpha=1.0, zorder=8)
538|     ax.plot(xs5,ys5, color=Colors['M6'], label='M6.0+'    , lw=0, marker='o', ms=5, alpha=1.0, zorder=9)
539|     ax.legend(loc='center right', bbox_to_anchor=(1.00,1.00), ncol=5, shadow=True, facecolor='#ffffff', framealpha=1.0)
540| 
541|     vertical_labels(ax)
542|     fig.set_figwidth(9.6)
543|     fig.set_figheight(4.8)
544|     fig.subplots_adjust(left=0.08, bottom=0.15, right=0.99, top=0.90)
545| 
546|     fig.savefig(path.join(HtmlPath,fname))
547|     return 'Done'
548| 
549| ##================================================================================================##
550| def chart_time_depth (*args):
551|     Log.info('chart-time-depth: %s' % str(args))
552|     fname = args[0] if 0 < len(args) else 'pele8.png'
553|     sql1 = SQL['mag.2']
554|     sql2 = SQL['mag.3']
555|     sql3 = SQL['mag.4']
556|     sql4 = SQL['mag.5']
557|     sql5 = SQL['mag.6+']
558|     dcut = '2018-04-29'
559|     # Query database for data...
560|     tbl = dbEarthquakeTable()
561|     rs1 = tbl.db_query(sql1 % tbl.name, [dcut])
562|     rs2 = tbl.db_query(sql2 % tbl.name, [dcut])
563|     rs3 = tbl.db_query(sql3 % tbl.name, [dcut])
564|     rs4 = tbl.db_query(sql4 % tbl.name, [dcut])
565|     rs5 = tbl.db_query(sql5 % tbl.name, [dcut])
566|     if not (rs1 and rs2 and rs3 and rs4 and rs5): Log.warn('No data!'); return 'No Data!'
567|     # Process data...
568|     xs1 = [Db2Date(r[4]) for r in rs1]
569|     xs2 = [Db2Date(r[4]) for r in rs2]
570|     xs3 = [Db2Date(r[4]) for r in rs3]
571|     xs4 = [Db2Date(r[4]) for r in rs4]
572|     xs5 = [Db2Date(r[4]) for r in rs5]
573|     ys1 = [r[2] for r in rs1]
574|     ys2 = [r[2] for r in rs2]
575|     ys3 = [r[2] for r in rs3]
576|     ys4 = [r[2] for r in rs4]
577|     ys5 = [r[2] for r in rs5]
578|     xmin, xmax = StartDate, CutoffDate
579|     ymin, ymax = +50.00, -10.00
580| 
581|     fig, ax = plt.subplots()
582|     fig.suptitle('Kilauea Events')
583|     ax.minorticks_on()
584| 
585|     ax.set_xlabel('Date/Time')
586|     ax.xaxis_date()
587|     ax.set_xlim(xmin, xmax)
588|     ax.xaxis.set_major_locator(DayLocator(interval=7))
589|     ax.xaxis.set_major_formatter(DateFormatter('%m-%d'))
590|     ax.xaxis.set_minor_locator(DayLocator(interval=1))
591| 
592|     ax.set_ylabel('Depth')
593|     ax.set_ylim(ymin, ymax)
594|     ax.yaxis.set_major_locator(MultipleLocator(10.0))
595|     ax.yaxis.set_minor_locator(MultipleLocator( 1.0))
596|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+.1f'))
597| 
598|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
599|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=2, alpha=1.0)
600|     ax.tick_params(which='major', axis='both', direction='out', color='#000000')
601|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f')
602| 
603|     ax.plot(xs1,ys1, color=Colors['M2'], label='M2.0-M2.9', lw=0, marker='o', ms=3, alpha=0.4, zorder=5)
604|     ax.plot(xs2,ys2, color=Colors['M3'], label='M3.0-M3.9', lw=0, marker='o', ms=3, alpha=0.7, zorder=6)
605|     ax.plot(xs3,ys3, color=Colors['M4'], label='M4.0-M4.9', lw=0, marker='o', ms=3, alpha=1.0, zorder=7)
606|     ax.plot(xs4,ys4, color=Colors['M5'], label='M5.0-M5.9', lw=0, marker='o', ms=4, alpha=1.0, zorder=8)
607|     ax.plot(xs5,ys5, color=Colors['M6'], label='M6.0+'    , lw=0, marker='o', ms=5, alpha=1.0, zorder=9)
608|     ax.legend(loc='center right', bbox_to_anchor=(1.00,0.02), ncol=5, shadow=True, facecolor='#ffffff', framealpha=1.0)
609| 
610|     vertical_labels(ax)
611|     fig.set_figwidth(9.6)
612|     fig.set_figheight(4.8)
613|     fig.subplots_adjust(left=0.08, bottom=0.15, right=0.99, top=0.90)
614| 
615|     fig.savefig(path.join(HtmlPath,fname))
616|     return 'Done'
617| 
618| ##================================================================================================##
619| def chart_event_counts (*args):
620|     Log.info('chart-event-counts: %s' % str(args))
621|     fname = args[0] if 0 < len(args) else 'pele9.png'
622|     which = args[1] if 1 < len(args) else ''
623|     sql = SQL['mag.all']
624|     dcut = '2018-04-29'
625|     # Query database for data...
626|     tbl = dbEarthquakeTable()
627|     rs = tbl.db_query(sql % tbl.name, [dcut])
628|     if not rs: Log.warn('No data!'); return 'No Data!'
629|     # Process the data into day bins...
630|     days = {}
631|     for r in rs:
632|         dt = Db2Date(r[0]).astimezone(HST()).date()
633|         if dt not in days: days[dt] = [0,0,0,0,0,0]
634|         days[dt][int(r[1])-1] += 1
635|     # Process data...
636|     dts = sorted(days.keys())
637|     x1,x2,x3,x4,x5,x6 = zip(*[days[dt] for dt in dts])
638| 
639|     # Create a chart...
640|     xmin, xmax = StartDate, CutoffDate
641|     ymin, ymax = 0, 600
642|     ymaj, ymin = 100, 10
643| 
644|     fig, ax = plt.subplots()
645|     fig.suptitle('Kilauea Events')
646|     ax.set_xlabel('Days')
647|     ax.set_ylabel('Counts')
648|     ax.minorticks_on()
649| 
650|     ax.xaxis_date()
651|     ax.set_xlim(xmin, xmax)
652|     ax.xaxis.set_major_locator(DayLocator(interval=7))
653|     ax.xaxis.set_major_formatter(DateFormatter('%m-%d'))
654|     ax.xaxis.set_minor_locator(DayLocator(interval=1))
655| 
656|     ax.set_ylim(ymin, ymax)
657|     ax.yaxis.set_major_locator(MultipleLocator(100))
658|     ax.yaxis.set_minor_locator(MultipleLocator(10))
659| 
660|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
661|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
662|     ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
663|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
664| 
665|     b1 = 'M1.0-1.9'
666|     b2 = 'M2.0-2.9'
667|     b3 = 'M3.0-3.9'
668|     ax.plot(dts,x1, color=Colors['M1'], label=b1, lw=1.2, ms=0, alpha=1.0, zorder=4)
669|     ax.plot(dts,x2, color=Colors['M2'], label=b2, lw=1.2, ms=0, alpha=1.0, zorder=5)
670|     ax.plot(dts,x3, color=Colors['M3'], label=b3, lw=1.2, ms=0, alpha=1.0, zorder=6)
671|     ax.legend(loc='upper left', bbox_to_anchor=(0.00,1.00), shadow=True)
672| 
673|     vertical_labels(ax)
674|     fig.set_figwidth(9.6)
675|     fig.set_figheight(4.8)
676|     fig.subplots_adjust(left=0.07, bottom=0.15, right=0.99, top=0.90)
677|     fig.savefig(path.join(HtmlPath,fname))
678|     return 'Done'
679| 
680| ##================================================================================================##
681| def chart_3d (*args):
682|     Log.info('chart-3D: %s' % str(args))
683|     fname = args[0] if 0 < len(args) else 'pele_3d.png'
684|     mode  = args[1] if 1 < len(args) else ''
685|     sql1 = SQL['mag.2']
686|     sql2 = SQL['mag.3']
687|     sql3 = SQL['mag.4']
688|     sql4 = SQL['mag.5']
689|     sql5 = SQL['mag.6+']
690|     dcut = '2018-08-04'
691|     # Query database for data...
692|     tbl = dbEarthquakeTable()
693|     rs1 = tbl.db_query(sql1 % tbl.name, [dcut])
694|     rs2 = tbl.db_query(sql2 % tbl.name, [dcut])
695|     rs3 = tbl.db_query(sql3 % tbl.name, [dcut])
696|     rs4 = tbl.db_query(sql4 % tbl.name, [dcut])
697|     rs5 = tbl.db_query(sql5 % tbl.name, [dcut])
698|     if not (rs1 and rs2 and rs3 and rs4 and rs5): Log.warn('No data!')
699|     # Process data...
700|     if mode == 'tight':
701|         xmin, xmax = -155.30, -155.25
702|         ymin, ymax =  +19.38,  +19.43
703|         zmin, zmax =   +5.00,   -2.00
704|         hticks = 0.01
705|         vticks = 1.00
706|     else:
707|         #rs1 = [r for r in rs1 if '2018-08-04' < r[4]]
708|         #rs2 = [r for r in rs2 if '2018-08-04' < r[4]]
709|         #rs3 = [r for r in rs3 if '2018-08-04' < r[4]]
710|         #rs4 = [r for r in rs4 if '2018-08-04' < r[4]]
711|         #rs5 = [r for r in rs5 if '2018-08-04' < r[4]]
712|         Log.debug(rs1)
713|         Log.debug(rs5)
714|         xmin, xmax = -155.50, -155.00
715|         ymin, ymax =  +19.00,  +19.50
716|         zmin, zmax =  +20.00,   -5.00
717|         hticks = 0.25
718|         vticks = 2.00
719|     xs1,ys1,zs1,_,_ = zip(*rs1) if len(rs1) else ([],[],[],[],[])
720|     xs2,ys2,zs2,_,_ = zip(*rs2) if len(rs2) else ([],[],[],[],[])
721|     xs3,ys3,zs3,_,_ = zip(*rs3) if len(rs3) else ([],[],[],[],[])
722|     xs4,ys4,zs4,_,_ = zip(*rs4) if len(rs4) else ([],[],[],[],[])
723|     xs5,ys5,zs5,_,_ = zip(*rs5) if len(rs5) else ([],[],[],[],[])
724|     xs6,ys6,zs6 = Coords['kilauea']
725|     xs7,ys7,zs7 = Coords['fissure8']
726| 
727|     fig = plt.figure()
728|     fig.suptitle('Kilauea Events')
729|     ax = fig.gca(projection='3d')
730|     ax.set_xlabel('Longitude')
731|     ax.set_ylabel('Latitude')
732|     ax.set_zlabel('Depth (km)')
733|     ax.minorticks_on()
734|     ax.view_init(azim=-110, elev=30)
735| 
736|     ax.set_xlim(xmin, xmax)
737|     ax.xaxis.set_major_locator(MultipleLocator(hticks))
738|     ax.xaxis.set_major_formatter(FormatStrFormatter('%+.2f'))
739|     #ax.xaxis.set_minor_locator(MultipleLocator(0.01))
740| 
741|     ax.set_ylim(ymin, ymax)
742|     ax.yaxis.set_major_locator(MultipleLocator(hticks))
743|     ax.yaxis.set_major_formatter(FormatStrFormatter('%+.2f'))
744|     #ax.yaxis.set_minor_locator(MultipleLocator(0.01))
745| 
746|     ax.set_zlim(zmin, zmax)
747|     ax.zaxis.set_major_locator(MultipleLocator(vticks))
748|     ax.zaxis.set_major_formatter(FormatStrFormatter('%+.2f'))
749|     #ax.zaxis.set_minor_locator(MultipleLocator(0.10))
750| 
751|     #ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
752|     #ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=2, alpha=1.0)
753|     #ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
754|     #ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
755| 
756|     ax.plot(xs1,ys1,zs1, color=Colors['M2'], lw=0, marker='o', ms=2, alpha=0.1, zorder=6)
757|     ax.plot(xs2,ys2,zs2, color=Colors['M3'], lw=0, marker='o', ms=3, alpha=0.2, zorder=7)
758|     ax.plot(xs3,ys3,zs3, color=Colors['M4'], lw=0, marker='o', ms=4, alpha=0.7, zorder=8)
759|     ax.plot(xs4,ys4,zs4, color=Colors['M5'], lw=0, marker='o', ms=4, alpha=0.9, zorder=9)
760|     ax.plot(xs5,ys5,zs5, color=Colors['M6'], lw=0, marker='o', ms=5, alpha=0.9, zorder=9)
761|     ax.plot([xs6],[ys6],[zs6], color='#000000', label='Kilauea', lw=0, marker='^', ms=9, alpha=1.0, zorder=9)
762|     ax.plot([xs7],[ys7],[zs7], color='#000000', label='F8'     , lw=0, marker='^', ms=4, alpha=1.0, zorder=9)
763| 
764|     fig.set_figwidth(10.24)
765|     fig.set_figheight(8.0)
766|     fig.subplots_adjust(left=0.00, bottom=0.00, right=1.00, top=1.00)
767| 
768|     fig.savefig(path.join(BasePath,fname))
769|     plt.show()
770|     return 'Done'
771| 
772| 
773| ##================================================================================================##
774| def chart_test_boxplot (*args):
775|     Log.info('chart-boxplot: %s' % str(args))
776|     fname = args[0] if 0 < len(args) else 'box_day_mag.png'
777|     sql = SQL['dep.all']
778|     dcut = '2018-01-01 10:00:00'
779|     # Query database for data...
780|     tbl = dbEarthquakeTable()
781|     rs = tbl.db_query(sql % tbl.name, [dcut])
782|     if not rs: Log.warn('No data!'); return 'No Data!'
783|     # Process the data into day bins...
784|     weeks = {}
785|     for r in rs:
786|         dt = Db2Date(r[0]).astimezone(HST()).date()
787|         wk = dt.isocalendar()[1]
788|         if wk not in weeks: weeks[wk] = [dt, []]
789|         if dt < weeks[wk][0]: weeks[wk][0] = dt
790|         weeks[wk][1].append(r[1])
791|     # Sort...
792|     ks = sorted(weeks.keys()) # KeyS
793|     bs = [weeks[k][0].strftime('%m-%d') for k in ks] # laBelS
794|     ds = [weeks[k][1] for k in ks] # DatumS
795| 
796|     # Create a chart...
797|     ymin, ymax = 110, -10
798| 
799|     fig, ax = plt.subplots()
800|     ax.set_title('Kilauea Events', horizontalalignment='left')
801|     ax.set_xlabel('Weeks')
802|     ax.set_ylabel('Depth (km)')
803|     ax.minorticks_on()
804| 
805|     ax.xaxis.set_minor_locator(MultipleLocator(1))
806| 
807|     ax.set_ylim(ymin, ymax)
808|     ax.yaxis.set_major_locator(MultipleLocator(10.0))
809|     ax.yaxis.set_minor_locator(MultipleLocator(2.0))
810|     #ax.invert_yaxis()
811| 
812|     ax.grid(which='major', axis='y', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
813|     ax.grid(which='minor', axis='y', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
814|     ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
815|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
816| 
817|     #ax.boxplot(ds, labels=bs, widths=0.40)
818|     ax.boxplot(ds, labels=bs, whis='range', widths=0.40)
819| 
820|     vertical_labels(ax)
821|     fig.set_figwidth(8.0)
822|     fig.set_figheight(4.8)
823|     fig.subplots_adjust(left=0.09, right=0.99, bottom=0.15, top=0.94)
824|     fig.savefig(path.join(BasePath,fname))
825|     return 'Done'
826| 
827| 
828| ####################################################################################################
829| def do_test (*args):
830|     Log.info('do-test: %s' % str(args))
831|     fname = args[0] if 0 < len(args) else 'test.png'
832|     qname = args[1] if 1 < len(args) else 'test.chart'
833|     sql = '''\
833| SELECT "ts", "mag","magtype"
833| FROM "%s"
833| WHERE ("ts" BETWEEN ? AND ?) AND (? <= "mag")
833| ORDER BY "ts"
833| '''

834|     dt0 = '2018-01-01'
835|     dt1 = '2019-01-01'
836|     mag = 1.0
837|     m0 = float(3) / float(2)
838|     # Query database for data...
839|     tbl = dbEarthquakeTable()
840|     rs = tbl.db_query(sql % tbl.name, [dt0, dt1, mag])
841|     if not rs: Log.warn('No data!'); return 'No Data!'
842|     # Process the data...
843|     data = {}
844|     for ts,mag,mt in rs:
845|         dt = date(int(ts[0:4]), int(ts[5:7]), int(ts[8:10]))
846|         #e = (10.0 ** (m0 * (mag + 10.7))) * (10 ** -18)
847|         e = (10.0 ** mag)
848|         if dt not in data:
849|             data[dt] = int(0)
850|         data[dt] += e
851|     xs = list(sorted(data.keys()))
852|     ys = [int(data[x]) for x in xs]
853|     for y in ys: Log.info(y)
854| 
855|     # Create a chart...
856|     xmin, xmax = date(2018,1,1), date(2018,12,31)
857|     ymin, ymax = 0, 1000000
858| 
859|     fig, ax = plt.subplots()
860|     ax.set_title('Kilauea Quake Energy')
861|     ax.set_xlabel('Months (in 2018)')
862|     ax.set_ylabel('Energy')
863|     ax.minorticks_on()
864| 
865|     ax.xaxis_date()
866|     ax.set_xlim(xmin, xmax)
867|     ax.xaxis.set_major_locator(MonthLocator(interval=1))
868|     ax.xaxis.set_minor_locator(DayLocator(interval=7))
869|     ax.xaxis.set_major_formatter(DateFormatter('%m-%d'))
870| 
871|     ax.set_ylim(ymin, ymax)
872|     ax.yaxis.set_major_locator(MultipleLocator(250000))
873|     ax.yaxis.set_minor_locator(MultipleLocator(100000))
874|     ax.yaxis.set_major_formatter(FormatStrFormatter('%.0e'))
875| 
876|     ax.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
877|     ax.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
878|     ax.tick_params(which='major', axis='both', direction='out', color='#000000', zorder=0)
879|     ax.tick_params(which='minor', axis='both', direction='out', color='#7f7f7f', zorder=0)
880| 
881|     ax.fill_between(xs,ys,0, color='#ff3f00', alpha=1.0, zorder=9)
882|     #ax.legend(loc='upper left', bbox_to_anchor=(0.00,1.00), shadow=True)
883|     vertical_labels(ax)
884| 
885|     fig.set_figwidth(6.4)
886|     fig.set_figheight(4.8)
887|     fig.subplots_adjust(left=0.13, right=0.99, bottom=0.15, top=0.94)
888|     fig.savefig(path.join(BasePath,fname))
889|     return 'Done'
890| 
891| ####################################################################################################
892| def do_all_charts (*args):
893|     Log.info('do-all-charts: %s' % str(args))
894| 
895|     chart_intervals()
896|     chart_histo_mag()
897|     chart_histo_dep()
898|     chart_magnitude_depth()
899|     chart_time_longitude()
900|     chart_time_latitude()
901|     chart_time_depth()
902|     chart_event_counts()
903| 
904|     chart_time_mag()
905|     chart_time_mag('pele2-1.png',  '1', '1',  '2', '1')
906|     chart_time_mag('pele2-2.png',  '2', '1',  '3', '1')
907|     chart_time_mag('pele2-3.png',  '3', '1',  '4', '1')
908|     chart_time_mag('pele2-4.png',  '4', '1',  '5', '1')
909|     chart_time_mag('pele2-5.png',  '5', '1',  '6', '1')
910|     chart_time_mag('pele2-6.png',  '6', '1',  '7', '1')
911|     chart_time_mag('pele2-7.png',  '7', '1',  '8', '1')
912|     chart_time_mag('pele2-8.png',  '8', '1',  '9', '1')
913|     chart_time_mag('pele2-9.png',  '9', '1', '10', '1')
914|     chart_time_mag('pele2-A.png', '10', '1', '11', '1')
915|     chart_time_mag('pele2-B.png', '11', '1', '12', '1')
916|     chart_time_mag('pele2-C.png', '12', '1', '12', '31')
917| 
918|     chart_longitude_latitude()
919|     chart_longitude_latitude('pele5-s.png', 'small')
920|     chart_longitude_latitude('pele5-t.png', 'tiny')
921|     chart_longitude_latitude('pele5-e.png', 'erz')
922|     return 'Done'
923| 
924| ####################################################################################################
925| def do_stub (*args):
926|     Log.info('do-stub: %s' % str(args))
927|     return 'Done'
928| 
929| ####################################################################################################
930| def dispatch (cmd, *args):
931|     Log.info('command: %s' % cmd)
932|     Log.info('arguments: %d' % len(args))
933| 
934|     if cmd == 'intervals': return chart_intervals(*args)
935|     if cmd == 'hist_mag': return chart_histo_mag(*args)
936|     if cmd == 'hist_dep': return chart_histo_dep(*args)
937| 
938|     if cmd == 'chart2': return chart_time_mag(*args)
939|     if cmd == 'chart4': return chart_magnitude_depth(*args)
940|     if cmd == 'chart5': return chart_longitude_latitude(*args)
941|     if cmd == 'chart6': return chart_time_longitude(*args)
942|     if cmd == 'chart7': return chart_time_latitude(*args)
943|     if cmd == 'chart8': return chart_time_depth(*args)
944|     if cmd == 'chart9': return chart_event_counts(*args)
945| 
946|     if cmd == '3d': return chart_3d(*args)
947|     if cmd == 'box': return chart_test_boxplot(*args)
948| 
949|     if cmd == 'test': return do_test(*args)
950|     if cmd == 'stub': return do_stub(*args)
951|     if cmd == 'all': return do_all_charts(*args)
952|     return 'Nothing to do!'
953| ####################################################################################################
954| if __name__ == '__main__':
955|     print('autorun: %s' % argv[0])
956|     Log.start(path.join(BasePath,'app_hi_eq.log'))
957|     Log.level(info())
958|     Log.info(argv[0])
959|     Log.info()
960|     cmd = argv[1] if 1 < len(argv) else ''
961|     etc = argv[2:]
962|     try:
963|         print('CMD: %s' % cmd)
964|         print()
965|         obj = dispatch(cmd, *etc)
966|         print()
967|         print(obj)
968|         Log.info()
969|         Log.info(obj)
970|     except:
971|         etype, evalue, tb = exc_info()
972|         ts = extract_tb(tb)
973|         Log.error()
974|         Log.error('%s: %s' % (etype.__name__,str(evalue)))
975|         Log.error()
976|         for t in ts[-5:]:
977|             Log.error('[%d] %s (%s)' % (t[1], t[2], t[0]))
978|             Log.error(' %s' % t[3])
979|             Log.error()
980|         raise
981|     finally:
982|         Log.end()
983| ####################################################################################################
984| '''eof'''
985|