Skip to content

Commit 8a21bdc

Browse files
committed
Last correction of identification code to solve x bounds problem, contour was mis-weigthed and test of poly which contain poly was inssuficient around x bounds
1 parent 6cceb97 commit 8a21bdc

File tree

9 files changed

+29
-25
lines changed

9 files changed

+29
-25
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ for tracking.
4040
Loading grid
4141
```python
4242
from py_eddy_tracker.dataset.grid import RegularGridDataset
43-
h = RegularGridDataset('share/nrt_global_allsat_phy_l4_20190223_20190226.nc', 'longitude', 'latitude')
43+
grid_name, lon_name, lat_name = 'share/nrt_global_allsat_phy_l4_20190223_20190226.nc', 'longitude', 'latitude'
44+
h = RegularGridDataset(grid_name, lon_name, lat_name)
4445
```
4546

4647
Plotting grid
@@ -51,13 +52,14 @@ ax = fig.add_axes([.02, .51, .9, .45])
5152
ax.set_title('ADT (m)')
5253
ax.set_ylim(-75, 75)
5354
ax.set_aspect('equal')
54-
m=ax.pcolormesh(h.x_bounds, h.y_bounds, h.grid('adt').T.copy(), vmin=-1, vmax=1, cmap='coolwarm')
55+
m = h.display(ax, name='adt', vmin=-1, vmax=1)
5556
ax.grid(True)
5657
plt.colorbar(m, cax=fig.add_axes([.94, .51, .01, .45]))
5758
```
5859

5960
Filtering
6061
```python
62+
h = RegularGridDataset(grid_name, lon_name, lat_name)
6163
h.bessel_high_filter('adt', 500, order=3)
6264
```
6365

@@ -72,7 +74,7 @@ ax = fig.add_axes([.02, .02, .9, .45])
7274
ax.set_title('ADT Filtered (m)')
7375
ax.set_aspect('equal')
7476
ax.set_ylim(-75, 75)
75-
m=ax.pcolormesh(h.x_bounds, h.y_bounds, h.grid('adt').T, vmin=-.1, vmax=.1, cmap='coolwarm')
77+
m = h.display(ax, name='adt', vmin=-.1, vmax=.1)
7678
ax.grid(True)
7779
plt.colorbar(m, cax=fig.add_axes([.94, .02, .01, .45]))
7880
fig.savefig('share/png/filter.png')
@@ -83,7 +85,6 @@ fig.savefig('share/png/filter.png')
8385
#### Compute spectrum and spectrum ratio on some area ####
8486
Load data
8587
```python
86-
grid_name, lon_name, lat_name = 'share/nrt_global_allsat_phy_l4_20190223_20190226.nc', 'longitude', 'latitude'
8788
raw = RegularGridDataset(grid_name, lon_name, lat_name)
8889
filtered = RegularGridDataset(grid_name, lon_name, lat_name)
8990
filtered.bessel_low_filter('adt', 150, order=3)
@@ -169,8 +170,8 @@ ax.set_title('Eddies detected -- Cyclonic(red) and Anticyclonic(blue)')
169170
ax.set_ylim(-75,75)
170171
ax.set_xlim(0,360)
171172
ax.set_aspect('equal')
172-
ax.plot(a.obs['contour_lon_s'].T, a.obs['contour_lat_s'].T, 'b', linewidth=.5)
173-
ax.plot(c.obs['contour_lon_s'].T, c.obs['contour_lat_s'].T, 'r', linewidth=.5)
173+
a.display(ax, color='b', linewidth=.5)
174+
c.display(ax, color='r', linewidth=.5)
174175
ax.grid()
175176
fig.savefig('share/png/eddies.png')
176177
```
13 KB
Binary file not shown.

share/png/eddies.png

127 KB
Loading

share/png/filter.png

94 Bytes
Loading

src/py_eddy_tracker/dataset/grid.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,22 @@ def raw_resample(datas, fixed_size):
3434

3535
@property
3636
def mean_coordinates(self):
37-
return self.vertices.mean(axis=0)
38-
39-
40-
BasePath.mean_coordinates = mean_coordinates
37+
# last coordinates == first
38+
return self.vertices[1:].mean(axis=0)
4139

4240

4341
@property
4442
def lon(self):
4543
return self.vertices[:, 0]
4644

4745

48-
BasePath.lon = lon
49-
50-
5146
@property
5247
def lat(self):
5348
return self.vertices[:, 1]
5449

5550

51+
BasePath.mean_coordinates = mean_coordinates
52+
BasePath.lon = lon
5653
BasePath.lat = lat
5754

5855

@@ -89,7 +86,8 @@ def fit_circle_path(self):
8986
@njit(cache=True, fastmath=True)
9087
def _fit_circle_path(vertice):
9188
lons, lats = vertice[:, 0], vertice[:, 1]
92-
lon0, lat0 = lons.mean(), lats.mean()
89+
# last coordinates == first
90+
lon0, lat0 = lons[1:].mean(), lats[1:].mean()
9391
c_x, c_y = coordinates_to_local(lons, lats, lon0, lat0)
9492
# Some time, edge is only a dot of few coordinates
9593
d_lon = lons.max() - lons.min()

src/py_eddy_tracker/eddy_feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def find_wrapcut_path_and_join(self, x0, x1):
309309
path_left.vertices[-1, 1] - path_right.vertices[0, 1]) < self.DELTA_PREC:
310310
polys_to_pop_left.append(i_left)
311311
path_right.vertices[:, 0] -= 360
312-
path_left.vertices = concatenate((path_left.vertices, path_right.vertices))
312+
path_left.vertices = concatenate((path_left.vertices, path_right.vertices[1:]))
313313
path_left.vertices[-1] = path_left.vertices[0]
314314
paths_solve.append(path_left)
315315
paths_right.pop(i_right)

src/py_eddy_tracker/generic.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,19 @@ def fit_circle(x_vec, y_vec):
128128
p_inon_x = empty(nb_elt)
129129
p_inon_y = empty(nb_elt)
130130

131-
x_mean = x_vec.mean()
132-
y_mean = y_vec.mean()
131+
# last coordinates == first
132+
x_mean = x_vec[1:].mean()
133+
y_mean = y_vec[1:].mean()
133134

134-
norme = (x_vec - x_mean) ** 2 + (y_vec - y_mean) ** 2
135+
norme = (x_vec[1:] - x_mean) ** 2 + (y_vec[1:] - y_mean) ** 2
135136
norme_max = norme.max()
136137
scale = norme_max ** .5
137138

138139
# Form matrix equation and solve it
139140
# Maybe put f4
140-
datas = ones((nb_elt, 3))
141-
datas[:, 0] = 2. * (x_vec - x_mean) / scale
142-
datas[:, 1] = 2. * (y_vec - y_mean) / scale
141+
datas = ones((nb_elt - 1, 3))
142+
datas[:, 0] = 2. * (x_vec[1:] - x_mean) / scale
143+
datas[:, 1] = 2. * (y_vec[1:] - y_mean) / scale
143144

144145
(center_x, center_y, radius), residuals, rank, s = lstsq(datas, norme / norme_max)
145146

src/py_eddy_tracker/observations.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,13 @@ def write_netcdf(self, path='./', filename='%(path)s/%(sign_type)s.nc'):
728728
def set_global_attr_netcdf(self, h_nc):
729729
pass
730730

731-
def display(self, ax, ref=0, **kwargs):
732-
ax.plot((self.obs['contour_lon_s'].T - ref) % 360 + ref, self.obs['contour_lat_s'].T, ** kwargs)
733-
ax.plot((self.obs['contour_lon_e'].T - ref) % 360 + ref, self.obs['contour_lat_e'].T, linestyle='-.', ** kwargs)
731+
def display(self, ax, ref=None, **kwargs):
732+
if ref is None:
733+
ax.plot(self.obs['contour_lon_s'].T, self.obs['contour_lat_s'].T, ** kwargs)
734+
ax.plot(self.obs['contour_lon_e'].T, self.obs['contour_lat_e'].T, linestyle='-.', ** kwargs)
735+
else:
736+
ax.plot((self.obs['contour_lon_s'].T - ref) % 360 + ref, self.obs['contour_lat_s'].T, ** kwargs)
737+
ax.plot((self.obs['contour_lon_e'].T - ref) % 360 + ref, self.obs['contour_lat_e'].T, linestyle='-.', ** kwargs)
734738

735739

736740
@njit(cache=True, fastmath=True)

src/py_eddy_tracker/poly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def poly_contain_poly(xy_poly_out, xy_poly_in):
2828
x_ref = xy_poly_out[0,0]
2929
d_x = abs(x[0] - x_ref)
3030
if d_x > 180:
31-
x = (x - x_ref + 180) % 360 - 180
31+
x = (x - x_ref + 180) % 360 + x_ref - 180
3232
for i_elt in prange(nb_elt):
3333
wn = winding_number_poly(x[i_elt], xy_poly_in[i_elt, 1], xy_poly_out)
3434
if wn == 0:

0 commit comments

Comments
 (0)