Skip to content
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
- minor english
  • Loading branch information
CoriPegliasco committed Apr 6, 2021
commit 8e6b5d47c006bc3c79a8836beb885c7db05056fd
2 changes: 1 addition & 1 deletion examples/01_general_things/pet_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# array field like contour/profile are 2D column.

# %%
# Eddies files (zarr or netcdf) could be loaded with ```load_file``` method:
# Eddies files (zarr or netcdf) can be loaded with ```load_file``` method:
eddies_collections = EddiesObservations.load_file(get_demo_path("Cyclonic_20160515.nc"))
eddies_collections.field_table()
# offset and scale_factor are used only when data is stored in zarr or netCDF4
Expand Down
12 changes: 6 additions & 6 deletions examples/14_generic_tools/pet_fit_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
from py_eddy_tracker import data
from py_eddy_tracker.generic import coordinates_to_local, local_to_coordinates
from py_eddy_tracker.observations.observation import EddiesObservations
from py_eddy_tracker.poly import fit_circle_, fit_ellips
from py_eddy_tracker.poly import fit_circle_, fit_ellipse

# %%
# Load example identification file
a = EddiesObservations.load_file(data.get_demo_path("Anticyclonic_20190223.nc"))


# %%
# Function to draw circle or ellips from parameter
# Function to draw circle or ellipse from parameter
def build_circle(x0, y0, r):
angle = radians(linspace(0, 360, 50))
x_norm, y_norm = cos(angle), sin(angle)
return local_to_coordinates(x_norm * r, y_norm * r, x0, y0)


def build_ellips(x0, y0, a, b, theta):
def build_ellipse(x0, y0, a, b, theta):
angle = radians(linspace(0, 360, 50))
x = a * cos(theta) * cos(angle) - b * sin(theta) * sin(angle)
y = a * sin(theta) * cos(angle) + b * cos(theta) * sin(angle)
return local_to_coordinates(x, y, x0, y0)


# %%
# Plot fitted circle or ellips on stored contour
# Plot fitted circle or ellipse on stored contour
xs, ys = a.contour_lon_s, a.contour_lat_s

fig = plt.figure(figsize=(15, 15))
Expand All @@ -51,9 +51,9 @@ def build_ellips(x0, y0, a, b, theta):
ax = fig.add_subplot(4, 4, j)
ax.grid(), ax.set_aspect("equal")
ax.plot(x, y, label="store", color="black")
x0, y0, a, b, theta = fit_ellips(x_, y_)
x0, y0, a, b, theta = fit_ellipse(x_, y_)
x0, y0 = local_to_coordinates(x0, y0, x0_, y0_)
ax.plot(*build_ellips(x0, y0, a, b, theta), label="ellips", color="green")
ax.plot(*build_ellipse(x0, y0, a, b, theta), label="ellipse", color="green")
x0, y0, radius, shape_error = fit_circle_(x_, y_)
x0, y0 = local_to_coordinates(x0, y0, x0_, y0_)
ax.plot(*build_circle(x0, y0, radius), label="circle", color="red", lw=0.5)
Expand Down
12 changes: 6 additions & 6 deletions examples/16_network/pet_follow_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _repr_html_(self, *args, **kwargs):

def save(self, *args, **kwargs):
if args[0].endswith("gif"):
# In this case gif is use to create thumbnail which are not use but consume same time than video
# In this case gif is used to create thumbnail which are not used but consumes same time than video
# So we create an empty file, to save time
with open(args[0], "w") as _:
pass
Expand Down Expand Up @@ -147,7 +147,7 @@ def particle_candidate(x, y, c, eddies, t_start, i_target, pct, **kwargs):
e = eddies.extract_with_mask(m_start)
# to be able to get global index
translate_start = where(m_start)[0]
# Identify particle in eddies(only in core)
# Identify particle in eddies (only in core)
i_start = e.contains(x, y, intern=True)
m = i_start != -1
x, y, i_start = x[m], y[m], i_start[m]
Expand All @@ -158,9 +158,9 @@ def particle_candidate(x, y, c, eddies, t_start, i_target, pct, **kwargs):
e_end = eddies.extract_with_mask(m_end)
# to be able to get global index
translate_end = where(m_end)[0]
# Id eddies for each alive particle(in core and extern)
# Id eddies for each alive particle (in core and extern)
i_end = e_end.contains(x, y)
# compute matrix and filled target array
# compute matrix and fill target array
get_matrix(i_start, i_end, translate_start, translate_end, i_target, pct)


Expand All @@ -169,7 +169,7 @@ def get_matrix(i_start, i_end, translate_start, translate_end, i_target, pct):
nb_start, nb_end = translate_start.size, translate_end.size
# Matrix which will store count for every couple
count = zeros((nb_start, nb_end), dtype=nb_types.int32)
# Number of particle in each origin observation
# Number of particles in each origin observation
ref = zeros(nb_start, dtype=nb_types.int32)
# For each particle
for i in range(i_start.size):
Expand All @@ -181,7 +181,7 @@ def get_matrix(i_start, i_end, translate_start, translate_end, i_target, pct):
for i in range(nb_start):
for j in range(nb_end):
pct_ = count[i, j]
# If there are particle from i to j
# If there are particles from i to j
if pct_ != 0:
# Get percent
pct_ = pct_ / ref[i] * 100.0
Expand Down
34 changes: 19 additions & 15 deletions examples/16_network/pet_ioannou_2017_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.ticker import FuncFormatter
from numpy import arange, where
from numpy import arange, where, array, pi

import py_eddy_tracker.gui
from py_eddy_tracker.appli.gui import Anim
from py_eddy_tracker.data import get_demo_path
from py_eddy_tracker.observations.network import NetworkObservations

from py_eddy_tracker.generic import coordinates_to_local, local_to_coordinates
from py_eddy_tracker.poly import fit_ellipse

# %%


class VideoAnimation(FuncAnimation):
def _repr_html_(self, *args, **kwargs):
"""To get video in html and have a player"""
Expand Down Expand Up @@ -192,43 +196,43 @@ def update_axes(ax, mappable=None):
# %%
# Rotation angle
# --------------
from py_eddy_tracker.generic import coordinates_to_local, local_to_coordinates
from py_eddy_tracker.poly import fit_ellips
# For each obs, fit an ellipse to the contour, with theta the angle from the x-axis,
# a the semi ax in x direction and b the semi ax in y dimension

theta_ = list()
a_ = list()
b_ = list()
for obs in close_to_i3:
x, y = obs['contour_lon_s'], obs['contour_lat_s']
x, y = obs["contour_lon_s"], obs["contour_lat_s"]
x0_, y0_ = x.mean(), y.mean()
x_, y_ = coordinates_to_local(x, y, x0_, y0_)
x0, y0, a, b, theta = fit_ellips(x_, y_)
x0, y0, a, b, theta = fit_ellipse(x_, y_)
theta_.append(theta)
a_.append(a)
b_.append(b)
a_=array(a_)
b_=array(b_)
a_ = array(a_)
b_ = array(b_)

# %%
# Theta
ax = timeline_axes()
m = close_to_i3.scatter_timeline(ax, theta_, vmin=-pi/2, vmax=pi/2, cmap='hsv')
m = close_to_i3.scatter_timeline(ax, theta_, vmin=-pi / 2, vmax=pi / 2, cmap="hsv")
cb = update_axes(ax, m["scatter"])

# %%
# A
# a
ax = timeline_axes()
m = close_to_i3.scatter_timeline(ax, a_ * 1e-3, vmin=0, vmax=80, cmap='Spectral_r')
m = close_to_i3.scatter_timeline(ax, a_ * 1e-3, vmin=0, vmax=80, cmap="Spectral_r")
cb = update_axes(ax, m["scatter"])

# %%
# B
# b
ax = timeline_axes()
m = close_to_i3.scatter_timeline(ax, b_ * 1e-3, vmin=0, vmax=80, cmap='Spectral_r')
m = close_to_i3.scatter_timeline(ax, b_ * 1e-3, vmin=0, vmax=80, cmap="Spectral_r")
cb = update_axes(ax, m["scatter"])

# %%
# A/B
# a/b
ax = timeline_axes()
m = close_to_i3.scatter_timeline(ax, a_/b_, vmin=1, vmax=2, cmap='Spectral_r')
m = close_to_i3.scatter_timeline(ax, a_ / b_, vmin=1, vmax=2, cmap="Spectral_r")
cb = update_axes(ax, m["scatter"])