def keep_by_rules(self, workspace, src_objects): """Keep objects according to rules workspace - workspace holding the measurements for the rules src_objects - filter these objects (uses measurement indexes instead) Open the rules file indicated by the settings and score the objects by the rules. Return the indexes of the objects that pass. """ rules = self.get_rules() rules_class = int(self.rules_class.value) - 1 scores = rules.score(workspace.measurements) if len(scores) > 0: is_not_nan = numpy.any(~numpy.isnan(scores), 1) best_class = numpy.argmax(scores[is_not_nan], 1).flatten() hits = numpy.zeros(scores.shape[0], bool) hits[is_not_nan] = best_class == rules_class indexes = numpy.argwhere(hits).flatten() + 1 else: indexes = numpy.array([], int) return indexes
def keep_by_rules(self, workspace, src_objects): '''Keep objects according to rules workspace - workspace holding the measurements for the rules src_objects - filter these objects (uses measurement indexes instead) Open the rules file indicated by the settings and score the objects by the rules. Return the indexes of the objects that pass. ''' rules = self.get_rules() rules_class = int(self.rules_class.value) - 1 scores = rules.score(workspace.measurements) if len(scores) > 0: is_not_nan = numpy.any(~ numpy.isnan(scores), 1) best_class = numpy.argmax(scores[is_not_nan], 1).flatten() hits = numpy.zeros(scores.shape[0], bool) hits[is_not_nan] = best_class == rules_class indexes = numpy.argwhere(hits).flatten() + 1 else: indexes = numpy.array([], int) return indexes