def ravel_from_mask(data, mask):
    """
    Selects out the data from a ND array whose points are marked true in `mask`. See also `unravel_from_mask`
    below which allows you to write back into data after you have transformed the 1D output in some way.

    These two functions are especially useful for hierarchical curve fitting where you want to rerun a fit over a subset
    of the data with a different model, such as when you know some of the data is best described by two bands rather than
    one.
    :param data:
    :param mask:
    :return:
    """
    return data.stack(stacked=mask.dims).where(mask.stack(stacked=mask.dims
        ), drop=True)
