ECOdyagnostics/operations.py
def average(self, P, axes, boundary=None, **maskargs):
        """
        Compute the weighted average of a variable along the specified axes.
        The weights are taken from the metric provided through the grid object.

        P_average = Sum( P * m ) / Sum( m )
        With P the variable and m the respective weight
        """
        # Get metric from xgcm grid
        dims = self.grid._get_dims_from_axis(P, axes)
        if boundary is None:
            m = self.grid.get_metric(P, axes)
        else:
            m = self.grid.get_metric(P, axes)[{dims[i]: slice(*boundary[axes[i]]) for i in range(len(axes))}]
            P = P[{dims[i]: slice(*boundary[axes[i]]) for i in range(len(axes))}]

        # Get and apply mask
        mask = self._get_mask(P,**maskargs)
        P = P * mask
        m = m * mask

        # Average along specified axes
        dims = self.grid._get_dims_from_axis(P, axes)
        P_av = (P * m).sum(dims) / m.sum(dims)

        return P_av

        Compute the weighted average of a variable along the specified axes.
        The weights are taken from the metric provided through the grid object.

        P_average = Sum( P * m ) / Sum( m )
        With P the variable and m the respective weight
        
Compute the weighted average of a variable along the specified axes.
The weights are taken from the metric provided through the grid object.

P_average = Sum( P * m ) / Sum( m )
With P the variable and m the respective weight
Compute the weighted average of a variable along the specified axes . The weights are taken from the metric provided through the grid object . P_average = Sum ( P * m ) / Sum ( m ) With P the variable and m the respective weight
def average(self, P, axes, boundary=None, **maskargs):
        dims = self.grid._get_dims_from_axis(P, axes)
        if boundary is None:
            m = self.grid.get_metric(P, axes)
        else:
            m = self.grid.get_metric(P, axes)[{dims[i]: slice(*boundary[axes[i]]) for i in range(len(axes))}]
            P = P[{dims[i]: slice(*boundary[axes[i]]) for i in range(len(axes))}]
        mask = self._get_mask(P,**maskargs)
        P = P * mask
        m = m * mask
        dims = self.grid._get_dims_from_axis(P, axes)
        P_av = (P * m).sum(dims) / m.sum(dims)
        return P_av
def average ( self , P , axes , boundary = None , ** maskargs ) : dims = self . grid . _get_dims_from_axis ( P , axes ) if boundary is None : m = self . grid . get_metric ( P , axes ) else : m = self . grid . get_metric ( P , axes ) [ { dims [ i ] : slice ( * boundary [ axes [ i ] ] ) for i in range ( len ( axes ) ) } ] P = P [ { dims [ i ] : slice ( * boundary [ axes [ i ] ] ) for i in range ( len ( axes ) ) } ] mask = self . _get_mask ( P , ** maskargs ) P = P * mask m = m * mask dims = self . grid . _get_dims_from_axis ( P , axes ) P_av = ( P * m ) . sum ( dims ) / m . sum ( dims ) return P_av
Compute the weighted average of a variable along the specified axes.
Compute the weighted average of a variable along the specified axes .
"""
        Compute the weighted average of a variable along the specified axes.
        The weights are taken from the metric provided through the grid object.

        P_average = Sum( P * m ) / Sum( m )
        With P the variable and m the respective weight
        """ # Get metric from xgcm grid # Get and apply mask # Average along specified axes
self
P
axes
boundary