Skip to content

Commit 5290549

Browse files
committed
contours display improvement
1 parent 0201274 commit 5290549

File tree

3 files changed

+40
-22
lines changed

3 files changed

+40
-22
lines changed

src/py_eddy_tracker/eddy_feature.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ def get_index_nearest_path_bbox_contain_pt(self, level, xpt, ypt):
493493

494494
def display(self, ax, step=1, only_used=False, only_unused=False, only_contain_eddies=False, **kwargs):
495495
from matplotlib.collections import LineCollection
496-
for collection in self.contours.collections[::step]:
496+
for j, collection in enumerate(self.contours.collections[::step]):
497497
paths = list()
498498
for i in collection.get_paths():
499499
if only_used and not i.used:
@@ -503,7 +503,13 @@ def display(self, ax, step=1, only_used=False, only_unused=False, only_contain_e
503503
elif only_contain_eddies and not i.contain_eddies:
504504
continue
505505
paths.append(i.vertices)
506-
ax.add_collection(LineCollection(paths, color=collection.get_color(), **kwargs))
506+
local_kwargs = kwargs.copy()
507+
if 'color' not in kwargs:
508+
local_kwargs['color'] = collection.get_color()
509+
local_kwargs.pop('label')
510+
elif j != 0:
511+
local_kwargs.pop('label')
512+
ax.add_collection(LineCollection(paths, **local_kwargs))
507513

508514
if hasattr(self.contours, '_mins'):
509515
ax.update_datalim([self.contours._mins, self.contours._maxs])
@@ -516,7 +522,7 @@ def label_contour_unused_which_contain_eddies(self, eddies):
516522
sl = slice(None,-1)
517523
cor = 1
518524
else:
519-
# cylonic
525+
# cyclonic
520526
sl = slice(1, None)
521527
cor = -1
522528

src/py_eddy_tracker/generic.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,25 @@ def uniform_resample(x_val, y_val, num_fac=2, fixed_size=None):
211211
x_new = interp(d_uniform, dist, x_val)
212212
y_new = interp(d_uniform, dist, y_val)
213213
return x_new, y_new
214+
215+
216+
@njit(cache=True)
217+
def flatten_line_matrix(l_matrix):
218+
"""
219+
Flat matrix and add on between each line
220+
Args:
221+
l_matrix: matrix of position
222+
223+
Returns: array with nan between line
224+
"""
225+
nb_line, sampling = l_matrix.shape
226+
final_size = (nb_line - 1) + nb_line * sampling
227+
out = empty(final_size, dtype=l_matrix.dtype)
228+
inc = 0
229+
for i in range(nb_line):
230+
for j in range(sampling):
231+
out[inc] = l_matrix[i,j]
232+
inc += 1
233+
out[inc] = nan
234+
inc += 1
235+
return out

src/py_eddy_tracker/observations/observation.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
ceil
4848
)
4949
from netCDF4 import Dataset
50-
from ..generic import distance_grid, distance
50+
from ..generic import distance_grid, distance, flatten_line_matrix
5151
from .. import VAR_DESCR, VAR_DESCR_inv
5252
import logging
5353
from datetime import datetime
@@ -1169,26 +1169,16 @@ def set_global_attr_netcdf(self, h_nc):
11691169
h_nc.setncattr(key, item)
11701170

11711171
def display(self, ax, ref=None, **kwargs):
1172+
lon_s = flatten_line_matrix(self.obs["contour_lon_s"])
1173+
lat_s = flatten_line_matrix(self.obs["contour_lat_s"])
1174+
lon_e = flatten_line_matrix(self.obs["contour_lon_e"])
1175+
lat_e = flatten_line_matrix(self.obs["contour_lat_e"])
11721176
if ref is None:
1173-
ax.plot(self.obs["contour_lon_s"].T, self.obs["contour_lat_s"].T, **kwargs)
1174-
ax.plot(
1175-
self.obs["contour_lon_e"].T,
1176-
self.obs["contour_lat_e"].T,
1177-
linestyle="-.",
1178-
**kwargs
1179-
)
1177+
ax.plot(lon_s, lat_s, **kwargs)
1178+
ax.plot(lon_e, lat_e, linestyle="-.", **kwargs)
11801179
else:
1181-
ax.plot(
1182-
(self.obs["contour_lon_s"].T - ref) % 360 + ref,
1183-
self.obs["contour_lat_s"].T,
1184-
**kwargs
1185-
)
1186-
ax.plot(
1187-
(self.obs["contour_lon_e"].T - ref) % 360 + ref,
1188-
self.obs["contour_lat_e"].T,
1189-
linestyle="-.",
1190-
**kwargs
1191-
)
1180+
ax.plot((lon_s - ref) % 360 + ref, lat_s, **kwargs)
1181+
ax.plot((lon_e - ref) % 360 + ref, lat_e, linestyle="-.", **kwargs)
11921182

11931183

11941184
class VirtualEddiesObservations(EddiesObservations):

0 commit comments

Comments
 (0)