Skip to content

Commit

Permalink
Better manage cases where event attributes are None
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Jun 19, 2024
1 parent 4d10b85 commit ee4ebab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions requake/families/families.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ def append(self, ev):
raise ValueError('Event trace_id does not match family trace_id')
super().append(ev)
self.sort()
self.lon = np.mean([e.lon for e in self])
self.lat = np.mean([e.lat for e in self])
self.depth = np.mean([e.depth for e in self])
if ev.lon is not None:
self.lon = np.mean([e.lon for e in self])
if ev.lat is not None:
self.lat = np.mean([e.lat for e in self])
if ev.depth is not None:
self.depth = np.mean([e.depth for e in self])
self.starttime = min(ev.orig_time, self.starttime)\
if self.starttime else ev.orig_time
self.endtime = max(ev.orig_time, self.endtime)\
Expand Down
7 changes: 6 additions & 1 deletion requake/plot/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,14 @@ def family_colors(families):
elif colorby == 'longitude':
values = [family.lon for family in families]
elif colorby == 'slip_rate':
values = [family.slip_rate if family.slip_rate is not np.inf else np.nan for family in families]
values = [
family.slip_rate if family.slip_rate is not np.inf
else np.nan for family in families
]
elif colorby == 'time':
values = [family.starttime.matplotlib_date for family in families]
# Convert values to float numpy array. This changes None values to np.nan
values = np.array(values, dtype=float)
norm = colors.Normalize(vmin=min(values), vmax=max(values))
fcolors = [cmap(norm(value)) for value in values]
return fcolors, norm, cmap
Expand Down

0 comments on commit ee4ebab

Please sign in to comment.