Skip to content

Commit

Permalink
Fix map plots when no magnitudes are available
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Dec 2, 2024
1 parent c5659b2 commit 88cf4d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
18 changes: 13 additions & 5 deletions seiscat/plot/plot_map_cartopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,29 @@ def _plot_events(ax, events, scale, plot_version_number=False):
:param scale: scale for event markers
:param ax: matplotlib axes object
"""
mags = [e['mag'] for e in events if e['mag'] is not None]
# use fixed radius if no magnitudes are available
fixed_radius = not mags
marker_scale = scale / 10. * 2
# remove events with no magnitude
events = [e for e in events if e['mag'] is not None]
if not fixed_radius:
# remove events with no magnitude
events = [e for e in events if e['mag'] is not None]
radii = [np.exp(e['mag']) * marker_scale for e in events]
else:
radii = [3*marker_scale] * len(events)
ev_attributes = [
(e['evid'], e['ver'], e['time'], e['lon'], e['lat'], e['depth'],
e['mag'], np.exp(e['mag']) * marker_scale)
for e in events
e['mag'], radii[n])
for n, e in enumerate(events)
]
# Sort events by time, so that the latest event is plotted on top
ev_attributes.sort(key=lambda x: x[2])
markers = []
for evid, ver, time, lon, lat, depth, mag, size in ev_attributes:
_evid = f'{evid} v{ver}' if plot_version_number else evid
mag_str = f'M{mag:.1f}' if mag is not None else ''
marker_label = (
f'{_evid} M{mag:.1f} {depth:.1f} km\n'
f'{_evid} {mag_str} {depth:.1f} km\n'
f'{time.strftime("%Y-%m-%d %H:%M:%S")}')
marker = ax.scatter(
lon, lat,
Expand Down
17 changes: 15 additions & 2 deletions seiscat/plot/plot_map_folium.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,25 @@ def plot_catalog_map_with_folium(events, config):
branca_element = branca.element.Element(catalog_stats)
m.get_root().html.add_child(branca_element)
# Add events to the map
mags = [event['mag'] for event in events if event['mag'] is not None]
# If no magnitudes are available, use a fixed marker radius
fixed_radius = not mags
scale = config['args'].scale
marker_scale = 0.2 * scale
for event in events:
if fixed_radius:
radius = marker_scale
elif event['mag'] is None:
continue
else:
radius = 1.5**(event['mag'])*marker_scale
mag_str = (
f"{event['mag_type']} {event['mag']:.1f} <br>"
if event['mag'] is not None else ''
)
popup_text = folium.Html(
f"<b>{event['evid']} v{event['ver']}</b> <br>"
f"{event['mag_type']} {event['mag']:.1f} <br>"
f"{mag_str}"
f"{event['time']} <br>"
f"{event['lat']:.2f} {event['lon']:.2f} "
f"{event['depth']:.1f} km",
Expand All @@ -90,7 +103,7 @@ def plot_catalog_map_with_folium(events, config):
popup = folium.Popup(popup_text, min_width=200, max_width=200)
folium.CircleMarker(
location=[event['lat'], event['lon']],
radius=1.5**(event['mag'])*marker_scale,
radius=radius,
color='red',
fill=True,
fill_color='red',
Expand Down

0 comments on commit 88cf4d1

Please sign in to comment.