def filter(self, criteria, applyto='measurement', ID=None):
        """
        Filter measurements according to given criteria.
        Retain only Measurements for which criteria returns True.

        TODO: add support for multiple criteria

        Parameters
        ----------
        criteria : callable
            Returns bool.
        applyto : 'measurement' | 'keys' | 'data' | mapping
             'measurement' : criteria is applied to Measurement objects
             'keys'         : criteria is applied to the keys.
             'data'         : criteria is applied to the Measurement objects' data.
             mapping        : for each key criteria is applied to mapping value with same key.
        ID : str
            ID of the filtered collection.
            If None is given, append '.filterd' to the current sample ID.

        Returns
        -------
        Filtered Collection.
        """
        fil = criteria
        new = self.copy()
        if isinstance(applyto, collections.Mapping):
            remove = (k for k, v in self.items() if not fil(applyto[k]))
        elif applyto == 'measurement':
            remove = (k for k, v in self.items() if not fil(v))
        elif applyto == 'keys':
            remove = (k for k, v in self.items() if not fil(k))
        elif applyto == 'data':
            remove = (k for k, v in self.items() if not fil(v.get_data()))
        else:
            raise ValueError('Unsupported value "%s" for applyto parameter.' % applyto)
        for r in remove:
            del new[r]
        if ID is None:
            ID = self.ID
        new.ID = ID
        return new
Filter measurements according to given criteria.
        Retain only Measurements for which criteria returns True.

        TODO: add support for multiple criteria

        Parameters
        ----------
        criteria : callable
            Returns bool.
        applyto : 'measurement' | 'keys' | 'data' | mapping
             'measurement' : criteria is applied to Measurement objects
             'keys'         : criteria is applied to the keys.
             'data'         : criteria is applied to the Measurement objects' data.
             mapping        : for each key criteria is applied to mapping value with same key.
        ID : str
            ID of the filtered collection.
            If None is given, append '.filterd' to the current sample ID.

        Returns
        -------
        Filtered Collection.