Skip to content

Commit 4bf8147

Browse files
committed
Add informations about speed profile in an example
1 parent 08d7dc8 commit 4bf8147

File tree

2 files changed

+105
-9
lines changed

2 files changed

+105
-9
lines changed

examples/01_general_things/pet_storage.py

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
"""
1717

1818
import py_eddy_tracker_sample
19+
from matplotlib import pyplot as plt
20+
from numpy import arange, outer
1921

20-
from py_eddy_tracker.data import get_demo_path, get_remote_demo_sample
22+
from py_eddy_tracker.data import get_demo_path
2123
from py_eddy_tracker.observations.network import NetworkObservations
2224
from py_eddy_tracker.observations.observation import EddiesObservations, Table
2325
from py_eddy_tracker.observations.tracking import TrackEddiesObservations
@@ -58,6 +60,53 @@
5860
# ---------------
5961
# All contours are stored on the same number of points, and are resampled if needed with an algorithm to be stored as objects
6062

63+
# %%
64+
# Speed profile storage
65+
# ---------------------
66+
# Speed profile is an interpolation of speed mean along each contour.
67+
# For each contour included in eddy, we compute mean of speed along the contour,
68+
# and after we interpolate speed mean array on a fixed size array.
69+
#
70+
# Several field are available to understand "uavg_profile" :
71+
# 0. - num_contours : Number of contour in eddies, must be equal to amplitude divide by isoline step
72+
# 1. - height_inner_contour : height of inner contour used
73+
# 2. - height_max_speed_contour : height of max speed contour used
74+
# 3. - height_external_contour : height of outter contour used
75+
#
76+
# Last value of "uavg_profile" is for inner contour and first value for outter contour.
77+
78+
# Observations selection of "uavg_profile" with high number of contour(Eddy with high amplitude)
79+
e = eddies_collections.extract_with_mask(eddies_collections.num_contours > 15)
80+
81+
# %%
82+
83+
# Raw display of profiles with more than 15 contours
84+
ax = plt.subplot(111)
85+
_ = ax.plot(e.uavg_profile.T, lw=0.5)
86+
87+
# %%
88+
89+
# Profile from inner to outter
90+
ax = plt.subplot(111)
91+
ax.plot(e.uavg_profile[:, ::-1].T, lw=0.5)
92+
_ = ax.set_xlabel("From inner to outter contour"), ax.set_ylabel("Speed (m/s)")
93+
94+
# %%
95+
96+
# If we normalize indice of contour to set speed contour to 1 and inner contour to 0
97+
ax = plt.subplot(111)
98+
h_in = e.height_inner_contour
99+
h_s = e.height_max_speed_contour
100+
h_e = e.height_external_contour
101+
r = (h_e - h_in) / (h_s - h_in)
102+
nb_pt = e.uavg_profile.shape[1]
103+
# Create an x array for each profile
104+
x = outer(arange(nb_pt) / nb_pt, r)
105+
106+
ax.plot(x, e.uavg_profile[:, ::-1].T, lw=0.5)
107+
_ = ax.set_xlabel("From inner to outter contour"), ax.set_ylabel("Speed (m/s)")
108+
109+
61110
# %%
62111
# Trajectories
63112
# ------------
@@ -86,11 +135,7 @@
86135
# - next_obs : Index of the next observation in the full dataset, if -1 there are no next observation (the segment ends)
87136
# - previous_cost : Result of the cost function (1 is a good association, 0 is bad) with previous observation
88137
# - next_cost : Result of the cost function (1 is a good association, 0 is bad) with next observation
89-
eddies_network = NetworkObservations.load_file(
90-
get_remote_demo_sample(
91-
"eddies_med_adt_allsat_dt2018_err70_filt500_order1/Anticyclonic_network.nc"
92-
)
93-
)
138+
eddies_network = NetworkObservations.load_file(get_demo_path("network_med.nc"))
94139
eddies_network.field_table()
95140

96141
# %%

notebooks/python_module/01_general_things/pet_storage.ipynb

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"import py_eddy_tracker_sample\n\nfrom py_eddy_tracker.data import get_demo_path, get_remote_demo_sample\nfrom py_eddy_tracker.observations.network import NetworkObservations\nfrom py_eddy_tracker.observations.observation import EddiesObservations, Table\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations"
29+
"import py_eddy_tracker_sample\nfrom matplotlib import pyplot as plt\nfrom numpy import arange, outer\n\nfrom py_eddy_tracker.data import get_demo_path\nfrom py_eddy_tracker.observations.network import NetworkObservations\nfrom py_eddy_tracker.observations.observation import EddiesObservations, Table\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations"
3030
]
3131
},
3232
{
@@ -108,6 +108,57 @@
108108
"## Contour storage\nAll contours are stored on the same number of points, and are resampled if needed with an algorithm to be stored as objects\n\n"
109109
]
110110
},
111+
{
112+
"cell_type": "markdown",
113+
"metadata": {},
114+
"source": [
115+
"## Speed profile storage\nSpeed profile is an interpolation of speed mean along each contour.\nFor each contour included in eddy, we compute mean of speed along the contour,\nand after we interpolate speed mean array on a fixed size array.\n\nSeveral field are available to understand \"uavg_profile\" :\n 0. - num_contours : Number of contour in eddies, must be equal to amplitude divide by isoline step\n 1. - height_inner_contour : height of inner contour used\n 2. - height_max_speed_contour : height of max speed contour used\n 3. - height_external_contour : height of outter contour used\n\nLast value of \"uavg_profile\" is for inner contour and first value for outter contour.\n\n"
116+
]
117+
},
118+
{
119+
"cell_type": "code",
120+
"execution_count": null,
121+
"metadata": {
122+
"collapsed": false
123+
},
124+
"outputs": [],
125+
"source": [
126+
"# Observations selection of \"uavg_profile\" with high number of contour(Eddy with high amplitude)\ne = eddies_collections.extract_with_mask(eddies_collections.num_contours > 15)"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"metadata": {
133+
"collapsed": false
134+
},
135+
"outputs": [],
136+
"source": [
137+
"# Raw display of profiles with more than 15 contours\nax = plt.subplot(111)\n_ = ax.plot(e.uavg_profile.T, lw=0.5)"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"metadata": {
144+
"collapsed": false
145+
},
146+
"outputs": [],
147+
"source": [
148+
"# Profile from inner to outter\nax = plt.subplot(111)\nax.plot(e.uavg_profile[:, ::-1].T, lw=0.5)\n_ = ax.set_xlabel(\"From inner to outter contour\"), ax.set_ylabel(\"Speed (m/s)\")"
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": null,
154+
"metadata": {
155+
"collapsed": false
156+
},
157+
"outputs": [],
158+
"source": [
159+
"# If we normalize indice of contour to set speed contour to 1 and inner contour to 0\nax = plt.subplot(111)\nh_in = e.height_inner_contour\nh_s = e.height_max_speed_contour\nh_e = e.height_external_contour\nr = (h_e - h_in) / (h_s - h_in)\nnb_pt = e.uavg_profile.shape[1]\n# Create an x array for each profile\nx = outer(arange(nb_pt) / nb_pt, r)\n\nax.plot(x, e.uavg_profile[:, ::-1].T, lw=0.5)\n_ = ax.set_xlabel(\"From inner to outter contour\"), ax.set_ylabel(\"Speed (m/s)\")"
160+
]
161+
},
111162
{
112163
"cell_type": "markdown",
113164
"metadata": {},
@@ -141,7 +192,7 @@
141192
},
142193
"outputs": [],
143194
"source": [
144-
"eddies_network = NetworkObservations.load_file(\n get_remote_demo_sample(\n \"eddies_med_adt_allsat_dt2018_err70_filt500_order1/Anticyclonic_network.nc\"\n )\n)\neddies_network.field_table()"
195+
"eddies_network = NetworkObservations.load_file(get_demo_path(\"network_med.nc\"))\neddies_network.field_table()"
145196
]
146197
},
147198
{
@@ -179,7 +230,7 @@
179230
"name": "python",
180231
"nbconvert_exporter": "python",
181232
"pygments_lexer": "ipython3",
182-
"version": "3.7.7"
233+
"version": "3.9.2"
183234
}
184235
},
185236
"nbformat": 4,

0 commit comments

Comments
 (0)