def _sum_contingency(contingency, category='total'):
    """ 
        Returns sums of specified categories in contingency table 
        Author: Dougie Squire
        Date: 12/05/2018
        
        Parameters
        ----------
        contingency : xarray DataArray
            A contingency table of the form output from doppyo.skill.contingency
        category : str, optional
            Contingency table category to sum. Options are 'total', 'reference' and 'comparison'
            
        Returns
        -------
        summed : 
            Sum of all counts in specified category
            
        Examples
        --------
        >>> da_cmp = xr.DataArray(np.random.normal(size=(3,3)), 
        ...                       coords=[('x', np.arange(3)), ('y', np.arange(3))])
        >>> da_ref = xr.DataArray(np.random.normal(size=(3,3)), 
        ...                       coords=[('x', np.arange(3)), ('y', np.arange(3))])
        >>> category_edges_cmp = np.linspace(-2,2,3)
        >>> category_edges_ref = np.linspace(-2,2,3)
        >>> contingency = doppyo.skill.contingency(da_cmp, da_ref, category_edges_cmp, 
        ...                                        category_edges_ref, over_dims='y')
        >>> doppyo.skill._sum_contingency(contingency, category='reference')
        <xarray.DataArray 'contingency' (x: 3, category: 2)>
        array([[0, 3],
               [2, 1],
               [2, 1]])
        Coordinates:
          * x         (x) int64 0 1 2
          * category  (category) int64 1 2
    """
    
    if category == 'total':
        N = contingency.sum(dim=('reference_category','comparison_category'), skipna=True)
    elif category == 'reference':
        N = contingency.sum(dim='comparison_category', skipna=True) \
                       .rename({'reference_category' : 'category'})
    elif category == 'comparison':
        N = contingency.sum(dim='reference_category', skipna=True) \
                       .rename({'comparison_category' : 'category'})    
    else: raise ValueError(f'"{category}" is not a recognised category')
        
    return N