import warnings


def get_zonal_means(data, time_mean=False):
    """Take the average values along longitude axis.

    For every latitude we will average all longitudes. This is known
    as a zonal mean.

    Parameters
    ----------
    data: xarray.DataArray
        Input must have a named `longitude` coordinate. If `time_mea`
        is True, then it also must have a named `time` coordinate.
    time_mean: bool, optional
        Whether to take the mean along th time axis as well. Default
        is False.

    Returns
    -------
    xarray.DataArray with zonal means (no `longitude` coordinate).
    """  # noqa

    # sometimes things are masked, ignore
    msg = 'Mean of empty slice'
    warnings.filterwarnings('ignore', message=msg)

    # compute zonal mean
    zm = data.mean(dim='longitude', keep_attrs=True)

    if time_mean is True:
        zm = zm.mean(dim='time', keep_attrs=True)

    return zm