Skip to content

Commit b3d3363

Browse files
committed
Minor improvements to pyOkada
Event id shown in popup window and link to USGS added
1 parent dbc7222 commit b3d3363

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

pgamit/pyOkada.py

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -386,21 +386,45 @@ def save_masks(self, txt_file=None, kmz_file=None, include_postseismic=False):
386386
img_base64 = base64.b64encode(img_buffer.read()).decode("utf-8")
387387

388388
# Add overlay to KML
389-
epicenter.description = """ID: %s<br>
390-
Date: %s<br>
391-
Magnitude: %.1f<br>
392-
Depth: %.0f km<br>
393-
<p class="centered">
394-
<strong>Focal mechanism</strong><br>
395-
<img src="data:image/png;base64, %s" alt="focal mechanism" align="center"/>
396-
</p>""" % (self.event_id, self.date.strftime('%Y-%m-%d %H:%M:%S'),
397-
self.mag, self.depth[1] / 1000, img_base64)
389+
epicenter.description = """<table style="border-collapse: collapse; width: 100%%; text-align: left;">
390+
<tr><td style="text-align: left; font-weight: bold;">ID:</td><td>%s</td></tr>
391+
<tr><td style="text-align: left; font-weight: bold;">Date:</td><td>%s</td></tr>
392+
<tr><td style="text-align: left; font-weight: bold;">Mag:</td><td>%.1f</td></tr>
393+
<tr><td style="text-align: left; font-weight: bold;">Depth:</td><td>%.0f km</td></tr>
394+
<tr>
395+
<td colspan="2" style="text-align: left;">
396+
<a href="https://earthquake.usgs.gov/earthquakes/eventpage/%s" target="_blank"
397+
style="display: inline-block; text-align: left;">
398+
USGS event page
399+
</a>
400+
</td>
401+
</tr>
402+
<tr>
403+
<td colspan="2"">
404+
<strong>Focal Mechanism</strong><br>
405+
<img src="data:image/png;base64,%s" alt="Focal Mechanism"
406+
style="display: block; margin: 0 auto; max-width: 100%%;" />
407+
</td>
408+
</tr>
409+
</table>""" % (self.event_id, self.date.strftime('%Y-%m-%d %H:%M:%S'),
410+
self.mag, self.depth[1] / 1000, self.event_id, img_base64)
398411
else:
399-
epicenter.description = """ID: %s<br>
400-
Date: %s<br>
401-
Magnitude: %.1f<br>
402-
Depth: %.0f km<br>
403-
""" % (self.event_id, self.date.strftime('%Y-%m-%d %H:%M:%S'), self.mag, self.depth[1] / 1000)
412+
epicenter.description = """<table style="border-collapse: collapse;">
413+
<tr><td style="text-align: left; font-weight: bold;">ID:</td><td>%s</td></tr>
414+
<tr><td style="text-align: left; font-weight: bold;">Date:</td><td>%s</td></tr>
415+
<tr><td style="text-align: left; font-weight: bold;">Mag:</td><td>%.1f</td></tr>
416+
<tr><td style="text-align: left; font-weight: bold;">Depth:</td><td>%.0f km</td></tr>
417+
<tr>
418+
<td colspan="2" style="text-align: left;">
419+
<a href="https://earthquake.usgs.gov/earthquakes/eventpage/%s" target="_blank"
420+
style="display: inline-block; text-align: left;">
421+
USGS event page
422+
</a>
423+
</td>
424+
</tr>
425+
</table>
426+
""" % (self.event_id, self.date.strftime('%Y-%m-%d %H:%M:%S'), self.mag,
427+
self.depth[1] / 1000, self.event_id)
404428

405429
def process_contours(contours, lon_grid, lat_grid, color, name):
406430
"""
@@ -415,9 +439,12 @@ def process_contours(contours, lon_grid, lat_grid, color, name):
415439
lat = lat_grid[row_indices, col_indices]
416440

417441
poly = Polygon(np.column_stack((lon, lat))) # Convert to a Shapely polygon
418-
if poly.area > 1:
419-
# ignore polygons with areas smaller than 1 km**2
442+
if poly.area > 0.0025:
443+
# ignore polygons with areas smaller than 10 km**2 (expressed in deg**2)
420444
polygons.append(poly)
445+
# print('added %f' % poly.area)
446+
# else:
447+
# print('not added %f' % poly.area)
421448

422449
# Separate outer polygons from inner holes
423450
outer_polys = []
@@ -431,6 +458,7 @@ def process_contours(contours, lon_grid, lat_grid, color, name):
431458
break
432459
if not is_hole:
433460
outer_polys.append(poly)
461+
# print('outer detected')
434462

435463
# Add to KML
436464
for outer in outer_polys:

0 commit comments

Comments
 (0)