def handle_blanks(features, blank_thresh=DEFAULT_BLANK_THRESH,
                            blank_handler=DEFAULT_BLANK_HANDLER,
                            inplace=False):
    '''Handles any SIFT descriptors that are blank, or nearly blank.'''

    if blank_handler not in BLANK_HANDLERS:
        msg = "unknown blank handler {!r}, expected one of {}".format(
            blank_handler, ", ".join(map(repr, BLANK_HANDLERS)))
        raise ValueError(msg)

    if blank_handler == 'drop':
        # TODO handle this more efficiently
        feats = [
            f[np.sum(f, axis=1) >= blank_thresh, :] for f in features.features
        ]
        return features._replace_bags(feats, inplace=inplace)

    handler = BLANK_HANDLERS[blank_handler](blank_thresh=blank_thresh)
    r = features._apply_transform(handler, fit_first=True, inplace=inplace)

    if not inplace:
        return r


################################################################################
### Add spatial information
dataset/ETHPy150Open dougalsutherland/py-sdm/sdm/proc_image_features.py/handle_blanks/original