Skip to content

Commit 7b47028

Browse files
add filter to grid_stat and grid_count (AntSimi#36)
1 parent d65f414 commit 7b47028

File tree

15 files changed

+110
-113
lines changed

15 files changed

+110
-113
lines changed

examples/02_eddy_identification/pet_filter_and_detection.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def update_axes(ax, mappable=None):
3333
# Add a new filed to store the high-pass filtered ADT
3434

3535
g = RegularGridDataset(
36-
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"),
37-
"longitude",
38-
"latitude",
36+
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude",
3937
)
4038
g.add_uv("adt")
4139
g.copy("adt", "adt_high")

examples/02_eddy_identification/pet_sla_and_adt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def update_axes(ax, mappable=None):
3131
# Load Input grid, ADT will be used to detect eddies
3232

3333
g = RegularGridDataset(
34-
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"),
35-
"longitude",
36-
"latitude",
34+
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude",
3735
)
3836
g.add_uv("adt", "ugos", "vgos")
3937
g.add_uv("sla", "ugosa", "vgosa")

examples/06_grid_manipulation/pet_filter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def update_axes(ax, mappable=None):
3232
# %%
3333
# All information will be for regular grid
3434
g = RegularGridDataset(
35-
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"),
36-
"longitude",
37-
"latitude",
35+
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude",
3836
)
3937
# %%
4038
# Kernel

examples/08_tracking_manipulation/pet_select_track_across_area.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,8 @@
3232
c.plot(ax, color="gray", lw=0.1, ref=-10, label="all tracks")
3333
c_subset.plot(ax, color="red", lw=0.2, ref=-10, label="selected tracks")
3434
ax.plot(
35-
(
36-
x0,
37-
x0,
38-
x1,
39-
x1,
40-
x0,
41-
),
42-
(
43-
y0,
44-
y1,
45-
y1,
46-
y0,
47-
y0,
48-
),
35+
(x0, x0, x1, x1, x0,),
36+
(y0, y1, y1, y0, y0,),
4937
color="green",
5038
lw=1.5,
5139
label="Box of selection",

examples/10_tracking_diagnostics/pet_center_count.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,21 @@
6868
ax.set_aspect("equal")
6969
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
7070
ax.grid()
71+
72+
# %%
73+
# Count Anticyclones as a function of lifetime
74+
# --------------------------------------------
75+
# Count at the center's position
76+
77+
fig = plt.figure(figsize=(12, 10))
78+
ax = fig.add_subplot(211)
79+
g_a = a.grid_count(bins, center=True, filter=a.lifetime >= 30)
80+
m = g_a.display(ax, **kwargs_pcolormesh)
81+
ax.set_aspect("equal")
82+
ax.set_title("Anticyclones with lifetime >= 30 days")
83+
cb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.1, 0.015, 0.8]))
84+
ax = fig.add_subplot(212)
85+
g_a = a.grid_count(bins, center=True, filter=a.lifetime < 30)
86+
m = g_a.display(ax, **kwargs_pcolormesh)
87+
ax.set_aspect("equal")
88+
ax.set_title("Anticyclones with lifetime < 30 days")

examples/10_tracking_diagnostics/pet_pixel_used.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,20 @@
6464
ax.set_aspect("equal")
6565
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
6666
ax.grid()
67+
68+
# %%
69+
# Count Anticyclones as a function of lifetime
70+
# --------------------------------------------
71+
72+
fig = plt.figure(figsize=(12, 10))
73+
ax = fig.add_subplot(211)
74+
g_a = a.grid_count(bins, intern=True, filter=a.lifetime >= 30)
75+
m = g_a.display(ax, **kwargs_pcolormesh)
76+
ax.set_aspect("equal")
77+
ax.set_title("Anticyclones with lifetime >= 30 days")
78+
cb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.1, 0.015, 0.8]))
79+
ax = fig.add_subplot(212)
80+
g_a = a.grid_count(bins, intern=True, filter=a.lifetime < 30)
81+
m = g_a.display(ax, **kwargs_pcolormesh)
82+
ax.set_aspect("equal")
83+
ax.set_title("Anticyclones with lifetime < 30 days")

notebooks/python_module/10_tracking_diagnostics/pet_center_count.ipynb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"from matplotlib import pyplot as plt\nfrom matplotlib.colors import LogNorm\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations\nimport py_eddy_tracker_sample"
29+
"import py_eddy_tracker_sample\nfrom matplotlib import pyplot as plt\nfrom matplotlib.colors import LogNorm\n\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations"
3030
]
3131
},
3232
{
@@ -64,6 +64,24 @@
6464
"source": [
6565
"fig = plt.figure(figsize=(12, 18.5))\nax_a = fig.add_axes([0.03, 0.75, 0.90, 0.25])\nax_a.set_title(\"Anticyclonic center frequency\")\nax_c = fig.add_axes([0.03, 0.5, 0.90, 0.25])\nax_c.set_title(\"Cyclonic center frequency\")\nax_all = fig.add_axes([0.03, 0.25, 0.90, 0.25])\nax_all.set_title(\"All eddies center frequency\")\nax_ratio = fig.add_axes([0.03, 0.0, 0.90, 0.25])\nax_ratio.set_title(\"Ratio cyclonic / Anticyclonic\")\n\n# Count pixel used for each center\ng_a = a.grid_count(bins, intern=True, center=True)\ng_a.display(ax_a, **kwargs_pcolormesh)\ng_c = c.grid_count(bins, intern=True, center=True)\ng_c.display(ax_c, **kwargs_pcolormesh)\n# Compute a ratio Cyclonic / Anticyclonic\nratio = g_c.vars[\"count\"] / g_a.vars[\"count\"]\n\n# Mask manipulation to be able to sum the 2 grids\nm_c = g_c.vars[\"count\"].mask\nm = m_c & g_a.vars[\"count\"].mask\ng_c.vars[\"count\"][m_c] = 0\ng_c.vars[\"count\"] += g_a.vars[\"count\"]\ng_c.vars[\"count\"].mask = m\n\nm = g_c.display(ax_all, **kwargs_pcolormesh)\ncb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.27, 0.01, 0.7]))\ncb.set_label(\"Eddies by 1\u00b0^2 by day\")\n\ng_c.vars[\"count\"] = ratio\nm = g_c.display(\n ax_ratio, name=\"count\", vmin=0.1, vmax=10, norm=LogNorm(), cmap=\"coolwarm_r\"\n)\nplt.colorbar(m, cax=fig.add_axes([0.94, 0.02, 0.01, 0.2]))\n\nfor ax in (ax_a, ax_c, ax_all, ax_ratio):\n ax.set_aspect(\"equal\")\n ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\n ax.grid()"
6666
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"## Count Anticyclones as a function of lifetime\nCount at the center's position\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"fig = plt.figure(figsize=(12, 10))\nax = fig.add_subplot(211)\ng_a = a.grid_count(bins, center=True, filter=a.lifetime >= 30)\nm = g_a.display(ax, **kwargs_pcolormesh)\nax.set_aspect(\"equal\")\nax.set_title(\"Anticyclones with lifetime >= 30 days\")\ncb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.1, 0.015, 0.8]))\nax = fig.add_subplot(212)\ng_a = a.grid_count(bins, center=True, filter=a.lifetime < 30)\nm = g_a.display(ax, **kwargs_pcolormesh)\nax.set_aspect(\"equal\")\nax.set_title(\"Anticyclones with lifetime < 30 days\")"
84+
]
6785
}
6886
],
6987
"metadata": {
@@ -82,7 +100,7 @@
82100
"name": "python",
83101
"nbconvert_exporter": "python",
84102
"pygments_lexer": "ipython3",
85-
"version": "3.7.7"
103+
"version": "3.7.6"
86104
}
87105
},
88106
"nbformat": 4,

notebooks/python_module/10_tracking_diagnostics/pet_pixel_used.ipynb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"from matplotlib import pyplot as plt\nfrom matplotlib.colors import LogNorm\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations\nimport py_eddy_tracker_sample"
29+
"import py_eddy_tracker_sample\nfrom matplotlib import pyplot as plt\nfrom matplotlib.colors import LogNorm\n\nfrom py_eddy_tracker.observations.tracking import TrackEddiesObservations"
3030
]
3131
},
3232
{
@@ -64,6 +64,24 @@
6464
"source": [
6565
"fig = plt.figure(figsize=(12, 18.5))\nax_a = fig.add_axes([0.03, 0.75, 0.90, 0.25])\nax_a.set_title(\"Anticyclonic frequency\")\nax_c = fig.add_axes([0.03, 0.5, 0.90, 0.25])\nax_c.set_title(\"Cyclonic frequency\")\nax_all = fig.add_axes([0.03, 0.25, 0.90, 0.25])\nax_all.set_title(\"All eddies frequency\")\nax_ratio = fig.add_axes([0.03, 0.0, 0.90, 0.25])\nax_ratio.set_title(\"Ratio cyclonic / Anticyclonic\")\n\n# Count pixel used for each contour\ng_a = a.grid_count(bins, intern=True)\ng_a.display(ax_a, **kwargs_pcolormesh)\ng_c = c.grid_count(bins, intern=True)\ng_c.display(ax_c, **kwargs_pcolormesh)\n# Compute a ratio Cyclonic / Anticyclonic\nratio = g_c.vars[\"count\"] / g_a.vars[\"count\"]\n\n# Mask manipulation to be able to sum the 2 grids\nm_c = g_c.vars[\"count\"].mask\nm = m_c & g_a.vars[\"count\"].mask\ng_c.vars[\"count\"][m_c] = 0\ng_c.vars[\"count\"] += g_a.vars[\"count\"]\ng_c.vars[\"count\"].mask = m\n\nm = g_c.display(ax_all, **kwargs_pcolormesh)\nplt.colorbar(m, cax=fig.add_axes([0.95, 0.27, 0.01, 0.7]))\n\ng_c.vars[\"count\"] = ratio\nm = g_c.display(\n ax_ratio, name=\"count\", vmin=0.1, vmax=10, norm=LogNorm(), cmap=\"coolwarm_r\"\n)\nplt.colorbar(m, cax=fig.add_axes([0.95, 0.02, 0.01, 0.2]))\n\nfor ax in (ax_a, ax_c, ax_all, ax_ratio):\n ax.set_aspect(\"equal\")\n ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\n ax.grid()"
6666
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"## Count Anticyclones as a function of lifetime\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"fig = plt.figure(figsize=(12, 10))\nax = fig.add_subplot(211)\ng_a = a.grid_count(bins, intern=True, filter=a.lifetime >= 30)\nm = g_a.display(ax, **kwargs_pcolormesh)\nax.set_aspect(\"equal\")\nax.set_title(\"Anticyclones with lifetime >= 30 days\")\ncb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.1, 0.015, 0.8]))\nax = fig.add_subplot(212)\ng_a = a.grid_count(bins, intern=True, filter=a.lifetime < 30)\nm = g_a.display(ax, **kwargs_pcolormesh)\nax.set_aspect(\"equal\")\nax.set_title(\"Anticyclones with lifetime < 30 days\")"
84+
]
6785
}
6886
],
6987
"metadata": {
@@ -82,7 +100,7 @@
82100
"name": "python",
83101
"nbconvert_exporter": "python",
84102
"pygments_lexer": "ipython3",
85-
"version": "3.7.7"
103+
"version": "3.7.6"
86104
}
87105
},
88106
"nbformat": 4,

src/py_eddy_tracker/__init__.py

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ def parse_args(self, *args, **kwargs):
149149
output_type="uint16",
150150
scale_factor=50.0,
151151
nc_dims=("obs",),
152-
nc_attr=dict(
153-
long_name="Distance to next position",
154-
units="m",
155-
),
152+
nc_attr=dict(long_name="Distance to next position", units="m",),
156153
),
157154
virtual=dict(
158155
attr_name=None,
@@ -304,18 +301,14 @@ def parse_args(self, *args, **kwargs):
304301
nc_name="i",
305302
nc_type="uint16",
306303
nc_dims=("obs",),
307-
nc_attr=dict(
308-
long_name="Longitude index in the grid of the detection",
309-
),
304+
nc_attr=dict(long_name="Longitude index in the grid of the detection",),
310305
),
311306
j=dict(
312307
attr_name="j",
313308
nc_name="j",
314309
nc_type="uint16",
315310
nc_dims=("obs",),
316-
nc_attr=dict(
317-
long_name="Latitude index in the grid of the detection",
318-
),
311+
nc_attr=dict(long_name="Latitude index in the grid of the detection",),
319312
),
320313
eke=dict(
321314
attr_name="eke",
@@ -364,8 +357,7 @@ def parse_args(self, *args, **kwargs):
364357
nc_type="uint32",
365358
nc_dims=("obs",),
366359
nc_attr=dict(
367-
long_name="Trajectory number",
368-
comment="Trajectory identification number",
360+
long_name="Trajectory number", comment="Trajectory identification number",
369361
),
370362
),
371363
sub_track=dict(
@@ -374,8 +366,7 @@ def parse_args(self, *args, **kwargs):
374366
nc_type="uint32",
375367
nc_dims=("obs",),
376368
nc_attr=dict(
377-
long_name="Segment Number",
378-
comment="Segment number inside a group",
369+
long_name="Segment Number", comment="Segment number inside a group",
379370
),
380371
),
381372
n=dict(
@@ -498,11 +489,7 @@ def parse_args(self, *args, **kwargs):
498489
output_type="u1",
499490
scale_factor=0.4,
500491
nc_dims=("obs",),
501-
nc_attr=dict(
502-
units="%",
503-
comment="score",
504-
long_name="Score",
505-
),
492+
nc_attr=dict(units="%", comment="score", long_name="Score",),
506493
),
507494
index_other=dict(
508495
attr_name=None,
@@ -571,10 +558,7 @@ def parse_args(self, *args, **kwargs):
571558
old_nc_name=["Chl"],
572559
nc_type="f4",
573560
nc_dims=("obs",),
574-
nc_attr=dict(
575-
long_name="Log base 10 chlorophyll",
576-
units="Log(Chl/[mg/m^3])",
577-
),
561+
nc_attr=dict(long_name="Log base 10 chlorophyll", units="Log(Chl/[mg/m^3])",),
578562
),
579563
dchl=dict(
580564
attr_name=None,
@@ -594,8 +578,7 @@ def parse_args(self, *args, **kwargs):
594578
nc_type="f4",
595579
nc_dims=("obs",),
596580
nc_attr=dict(
597-
long_name="Log base 10 background chlorophyll",
598-
units="Log(Chl/[mg/m^3])",
581+
long_name="Log base 10 background chlorophyll", units="Log(Chl/[mg/m^3])",
599582
),
600583
),
601584
year=dict(
@@ -604,32 +587,23 @@ def parse_args(self, *args, **kwargs):
604587
old_nc_name=["Year"],
605588
nc_type="u2",
606589
nc_dims=("obs",),
607-
nc_attr=dict(
608-
long_name="Year",
609-
units="year",
610-
),
590+
nc_attr=dict(long_name="Year", units="year",),
611591
),
612592
month=dict(
613593
attr_name=None,
614594
nc_name="month",
615595
old_nc_name=["Month"],
616596
nc_type="u1",
617597
nc_dims=("obs",),
618-
nc_attr=dict(
619-
long_name="Month",
620-
units="month",
621-
),
598+
nc_attr=dict(long_name="Month", units="month",),
622599
),
623600
day=dict(
624601
attr_name=None,
625602
nc_name="day",
626603
old_nc_name=["Day"],
627604
nc_type="u1",
628605
nc_dims=("obs",),
629-
nc_attr=dict(
630-
long_name="Day",
631-
units="day",
632-
),
606+
nc_attr=dict(long_name="Day", units="day",),
633607
),
634608
nb_contour_selected=dict(
635609
attr_name=None,

src/py_eddy_tracker/appli/network.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
def build_network():
2222
parser = EddyParser("Merge eddies")
2323
parser.add_argument(
24-
"identification_regex",
25-
help="Give an expression which will use with glob",
24+
"identification_regex", help="Give an expression which will use with glob",
2625
)
2726
parser.add_argument("out", help="output file")
2827
parser.add_argument(
@@ -294,11 +293,7 @@ def display_network(x, y, tr, t, c):
294293
lw=0.5,
295294
)
296295
ax_time.plot(
297-
t[sl],
298-
tr[s].repeat(e - s),
299-
color=color,
300-
lw=1,
301-
marker="+",
296+
t[sl], tr[s].repeat(e - s), color=color, lw=1, marker="+",
302297
)
303298
ax_time.text(t[s], tr[s] + 0.15, f"{x[s].mean():.2f}, {y[s].mean():.2f}")
304299
ax_time.axvline(t[s], color=".75", lw=0.5, ls="--", zorder=-10)

0 commit comments

Comments
 (0)