def _sleep_wake_categorization(data, trend, threshold=0.15):
    """Categorize data as wake (0) or sleep (1)

    If the data are above `thr` % of the trend, they are assigned wake.
    Otherwise, they are assigned sleep.

    Parameters
    ----------
    data : pandas.Series
        Data to categorize

    trend : pandas.Series
        Data with trend

    threshold : int, optional
        Fraction of the trend to use as a threshold for categorization.
        Default is '0.15'.

    Return
    ----------
    sw : pandas.Series
        Categorized data

    """
    sw = (data <= threshold * trend).astype(int)
    return sw.where(trend.notnull())
