Skip to content

Commit 85067e5

Browse files
committed
add a function to filter position
1 parent a237a29 commit 85067e5

File tree

11 files changed

+83
-22
lines changed

11 files changed

+83
-22
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Grid Manipulation
2+
=======================
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Select pixel in eddies
3+
======================
4+
5+
"""
6+
7+
from matplotlib import pyplot as plt
8+
from matplotlib.path import Path
9+
from numpy import ones
10+
from py_eddy_tracker.observations.observation import EddiesObservations, custom_concat
11+
from py_eddy_tracker.dataset.grid import RegularGridDataset
12+
from py_eddy_tracker import data
13+
14+
a = EddiesObservations.load_file(data.get_path("Anticyclonic_20190223.nc"))
15+
g = RegularGridDataset(
16+
data.get_path("nrt_global_allsat_phy_l4_20190223_20190226.nc"),
17+
"longitude",
18+
"latitude",
19+
)
20+
21+
# Plot
22+
fig = plt.figure(figsize=(12, 6))
23+
ax = fig.add_axes((0.05, 0.05, 0.9, 0.9))
24+
ax.set_aspect("equal")
25+
ax.set_xlim(10, 70)
26+
ax.set_ylim(-50, -25)
27+
x_name, y_name = a.intern(False)
28+
adt = g.grid("adt")
29+
mask = ones(adt.shape, dtype='bool')
30+
for eddy in a:
31+
i, j = Path(custom_concat(eddy[x_name], eddy[y_name])).pixels_in(g)
32+
mask[i, j] = False
33+
adt.mask[:] += ~mask
34+
g.display(ax, "adt")
35+
a.display(ax, label="Anticyclonic", color="g", lw=1, extern_only=True)
36+
37+
fig = plt.figure(figsize=(12, 6))
38+
ax = fig.add_axes((0.05, 0.05, 0.9, 0.9))
39+
ax.set_aspect("equal")
40+
ax.set_xlim(10, 70)
41+
ax.set_ylim(-50, -25)
42+
adt.mask[:] = mask
43+
g.display(ax, "adt")
44+
a.display(ax, label="Anticyclonic", color="g", lw=1, extern_only=True)
File renamed without changes.
File renamed without changes.

examples/00_tracking_manipulation/pet_display_track.py renamed to examples/08_tracking_manipulation/pet_display_track.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
a = a.extract_with_length((7 * 20, -1))
1919
c = c.extract_with_length((7 * 20, -1))
20-
a.median_filter(1, 'time', 'lon').loess_filter(5, 'time', 'lon')
21-
a.median_filter(1, 'time', 'lat').loess_filter(5, 'time', 'lat')
22-
c.median_filter(1, 'time', 'lon').loess_filter(5, 'time', 'lon')
23-
c.median_filter(1, 'time', 'lat').loess_filter(5, 'time', 'lat')
24-
20+
a.position_filter(median_half_window=1, loess_half_window=5)
21+
c.position_filter(median_half_window=1, loess_half_window=5)
2522

2623
# Plot
2724
fig = plt.figure(figsize=(12, 5))

examples/00_tracking_manipulation/pet_one_track.py renamed to examples/08_tracking_manipulation/pet_one_track.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@
1313

1414
eddy = a.extract_ids([9672])
1515
eddy_f = a.extract_ids([9672])
16-
eddy_f.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
17-
eddy_f.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
16+
eddy_f.position_filter(median_half_window=1, loess_half_window=5)
17+
1818
fig = plt.figure(figsize=(12, 5))
19-
ax = fig.add_axes((0.05, 0.1, 0.9, 0.9))
19+
ax = fig.add_axes((0.05, 0.05, 0.9, 0.9))
2020
ax.set_xlim(17.5, 22)
2121
ax.set_ylim(35, 36.5)
2222
ax.set_aspect("equal")
2323
ax.grid()
2424
eddy.plot(ax, color="r", lw=0.5)
25-
eddy_f.plot(ax, color="g", lw=1)
25+
eddy_f.scatter(ax, "n", cmap="jet", s=80)
26+
27+
fig = plt.figure(figsize=(12, 5))
28+
ax = fig.add_axes((0.05, 0.05, 0.9, 0.9))
29+
ax.set_xlim(17, 23)
30+
ax.set_ylim(34.5, 37)
31+
ax.set_aspect("equal")
32+
ax.grid()
33+
eddy.plot(ax, color="r", lw=0.5, label='track')
34+
eddy.index(range(0, len(eddy), 40)).display(ax, intern_only=True, label='observations every 40')
35+
ax.legend()

examples/00_tracking_manipulation/pet_select_track_across_area.py renamed to examples/08_tracking_manipulation/pet_select_track_across_area.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
c = TrackEddiesObservations.load_file(
1111
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
1212
)
13-
c.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
14-
c.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
13+
c.position_filter(median_half_window=1, loess_half_window=5)
1514
x0, x1, y0, y1 = 3, 4, 37, 38
1615
area = dict(llcrnrlon=x0, llcrnrlat=y0, urcrnrlon=x1, urcrnrlat=y1)
1716
c_subset = c.extract_with_area(area, full_path=True)

examples/10_tracking_diagnostics/pet_propagation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ def cum_distance_by_track(distance, track):
3434
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
3535
)
3636

37-
a.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
38-
a.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
39-
c.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
40-
c.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
37+
a.position_filter(median_half_window=1, loess_half_window=5)
38+
c.position_filter(median_half_window=1, loess_half_window=5)
4139

4240
d_a = distance(a.longitude[:-1], a.latitude[:-1], a.longitude[1:], a.latitude[1:])
4341
d_c = distance(c.longitude[:-1], c.latitude[:-1], c.longitude[1:], c.latitude[1:])
File renamed without changes.

src/py_eddy_tracker/observations/observation.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,26 +1247,29 @@ def scatter(self, ax, name, ref=None, ** kwargs):
12471247
x = (x - ref) % 360 + ref
12481248
return ax.scatter(x, self.latitude, c=self[name], **kwargs)
12491249

1250-
def display(self, ax, ref=None, extern_only=False, **kwargs):
1250+
def display(self, ax, ref=None, extern_only=False, intern_only=False, **kwargs):
12511251
if not extern_only:
12521252
lon_s = flatten_line_matrix(self.obs["contour_lon_s"])
12531253
lat_s = flatten_line_matrix(self.obs["contour_lat_s"])
1254-
lon_e = flatten_line_matrix(self.obs["contour_lon_e"])
1255-
lat_e = flatten_line_matrix(self.obs["contour_lat_e"])
1254+
if not intern_only:
1255+
lon_e = flatten_line_matrix(self.obs["contour_lon_e"])
1256+
lat_e = flatten_line_matrix(self.obs["contour_lat_e"])
12561257
if "label" in kwargs:
1257-
kwargs["label"] += " (%s eddies)" % len(self)
1258+
kwargs["label"] += " (%s observations)" % len(self)
12581259
kwargs_e = kwargs.copy()
12591260
if not extern_only:
12601261
kwargs_e.pop("label", None)
12611262
if ref is None:
12621263
if not extern_only:
12631264
ax.plot(lon_s, lat_s, **kwargs)
1264-
ax.plot(lon_e, lat_e, linestyle="-.", **kwargs_e)
1265+
if not intern_only:
1266+
ax.plot(lon_e, lat_e, linestyle="-.", **kwargs_e)
12651267
else:
12661268
# FIXME : ref could split eddies
12671269
if not extern_only:
12681270
ax.plot((lon_s - ref) % 360 + ref, lat_s, **kwargs)
1269-
ax.plot((lon_e - ref) % 360 + ref, lat_e, linestyle="-.", **kwargs_e)
1271+
if not intern_only:
1272+
ax.plot((lon_e - ref) % 360 + ref, lat_e, linestyle="-.", **kwargs_e)
12701273

12711274
def grid_count(self, bins, intern=False, center=False):
12721275
x_name, y_name = self.intern(intern)

0 commit comments

Comments
 (0)