Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Changed
Fixed
^^^^^
- Use `safe_load` for yaml load
- repr of EddiesObservation when the collection is empty (time attribute empty array)
- display_timeline and event_timeline can now use colors according to 'y' values.
- event_timeline now plot all merging event in one plot, instead of one plot per merging. Same for splitting. (avoid bad legend)

Added
^^^^^
Expand All @@ -28,6 +31,7 @@ Added
- Save EddyAnim in mp4
- Add method to get eddy contour which enclosed obs defined with (x,y) coordinates
- Add **EddyNetworkSubSetter** to subset network which need special tool and operation after subset
- Add functions to find relatives segments

[3.3.0] - 2020-12-03
--------------------
Expand Down
41 changes: 41 additions & 0 deletions examples/16_network/pet_relative.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
==========================
"""

import datetime

from matplotlib import pyplot as plt
from matplotlib.ticker import FuncFormatter

import py_eddy_tracker.gui
from py_eddy_tracker import data
Expand Down Expand Up @@ -186,6 +189,44 @@
ax.set_title(f"Close segments ({close_to_i3.infos()})")
_ = close_to_i3.display_timeline(ax)

# %%
# Keep relatives to an event
# --------------------------
# When you want to investigate one particular event and select only the closest segments
#
# First choose an event in the network
after, before, stopped = n.merging_event(triplet=True, only_index=True)
i_event = 5
# %%
# then see some order of relatives
@FuncFormatter
def formatter(x, pos):
return (datetime.timedelta(x) + datetime.datetime(1950, 1, 1)).strftime("%d/%m/%Y")


max_order = 2
fig, axs = plt.subplots(
max_order + 2, 1, sharex=True, figsize=(15, 5 * (max_order + 2))
)

axs[0].set_title(f"full network", weight="bold")
axs[0].xaxis.set_major_formatter(formatter), axs[0].grid()
mappables = n.display_timeline(axs[0], colors_mode="y")
axs[0].legend()

for k in range(0, max_order + 1):

ax = axs[k + 1]
sub_network = n.find_segments_relative(after[i_event], stopped[i_event], order=k)

ax.set_title(f"relatives order={k}", weight="bold")
ax.xaxis.set_major_formatter(formatter), ax.grid()

mappables = sub_network.display_timeline(ax, colors_mode="y")
ax.legend()
_ = ax.set_ylim(axs[0].get_ylim())


# %%
# Display track on map
# --------------------
Expand Down
14 changes: 13 additions & 1 deletion examples/16_network/pet_segmentation_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ def save(self, *args, **kwargs):
# %%
# Overlaod of class to pick up
TRACKS = list()
INDICES = list()


class MyTrack(TrackEddiesObservations):
@staticmethod
def get_next_obs(i_current, ids, x, y, time_s, time_e, time_ref, window, **kwargs):
TRACKS.append(ids["track"].copy())
INDICES.append(i_current)
return TrackEddiesObservations.get_next_obs(
i_current, ids, x, y, time_s, time_e, time_ref, window, **kwargs
)
Expand Down Expand Up @@ -70,9 +72,16 @@ def get_next_obs(i_current, ids, x, y, time_s, time_e, time_ref, window, **kwarg
def update(i_frame):
tr = TRACKS[i_frame]
mappable_tracks.set_array(tr)
s = 80 * ones(tr.shape)
s = 40 * ones(tr.shape)
s[tr == 0] = 4
mappable_tracks.set_sizes(s)

indices_frames = INDICES[i_frame]
mappable_CONTOUR.set_data(
e.contour_lon_e[indices_frames],
e.contour_lat_e[indices_frames],
)
mappable_CONTOUR.set_color(cmap.colors[tr[indices_frames] % len(cmap.colors)])
return (mappable_tracks,)


Expand All @@ -85,4 +94,7 @@ def update(i_frame):
mappable_tracks = ax.scatter(
e.lon, e.lat, c=TRACKS[0], cmap=cmap, vmin=0, vmax=vmax, s=20
)
mappable_CONTOUR = ax.plot(
e.contour_lon_e[INDICES[0]], e.contour_lat_e[INDICES[0]], color=cmap.colors[0]
)[0]
ani = VideoAnimation(fig, update, frames=range(1, len(TRACKS), 4), interval=125)
Loading