Skip to content

Commit b789b6a

Browse files
committed
Allow x reference to display grid
1 parent cffc8f1 commit b789b6a

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11+
- Allow to give a x reference when we display grid to be able to change xlim
1112
- Add option to EddyId to select data index like `--indexs time=5 depth=2`
1213
- Add a method to merge several indexs type for eddy obs
1314
- Acces at dataset variable like attribute, and lifetime/age are available for all observations

src/py_eddy_tracker/dataset/grid.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,20 @@ def load(self):
412412
self.setup_coordinates()
413413
self.init_pos_interpolator()
414414

415+
@staticmethod
416+
def c_to_bounds(c):
417+
"""
418+
Centred coordinates to bounds coordinates
419+
420+
:param array c: centred coordinates to translate
421+
:return: bounds coordinates
422+
"""
423+
bounds = concatenate((c, (2 * c[-1] - c[-2],)))
424+
d = bounds[1:] - bounds[:-1]
425+
bounds[:-1] -= d / 2
426+
bounds[-1] -= d[-1] / 2
427+
return bounds
428+
415429
def setup_coordinates(self):
416430
x_name, y_name = self.coordinates
417431
if self.is_centered:
@@ -1416,7 +1430,7 @@ def convolve_filter_with_dynamic_kernel(
14161430
demi_x, demi_y = k_shape[0] // 2, k_shape[1] // 2
14171431
values_sum = filter2D(tmp_matrix.data, -1, kernel)[demi_x:-demi_x, demi_y]
14181432
kernel_sum = filter2D(m.astype(float), -1, kernel)[demi_x:-demi_x, demi_y]
1419-
with errstate(invalid="ignore"):
1433+
with errstate(invalid="ignore", divide="ignore"):
14201434
if extend:
14211435
data_out[:, i] = ma.array(
14221436
values_sum / kernel_sum,
@@ -1871,31 +1885,47 @@ def init_speed_coef(self, uname="u", vname="v"):
18711885
"""Draft"""
18721886
self._speed_ev = (self.grid(uname) ** 2 + self.grid(vname) ** 2) ** 0.5
18731887

1874-
def display(self, ax, name, factor=1, **kwargs):
1888+
def display(self, ax, name, factor=1, ref=None, **kwargs):
18751889
"""
18761890
:param matplotlib.axes.Axes ax: matplotlib axes use to draw
18771891
:param str,array name: variable to display, could be an array
18781892
:param float factor: multiply grid by
1893+
:param float,None ref: if define use like west bound
18791894
:param dict kwargs: look at :py:meth:`matplotlib.axes.Axes.pcolormesh`
18801895
18811896
.. minigallery:: py_eddy_tracker.RegularGridDataset.display
18821897
"""
18831898
if "cmap" not in kwargs:
18841899
kwargs["cmap"] = "coolwarm"
18851900
data = self.grid(name) if isinstance(name, str) else name
1886-
return ax.pcolormesh(self.x_bounds, self.y_bounds, data.T * factor, **kwargs)
1901+
if ref is None:
1902+
x = self.x_bounds
1903+
else:
1904+
x = (self.x_c - ref) % 360 + ref
1905+
i = x.argsort()
1906+
x = self.c_to_bounds(x[i])
1907+
data = data[i]
1908+
return ax.pcolormesh(x, self.y_bounds, data.T * factor, **kwargs)
18871909

1888-
def contour(self, ax, name, factor=1, **kwargs):
1910+
def contour(self, ax, name, factor=1, ref=None, **kwargs):
18891911
"""
18901912
:param matplotlib.axes.Axes ax: matplotlib axes use to draw
18911913
:param str,array name: variable to display, could be an array
18921914
:param float factor: multiply grid by
1915+
:param float,None ref: if define use like west bound
18931916
:param dict kwargs: look at :py:meth:`matplotlib.axes.Axes.contour`
18941917
18951918
.. minigallery:: py_eddy_tracker.RegularGridDataset.contour
18961919
"""
18971920
data = self.grid(name) if isinstance(name, str) else name
1898-
return ax.contour(self.x_c, self.y_c, data.T * factor, **kwargs)
1921+
if ref is None:
1922+
x = self.x_c
1923+
else:
1924+
x = (self.x_c - ref) % 360 + ref
1925+
i = x.argsort()
1926+
x = x[i]
1927+
data = data[i]
1928+
return ax.contour(x, self.y_c, data.T * factor, **kwargs)
18991929

19001930
def regrid(self, other, grid_name, new_name=None):
19011931
"""

src/py_eddy_tracker/observations/observation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ def scatter(self, ax, name=None, ref=None, factor=1, **kwargs):
16141614
:param matplotlib.axes.Axes ax: matplotlib axe used to draw
16151615
:param str,array,None name:
16161616
variable used to fill the contour, if None all elements have the same color
1617-
:param float,None ref: if define use like west bound ?
1617+
:param float,None ref: if define use like west bound
16181618
:param float factor: multiply value by
16191619
:param dict kwargs: look at :py:meth:`matplotlib.axes.Axes.scatter`
16201620
:return: scatter mappable

0 commit comments

Comments
 (0)