Skip to content

Commit 17d78d8

Browse files
committed
- Add method to know how contour is reject
- Add method a first version to regrid one grid on another (AntSimi#24)
1 parent 486e895 commit 17d78d8

File tree

8 files changed

+340
-41
lines changed

8 files changed

+340
-41
lines changed

examples/02_eddy_identification/pet_eddy_detection.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
2-
Eddy detection
3-
==============
2+
Eddy detection : Med
3+
====================
44
55
Script will detect eddies on adt field, and compute u,v with method add_uv(which could use, only if equator is avoid)
66
77
Figures will show different step to detect eddies.
88
99
"""
10+
from numpy import arange
1011
from datetime import datetime
1112
from matplotlib import pyplot as plt
1213
from py_eddy_tracker.dataset.grid import RegularGridDataset
@@ -26,7 +27,7 @@ def start_axes(title):
2627
def update_axes(ax, mappable=None):
2728
ax.grid()
2829
if mappable:
29-
plt.colorbar(mappable, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))
30+
plt.colorbar(mappable, cax=ax.figure.add_axes([0.94, 0.05, 0.01, 0.9]))
3031

3132

3233
# %%
@@ -65,7 +66,7 @@ def update_axes(ax, mappable=None):
6566
# --------------
6667
# run identification with slice of 2 mm
6768
date = datetime(2016, 5, 15)
68-
a, c = g.eddy_identification("adt", "u", "v", date, 0.002)
69+
a, c = g.eddy_identification("adt", "u", "v", date, 0.002, shape_error=55)
6970

7071
# %%
7172
# All closed contour found in this input grid (Display only 1 contour every 4)
@@ -80,11 +81,33 @@ def update_axes(ax, mappable=None):
8081
update_axes(ax)
8182

8283
# %%
84+
# Post analyse
85+
# ------------
8386
# Contours reject from several origin (shape error to high, several extremum in contour, ...)
8487
ax = start_axes("ADT contour reject")
8588
g.contours.display(ax, only_unused=True)
8689
update_axes(ax)
8790

91+
# %%
92+
# Contours reject criterion
93+
#
94+
# 0. - Accepted (green)
95+
# 1. - Reject for shape error (red)
96+
# 2. - Masked value in contour (blue)
97+
# 3. - Under or over pixel limit bound (black)
98+
# 4. - Amplitude criterion (yellow)
99+
ax = start_axes("Contour reject criterion")
100+
g.contours.display(ax, only_unused=True, lw=0.25, display_criterion=True)
101+
update_axes(ax)
102+
103+
# %%
104+
# Display shape error of each tested contour, the limit of shape error is set to 55 %
105+
ax = start_axes("Contour shape error")
106+
m = g.contours.display(
107+
ax, lw=0.5, field="shape_error", bins=arange(20, 90.1, 5), cmap="seismic"
108+
)
109+
update_axes(ax, m)
110+
88111
# %%
89112
# Contours closed which contains several eddies
90113
ax = start_axes("ADT contour reject but which contain eddies")
@@ -116,3 +139,14 @@ def update_axes(ax, mappable=None):
116139
a.scatter(ax, "radius_s", vmin=10, vmax=50, s=80, ref=-10, cmap="jet", factor=0.001)
117140
m = c.scatter(ax, "radius_s", vmin=10, vmax=50, s=80, ref=-10, cmap="jet", factor=0.001)
118141
update_axes(ax, m)
142+
143+
# %%
144+
# Display speed radius of eddies detected
145+
ax = start_axes("Eddies speed radius (km)")
146+
a.filled(
147+
ax, "radius_e", vmin=10, vmax=80, cmap="magma_r", factor=0.001, lut=14, ref=-10
148+
)
149+
m = c.filled(
150+
ax, "radius_e", vmin=10, vmax=80, cmap="magma_r", factor=0.001, lut=14, ref=-10
151+
)
152+
update_axes(ax, m)

examples/02_eddy_identification/pet_eddy_detection_gulf_stream.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
2-
Eddy detection Gulf stream
3-
==========================
2+
Eddy detection : Gulf stream
3+
============================
44
55
Script will detect eddies on adt field, and compute u,v with method add_uv(which could use, only if equator is avoid)
66
77
Figures will show different step to detect eddies.
88
99
"""
10+
from numpy import arange
1011
from datetime import datetime
1112
from matplotlib import pyplot as plt
1213
from py_eddy_tracker.dataset.grid import RegularGridDataset
@@ -72,7 +73,7 @@ def update_axes(ax, mappable=None):
7273
# --------------
7374
# run identification with slice of 2 mm
7475
date = datetime(2016, 5, 15)
75-
a, c = g.eddy_identification("adt", "u", "v", date, 0.002)
76+
a, c = g.eddy_identification("adt", "u", "v", date, 0.002, shape_error=55)
7677

7778
# %%
7879
# All closed contour found in this input grid (Display only 1 contour every 5)
@@ -89,12 +90,34 @@ def update_axes(ax, mappable=None):
8990
update_axes(ax)
9091

9192
# %%
93+
# Post analyse
94+
# ------------
9295
# Contours reject from several origin (shape error to high, several extremum in contour, ...)
9396
ax = start_axes("ADT contour reject")
9497
g.contours.display(ax, only_unused=True, lw=0.25)
9598
great_current.display(ax, color="k")
9699
update_axes(ax)
97100

101+
# %%
102+
# Contours reject criterion
103+
#
104+
# 0. - Accepted (green)
105+
# 1. - Reject for shape error (red)
106+
# 2. - Masked value in contour (blue)
107+
# 3. - Under or over pixel limit bound (black)
108+
# 4. - Amplitude criterion (yellow)
109+
ax = start_axes("Contour reject criterion")
110+
g.contours.display(ax, only_unused=True, lw=0.25, display_criterion=True)
111+
update_axes(ax)
112+
113+
# %%
114+
# Display shape error of each tested contour, the limit of shape error is set to 55 %
115+
ax = start_axes("Contour shape error")
116+
m = g.contours.display(
117+
ax, lw=0.5, field="shape_error", bins=arange(20, 90.1, 5), cmap="seismic"
118+
)
119+
update_axes(ax, m)
120+
98121
# %%
99122
# Contours closed which contains several eddies
100123
ax = start_axes("ADT contour reject but which contain eddies")

notebooks/python_module/02_eddy_identification/pet_eddy_detection.ipynb

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\nEddy detection\n==============\n\nScript will detect eddies on adt field, and compute u,v with method add_uv(which could use, only if equator is avoid)\n\nFigures will show different step to detect eddies.\n"
18+
"\n# Eddy detection : Med\n\nScript will detect eddies on adt field, and compute u,v with method add_uv(which could use, only if equator is avoid)\n\nFigures will show different step to detect eddies.\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"from datetime import datetime\nfrom matplotlib import pyplot as plt\nfrom py_eddy_tracker.dataset.grid import RegularGridDataset\nfrom py_eddy_tracker import data"
29+
"from numpy import arange\nfrom datetime import datetime\nfrom matplotlib import pyplot as plt\nfrom py_eddy_tracker.dataset.grid import RegularGridDataset\nfrom py_eddy_tracker import data"
3030
]
3131
},
3232
{
@@ -37,7 +37,7 @@
3737
},
3838
"outputs": [],
3939
"source": [
40-
"def start_axes(title):\n fig = plt.figure(figsize=(13, 5))\n ax = fig.add_axes([0.03, 0.03, 0.90, 0.94])\n ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\n ax.set_aspect(\"equal\")\n ax.set_title(title)\n return ax\n\n\ndef update_axes(ax, mappable=None):\n ax.grid()\n if mappable:\n plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))"
40+
"def start_axes(title):\n fig = plt.figure(figsize=(13, 5))\n ax = fig.add_axes([0.03, 0.03, 0.90, 0.94])\n ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\n ax.set_aspect(\"equal\")\n ax.set_title(title)\n return ax\n\n\ndef update_axes(ax, mappable=None):\n ax.grid()\n if mappable:\n plt.colorbar(mappable, cax=ax.figure.add_axes([0.94, 0.05, 0.01, 0.9]))"
4141
]
4242
},
4343
{
@@ -62,7 +62,7 @@
6262
"cell_type": "markdown",
6363
"metadata": {},
6464
"source": [
65-
"Get u/v\n-------\nU/V are deduced from ADT, this algortihm are not usable around equator (~+- 2\u00b0)\n\n"
65+
"## Get u/v\nU/V are deduced from ADT, this algortihm are not usable around equator (~+- 2\u00b0)\n\n"
6666
]
6767
},
6868
{
@@ -80,7 +80,7 @@
8080
"cell_type": "markdown",
8181
"metadata": {},
8282
"source": [
83-
"Pre-processings\n---------------\nApply high filter to remove long scale to highlight mesoscale\n\n"
83+
"## Pre-processings\nApply high filter to remove long scale to highlight mesoscale\n\n"
8484
]
8585
},
8686
{
@@ -98,7 +98,7 @@
9898
"cell_type": "markdown",
9999
"metadata": {},
100100
"source": [
101-
"Identification\n--------------\nrun identification with slice of 2 mm\n\n"
101+
"## Identification\nrun identification with slice of 2 mm\n\n"
102102
]
103103
},
104104
{
@@ -109,7 +109,7 @@
109109
},
110110
"outputs": [],
111111
"source": [
112-
"date = datetime(2016, 5, 15)\na, c = g.eddy_identification(\"adt\", \"u\", \"v\", date, 0.002)"
112+
"date = datetime(2016, 5, 15)\na, c = g.eddy_identification(\"adt\", \"u\", \"v\", date, 0.002, shape_error=55)"
113113
]
114114
},
115115
{
@@ -152,7 +152,7 @@
152152
"cell_type": "markdown",
153153
"metadata": {},
154154
"source": [
155-
"Contours reject from several origin (shape error to high, several extremum in contour, ...)\n\n"
155+
"## Post analyse\nContours reject from several origin (shape error to high, several extremum in contour, ...)\n\n"
156156
]
157157
},
158158
{
@@ -166,6 +166,42 @@
166166
"ax = start_axes(\"ADT contour reject\")\ng.contours.display(ax, only_unused=True)\nupdate_axes(ax)"
167167
]
168168
},
169+
{
170+
"cell_type": "markdown",
171+
"metadata": {},
172+
"source": [
173+
"Contours reject criterion\n\n0. - Accepted (green)\n1. - Reject for shape error (red)\n2. - Masked value in contour (blue)\n3. - Under or over pixel limit bound (black)\n4. - Amplitude criterion (yellow)\n\n"
174+
]
175+
},
176+
{
177+
"cell_type": "code",
178+
"execution_count": null,
179+
"metadata": {
180+
"collapsed": false
181+
},
182+
"outputs": [],
183+
"source": [
184+
"ax = start_axes(\"Contour reject criterion\")\ng.contours.display(ax, only_unused=True, lw=0.25, display_criterion=True)\nupdate_axes(ax)"
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"metadata": {},
190+
"source": [
191+
"Display shape error of each tested contour, the limit of shape error is set to 55 %\n\n"
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": null,
197+
"metadata": {
198+
"collapsed": false
199+
},
200+
"outputs": [],
201+
"source": [
202+
"ax = start_axes(\"Contour shape error\")\nm = g.contours.display(\n ax, lw=0.5, field=\"shape_error\", bins=arange(20, 90.1, 5), cmap=\"seismic\"\n)\nupdate_axes(ax, m)"
203+
]
204+
},
169205
{
170206
"cell_type": "markdown",
171207
"metadata": {},
@@ -188,7 +224,7 @@
188224
"cell_type": "markdown",
189225
"metadata": {},
190226
"source": [
191-
"Output\n------\nDisplay detected eddies, dashed lines represent effective contour\nand solid lines represent contour of maximum of speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1\n\n"
227+
"## Output\nDisplay detected eddies, dashed lines represent effective contour\nand solid lines represent contour of maximum of speed. See figure 1 of https://doi.org/10.1175/JTECH-D-14-00019.1\n\n"
192228
]
193229
},
194230
{
@@ -219,6 +255,24 @@
219255
"source": [
220256
"ax = start_axes(\"Eddies speed radius (km)\")\na.scatter(ax, \"radius_s\", vmin=10, vmax=50, s=80, ref=-10, cmap=\"jet\", factor=0.001)\nm = c.scatter(ax, \"radius_s\", vmin=10, vmax=50, s=80, ref=-10, cmap=\"jet\", factor=0.001)\nupdate_axes(ax, m)"
221257
]
258+
},
259+
{
260+
"cell_type": "markdown",
261+
"metadata": {},
262+
"source": [
263+
"Display speed radius of eddies detected\n\n"
264+
]
265+
},
266+
{
267+
"cell_type": "code",
268+
"execution_count": null,
269+
"metadata": {
270+
"collapsed": false
271+
},
272+
"outputs": [],
273+
"source": [
274+
"ax = start_axes(\"Eddies speed radius (km)\")\na.filled(\n ax, \"radius_e\", vmin=10, vmax=80, cmap=\"magma_r\", factor=0.001, lut=14, ref=-10\n)\nm = c.filled(\n ax, \"radius_e\", vmin=10, vmax=80, cmap=\"magma_r\", factor=0.001, lut=14, ref=-10\n)\nupdate_axes(ax, m)"
275+
]
222276
}
223277
],
224278
"metadata": {

notebooks/python_module/02_eddy_identification/pet_eddy_detection_gulf_stream.ipynb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\n# Eddy detection Gulf stream\n\nScript will detect eddies on adt field, and compute u,v with method add_uv(which could use, only if equator is avoid)\n\nFigures will show different step to detect eddies.\n"
18+
"\n# Eddy detection : Gulf stream\n\nScript will detect eddies on adt field, and compute u,v with method add_uv(which could use, only if equator is avoid)\n\nFigures will show different step to detect eddies.\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"from datetime import datetime\nfrom matplotlib import pyplot as plt\nfrom py_eddy_tracker.dataset.grid import RegularGridDataset\nfrom py_eddy_tracker import data\nfrom py_eddy_tracker.eddy_feature import Contours"
29+
"from numpy import arange\nfrom datetime import datetime\nfrom matplotlib import pyplot as plt\nfrom py_eddy_tracker.dataset.grid import RegularGridDataset\nfrom py_eddy_tracker import data\nfrom py_eddy_tracker.eddy_feature import Contours"
3030
]
3131
},
3232
{
@@ -109,7 +109,7 @@
109109
},
110110
"outputs": [],
111111
"source": [
112-
"date = datetime(2016, 5, 15)\na, c = g.eddy_identification(\"adt\", \"u\", \"v\", date, 0.002)"
112+
"date = datetime(2016, 5, 15)\na, c = g.eddy_identification(\"adt\", \"u\", \"v\", date, 0.002, shape_error=55)"
113113
]
114114
},
115115
{
@@ -152,7 +152,7 @@
152152
"cell_type": "markdown",
153153
"metadata": {},
154154
"source": [
155-
"Contours reject from several origin (shape error to high, several extremum in contour, ...)\n\n"
155+
"## Post analyse\nContours reject from several origin (shape error to high, several extremum in contour, ...)\n\n"
156156
]
157157
},
158158
{
@@ -166,6 +166,42 @@
166166
"ax = start_axes(\"ADT contour reject\")\ng.contours.display(ax, only_unused=True, lw=0.25)\ngreat_current.display(ax, color=\"k\")\nupdate_axes(ax)"
167167
]
168168
},
169+
{
170+
"cell_type": "markdown",
171+
"metadata": {},
172+
"source": [
173+
"Contours reject criterion\n\n0. - Accepted (green)\n1. - Reject for shape error (red)\n2. - Masked value in contour (blue)\n3. - Under or over pixel limit bound (black)\n4. - Amplitude criterion (yellow)\n\n"
174+
]
175+
},
176+
{
177+
"cell_type": "code",
178+
"execution_count": null,
179+
"metadata": {
180+
"collapsed": false
181+
},
182+
"outputs": [],
183+
"source": [
184+
"ax = start_axes(\"Contour reject criterion\")\ng.contours.display(ax, only_unused=True, lw=0.25, display_criterion=True)\nupdate_axes(ax)"
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"metadata": {},
190+
"source": [
191+
"Display shape error of each tested contour, the limit of shape error is set to 55 %\n\n"
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": null,
197+
"metadata": {
198+
"collapsed": false
199+
},
200+
"outputs": [],
201+
"source": [
202+
"ax = start_axes(\"Contour shape error\")\nm = g.contours.display(\n ax, lw=0.5, field=\"shape_error\", bins=arange(20, 90.1, 5), cmap=\"seismic\"\n)\nupdate_axes(ax, m)"
203+
]
204+
},
169205
{
170206
"cell_type": "markdown",
171207
"metadata": {},

0 commit comments

Comments
 (0)