Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
- add scatter and event_map
  • Loading branch information
CoriPegliasco committed Feb 4, 2021
commit 58fdba736074b49c458f63901542445644eaf401
80 changes: 80 additions & 0 deletions src/py_eddy_tracker/observations/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,86 @@ def scatter_timeline(
mappables["scatter"] = ax.scatter(self.time, y, **kwargs)
return mappables

def event_map(self, ax, **kwargs):
"""Add the merging and splitting events """
j = 0
mappables = dict()
symbol_kw = dict(
markersize=10,
color="k",
)
symbol_kw.update(kwargs)
symbol_kw_split = symbol_kw.copy()
symbol_kw_split["markersize"] += 5
for i, b0, b1 in self.iter_on("segment"):
nb = i.stop - i.start
if nb == 0:
continue
event_kw = dict(color=self.COLORS[j % self.NB_COLORS], ls="-", **kwargs)
i_n, i_p = (
self.next_obs[i.stop - 1],
self.previous_obs[i.start],
)

if i_n != -1:
y0, y1 = self.lat[i.stop - 1], self.lat[i_n]
x0, x1 = self.lon[i.stop - 1], self.lon[i_n]
ax.plot((x0, x1), (y0, y1), **event_kw)[0]
ax.plot(x0, y0, marker="s", **symbol_kw)[0]
if i_p != -1:
y0, y1 = self.lat[i.start], self.lat[i_p]
x0, x1 = self.lon[i.start], self.lon[i_p]
ax.plot((x0, x1), (y0, y1), **event_kw)[0]
ax.plot(x0, y0, marker="*", **symbol_kw_split)[0]

j += 1
return mappables

def scatter(
self,
ax,
name="time",
s=25,
factor=1,
ref=None,
edgecolor_cycle=None,
cmap="Spectral_r",
**kwargs,
):
"""
This function will scatter the path of each trajectory

:param matplotlib.axes.Axes ax: ax to draw
:param float,int ref: if defined, all coordinates will be wrapped with ref like west boundary
:param dict kwargs: keyword arguments for Axes.plot
:return: a list of matplotlib mappables
"""
mappables = dict()
nb_colors = len(edgecolor_cycle) if edgecolor_cycle != None else None
x = self.longitude
if ref is not None:
x = (x - ref) % 360 + ref
kwargs = kwargs.copy()
if nb_colors:
edgecolors = list()
seg_previous = self.segment[0]
j = 0
for seg in self.segment:
if seg != seg_previous:
j += 1
edgecolors.append(edgecolor_cycle[j % nb_colors])
seg_previous = seg
mappables["edges"] = ax.scatter(
x, self.latitude, edgecolor=edgecolors, **kwargs
)
kwargs.pop("linewidths", None)
kwargs["lw"] = 0
if name is not None and "c" not in kwargs:
v = self.parse_varname(name)
kwargs["c"] = v * factor
mappables["scatter"] = ax.scatter(x, self.latitude, **kwargs)
return mappables

def insert_virtual(self):
# TODO
pass
Expand Down