@@ -1532,20 +1532,26 @@ def filled(
15321532 c .norm = Normalize (vmin = vmin , vmax = vmax )
15331533 return c
15341534
1535- def bins_stat (self , name , bins = None ):
1535+ def bins_stat (self , xname , bins = None , yname = None , method = None ):
15361536 """
1537- :param str name : var which will be use
1537+ :param str,array xname : var which will be use
15381538 :param array, None bins: bins to perform statistics,if None method will get min and max of variable
1539+ :param None,str yname: var which will be use to apply method
1540+ :param None,str method: If None method count in each bin, could also do mean, std
15391541 :return: x array and y array
15401542 :rtype: array,array
15411543
15421544 .. minigallery:: py_eddy_tracker.EddiesObservations.bins_stat
15431545 """
1544- v = self [name ]
1546+ v = self [xname ] if isinstance ( xname , str ) else xname
15451547 if bins is None :
15461548 bins = arange (v .min (), v .max () + 2 )
15471549 y , x = hist_numba (v , bins = bins )
15481550 x = (x [1 :] + x [:- 1 ]) / 2
1551+ if method == "mean" :
1552+ y_v = self [yname ]
1553+ y_ , _ = histogram (v , bins = bins , weights = y_v )
1554+ y = y_ / y
15491555 return x , y
15501556
15511557 def display (
@@ -1679,12 +1685,13 @@ def grid_count(self, bins, intern=False, center=False):
16791685 grid .mask = grid == 0
16801686 return regular_grid
16811687
1682- def grid_stat (self , bins , varname ):
1688+ def grid_stat (self , bins , varname , data = None ):
16831689 """
16841690 Compute mean of eddies in each bin
16851691
16861692 :param (numpy.array,numpy.array) bins: bins to compute count
16871693 :param str varname: name of variable to compute mean
1694+ :param array data: Array used to compute stat if defined
16881695 :return: return grid of mean
16891696 :rtype: py_eddy_tracker.dataset.grid.RegularGridDataset
16901697
@@ -1693,8 +1700,14 @@ def grid_stat(self, bins, varname):
16931700 x_bins , y_bins = arange (* bins [0 ]), arange (* bins [1 ])
16941701 x0 = bins [0 ][0 ]
16951702 x , y = (self .longitude - x0 ) % 360 + x0 , self .latitude
1696- sum_obs = histogram2d (x , y , (x_bins , y_bins ), weights = self [varname ])[0 ]
1697- nb_obs = histogram2d (x , y , (x_bins , y_bins ))[0 ]
1703+ data = self [varname ] if data is None else data
1704+ if hasattr (data , 'mask' ):
1705+ m = ~ data .mask
1706+ sum_obs = histogram2d (x [m ], y [m ], (x_bins , y_bins ), weights = data [m ])[0 ]
1707+ nb_obs = histogram2d (x [m ], y [m ], (x_bins , y_bins ))[0 ]
1708+ else :
1709+ sum_obs = histogram2d (x , y , (x_bins , y_bins ), weights = data )[0 ]
1710+ nb_obs = histogram2d (x , y , (x_bins , y_bins ))[0 ]
16981711 from ..dataset .grid import RegularGridDataset
16991712
17001713 regular_grid = RegularGridDataset .with_array (
0 commit comments