def good_cutouts(image, xy, r=30, upper=40000, lower=1000, trim=100):
    (idxs, _cuts) = cutouts(image, xy, r)
    cuts = OrderedDict(zip(idxs, _cuts))
    peaks = [cutout.data.max() for cutout in cuts.values()]
    for (i, cutout) in cuts.copy().items():
        if (i in cuts):
            peak = cutout.data.max()
            center = cutout.center
            if ((peak > upper) or (peak < lower)):
                del cuts[i]
            elif (np.any((center < [trim, trim])) or np.any((center > (np.array(image.shape) - trim)))):
                del cuts[i]
            closest = idxs[np.nonzero((np.linalg.norm((center - xy[idxs]), axis=1) < r))[0]]
            if (len(closest) > 1):
                for j in closest:
                    if (j in cuts):
                        del cuts[j]
    return cuts
def good_cutouts(image, xy, r=30, upper=40000, lower=1000, trim=100):
    (idxs, _cuts) = cutouts(image, xy, r)
    cuts = OrderedDict(zip(idxs, _cuts))
    peaks = [cutout.data.max() for cutout in cuts.values()]
    for (i, cutout) in cuts.copy().items():
        if (i in cuts):
            peak = cutout.data.max()
            center = cutout.center
            if ((peak > upper) or (peak < lower)):
                del cuts[i]
            elif (np.any((center < [trim, trim])) or np.any((center > (np.array(image.shape) - trim)))):
                del cuts[i]
            closest = idxs[np.nonzero((np.linalg.norm((center - xy[idxs]), axis=1) < r))[0]]
            if (len(closest) > 1):
                for j in closest:
                    if (j in cuts):
                        del cuts[j]
    return cuts