@@ -412,6 +412,20 @@ def load(self):
412
412
self .setup_coordinates ()
413
413
self .init_pos_interpolator ()
414
414
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
+
415
429
def setup_coordinates (self ):
416
430
x_name , y_name = self .coordinates
417
431
if self .is_centered :
@@ -1416,7 +1430,7 @@ def convolve_filter_with_dynamic_kernel(
1416
1430
demi_x , demi_y = k_shape [0 ] // 2 , k_shape [1 ] // 2
1417
1431
values_sum = filter2D (tmp_matrix .data , - 1 , kernel )[demi_x :- demi_x , demi_y ]
1418
1432
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" ):
1420
1434
if extend :
1421
1435
data_out [:, i ] = ma .array (
1422
1436
values_sum / kernel_sum ,
@@ -1871,31 +1885,47 @@ def init_speed_coef(self, uname="u", vname="v"):
1871
1885
"""Draft"""
1872
1886
self ._speed_ev = (self .grid (uname ) ** 2 + self .grid (vname ) ** 2 ) ** 0.5
1873
1887
1874
- def display (self , ax , name , factor = 1 , ** kwargs ):
1888
+ def display (self , ax , name , factor = 1 , ref = None , ** kwargs ):
1875
1889
"""
1876
1890
:param matplotlib.axes.Axes ax: matplotlib axes use to draw
1877
1891
:param str,array name: variable to display, could be an array
1878
1892
:param float factor: multiply grid by
1893
+ :param float,None ref: if define use like west bound
1879
1894
:param dict kwargs: look at :py:meth:`matplotlib.axes.Axes.pcolormesh`
1880
1895
1881
1896
.. minigallery:: py_eddy_tracker.RegularGridDataset.display
1882
1897
"""
1883
1898
if "cmap" not in kwargs :
1884
1899
kwargs ["cmap" ] = "coolwarm"
1885
1900
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 )
1887
1909
1888
- def contour (self , ax , name , factor = 1 , ** kwargs ):
1910
+ def contour (self , ax , name , factor = 1 , ref = None , ** kwargs ):
1889
1911
"""
1890
1912
:param matplotlib.axes.Axes ax: matplotlib axes use to draw
1891
1913
:param str,array name: variable to display, could be an array
1892
1914
:param float factor: multiply grid by
1915
+ :param float,None ref: if define use like west bound
1893
1916
:param dict kwargs: look at :py:meth:`matplotlib.axes.Axes.contour`
1894
1917
1895
1918
.. minigallery:: py_eddy_tracker.RegularGridDataset.contour
1896
1919
"""
1897
1920
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 )
1899
1929
1900
1930
def regrid (self , other , grid_name , new_name = None ):
1901
1931
"""
0 commit comments