Skip to content

Commit 3359eda

Browse files
committed
Add ref in display_color
1 parent 943bbf3 commit 3359eda

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/py_eddy_tracker/generic.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,17 +456,18 @@ def wrap_longitude(x, y, ref, cut=False):
456456
if cut:
457457
indexs = list()
458458
nb = x.shape[0]
459-
new_previous = (x[0] - ref) % 360
459+
460+
new_x_previous = (x[0] - ref) % 360 + ref
460461
x_previous = x[0]
461462
for i in range(1, nb):
462463
x_ = x[i]
463-
new_x = (x_ - ref) % 360
464+
new_x = (x_ - ref) % 360 + ref
464465
if not isnan(x_) and not isnan(x_previous):
465-
d_new = new_x - new_previous
466+
d_new = new_x - new_x_previous
466467
d = x_ - x_previous
467468
if abs(d - d_new) > 1e-5:
468469
indexs.append(i)
469-
x_previous, new_previous = x_, new_x
470+
x_previous, new_x_previous = x_, new_x
470471

471472
nb_indexs = len(indexs)
472473
new_size = nb + nb_indexs * 3
@@ -477,6 +478,7 @@ def wrap_longitude(x, y, ref, cut=False):
477478
for i in range(nb):
478479
if j < nb_indexs and i == indexs[j]:
479480
j += 1
481+
# FIXME need check
480482
cor = 360 if x[i - 1] > x[i] else -360
481483
out_x[i + i_] = (x[i] - ref) % 360 + ref - cor
482484
out_y[i + i_] = y[i]

src/py_eddy_tracker/observations/observation.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,18 +2069,26 @@ def format_label(self, label):
20692069
nb_obs=len(self),
20702070
)
20712071

2072-
def display_color(self, ax, field, intern=False, **kwargs):
2072+
def display_color(self, ax, field, ref=None, intern=False, **kwargs):
20732073
"""Plot colored contour of eddies
20742074
20752075
:param matplotlib.axes.Axes ax: matplotlib axe used to draw
20762076
:param str,array field: color field
2077+
:param float,None ref: if defined, all coordinates are wrapped with ref as western boundary
20772078
:param bool intern: if True, draw the speed contour
20782079
:param dict kwargs: look at :py:meth:`matplotlib.collections.LineCollection`
20792080
20802081
.. minigallery:: py_eddy_tracker.EddiesObservations.display_color
20812082
"""
20822083
xname, yname = self.intern(intern)
20832084
x, y = self[xname], self[yname]
2085+
2086+
if ref is not None:
2087+
# TODO : maybe buggy with global display
2088+
shape_out = x.shape
2089+
x, y = wrap_longitude(x.reshape(-1), y.reshape(-1), ref)
2090+
x, y = x.reshape(shape_out), y.reshape(shape_out)
2091+
20842092
c = self.parse_varname(field)
20852093
cmap = get_cmap(kwargs.pop("cmap", "Spectral_r"))
20862094
cmin, cmax = kwargs.pop("vmin", c.min()), kwargs.pop("vmax", c.max())
@@ -2089,6 +2097,8 @@ def display_color(self, ax, field, intern=False, **kwargs):
20892097
[create_vertice(i, j) for i, j in zip(x, y)], colors=colors, **kwargs
20902098
)
20912099
ax.add_collection(lines)
2100+
lines.cmap = cmap
2101+
lines.norm = Normalize(vmin=cmin, vmax=cmax)
20922102
return lines
20932103

20942104
def display(self, ax, ref=None, extern_only=False, intern_only=False, **kwargs):

0 commit comments

Comments
 (0)