Skip to content

Commit

Permalink
Add ref in display_color
Browse files Browse the repository at this point in the history
  • Loading branch information
AntSimi committed Oct 13, 2022
1 parent 943bbf3 commit 3359eda
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/py_eddy_tracker/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,18 @@ def wrap_longitude(x, y, ref, cut=False):
if cut:
indexs = list()
nb = x.shape[0]
new_previous = (x[0] - ref) % 360

new_x_previous = (x[0] - ref) % 360 + ref
x_previous = x[0]
for i in range(1, nb):
x_ = x[i]
new_x = (x_ - ref) % 360
new_x = (x_ - ref) % 360 + ref
if not isnan(x_) and not isnan(x_previous):
d_new = new_x - new_previous
d_new = new_x - new_x_previous
d = x_ - x_previous
if abs(d - d_new) > 1e-5:
indexs.append(i)
x_previous, new_previous = x_, new_x
x_previous, new_x_previous = x_, new_x

nb_indexs = len(indexs)
new_size = nb + nb_indexs * 3
Expand All @@ -477,6 +478,7 @@ def wrap_longitude(x, y, ref, cut=False):
for i in range(nb):
if j < nb_indexs and i == indexs[j]:
j += 1
# FIXME need check
cor = 360 if x[i - 1] > x[i] else -360
out_x[i + i_] = (x[i] - ref) % 360 + ref - cor
out_y[i + i_] = y[i]
Expand Down
12 changes: 11 additions & 1 deletion src/py_eddy_tracker/observations/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2069,18 +2069,26 @@ def format_label(self, label):
nb_obs=len(self),
)

def display_color(self, ax, field, intern=False, **kwargs):
def display_color(self, ax, field, ref=None, intern=False, **kwargs):
"""Plot colored contour of eddies
:param matplotlib.axes.Axes ax: matplotlib axe used to draw
:param str,array field: color field
:param float,None ref: if defined, all coordinates are wrapped with ref as western boundary
:param bool intern: if True, draw the speed contour
:param dict kwargs: look at :py:meth:`matplotlib.collections.LineCollection`
.. minigallery:: py_eddy_tracker.EddiesObservations.display_color
"""
xname, yname = self.intern(intern)
x, y = self[xname], self[yname]

if ref is not None:
# TODO : maybe buggy with global display
shape_out = x.shape
x, y = wrap_longitude(x.reshape(-1), y.reshape(-1), ref)
x, y = x.reshape(shape_out), y.reshape(shape_out)

c = self.parse_varname(field)
cmap = get_cmap(kwargs.pop("cmap", "Spectral_r"))
cmin, cmax = kwargs.pop("vmin", c.min()), kwargs.pop("vmax", c.max())
Expand All @@ -2089,6 +2097,8 @@ def display_color(self, ax, field, intern=False, **kwargs):
[create_vertice(i, j) for i, j in zip(x, y)], colors=colors, **kwargs
)
ax.add_collection(lines)
lines.cmap = cmap
lines.norm = Normalize(vmin=cmin, vmax=cmax)
return lines

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

0 comments on commit 3359eda

Please sign in to comment.