@@ -1532,20 +1532,26 @@ def filled(
1532
1532
c .norm = Normalize (vmin = vmin , vmax = vmax )
1533
1533
return c
1534
1534
1535
- def bins_stat (self , name , bins = None ):
1535
+ def bins_stat (self , xname , bins = None , yname = None , method = None ):
1536
1536
"""
1537
- :param str name : var which will be use
1537
+ :param str,array xname : var which will be use
1538
1538
: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
1539
1541
:return: x array and y array
1540
1542
:rtype: array,array
1541
1543
1542
1544
.. minigallery:: py_eddy_tracker.EddiesObservations.bins_stat
1543
1545
"""
1544
- v = self [name ]
1546
+ v = self [xname ] if isinstance ( xname , str ) else xname
1545
1547
if bins is None :
1546
1548
bins = arange (v .min (), v .max () + 2 )
1547
1549
y , x = hist_numba (v , bins = bins )
1548
1550
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
1549
1555
return x , y
1550
1556
1551
1557
def display (
@@ -1679,12 +1685,13 @@ def grid_count(self, bins, intern=False, center=False):
1679
1685
grid .mask = grid == 0
1680
1686
return regular_grid
1681
1687
1682
- def grid_stat (self , bins , varname ):
1688
+ def grid_stat (self , bins , varname , data = None ):
1683
1689
"""
1684
1690
Compute mean of eddies in each bin
1685
1691
1686
1692
:param (numpy.array,numpy.array) bins: bins to compute count
1687
1693
:param str varname: name of variable to compute mean
1694
+ :param array data: Array used to compute stat if defined
1688
1695
:return: return grid of mean
1689
1696
:rtype: py_eddy_tracker.dataset.grid.RegularGridDataset
1690
1697
@@ -1693,8 +1700,14 @@ def grid_stat(self, bins, varname):
1693
1700
x_bins , y_bins = arange (* bins [0 ]), arange (* bins [1 ])
1694
1701
x0 = bins [0 ][0 ]
1695
1702
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 ]
1698
1711
from ..dataset .grid import RegularGridDataset
1699
1712
1700
1713
regular_grid = RegularGridDataset .with_array (
0 commit comments