docstr: Evaluate a measurement
  
  workspace - holds the measurements to be evaluated
  ms - the measurement settings indicating how to evaluate
  
  returns a tuple
     first tuple element is True = pass, False = Fail
     second tuple element has all of the statistics except for the
                  flag name
docstr_tok: ["Evaluate","a","measurement","workspace","-","holds","the","measurements","to","be","evaluated","ms","-","the","measurement","settings","indicating","how","to","evaluate","returns","a","tuple","first","tuple","element","is","True","=","pass",",","False","=","Fail","second","tuple","element","has","all","of","the","statistics","except","for","the","flag","name"]
code: def eval_measurement(self, workspace, ms):
      """Evaluate a measurement
  
      workspace - holds the measurements to be evaluated
      ms - the measurement settings indicating how to evaluate
  
      returns a tuple
         first tuple element is True = pass, False = Fail
         second tuple element has all of the statistics except for the
                      flag name
      """
      m = workspace.measurements
      assert isinstance(m, Measurements)
      fail = False
      if ms.source_choice == S_IMAGE:
          value = m.get_current_image_measurement(ms.measurement.value)
          min_value = max_value = value
          display_value = str(round(value, 3))
          source = IMAGE
      elif ms.source_choice == S_AVERAGE_OBJECT:
          data = m.get_current_measurement(
              ms.object_name.value, ms.measurement.value
          )
          if len(data) == 0:
              min_value = max_value = numpy.NaN
              fail = True
              display_value = "No objects"
          else:
              min_value = max_value = numpy.mean(data)
              display_value = str(round(min_value, 3))
          source = "Ave. %s" % ms.object_name.value
      elif ms.source_choice == S_ALL_OBJECTS:
          data = m.get_current_measurement(
              ms.object_name.value, ms.measurement.value
          )
          source = ms.object_name.value
          if len(data) == 0:
              min_value = max_value = numpy.NaN
              fail = True
              display_value = "No objects"
          else:
              min_value = numpy.min(data)
              max_value = numpy.max(data)
              if min_value == max_value:
                  display_value = str(min_value)
              else:
                  display_value = "%.3f - %.3f" % (min_value, max_value)
      elif ms.source_choice == S_RULES:
          rules = self.get_rules(ms)
          scores = rules.score(workspace.measurements)
          rules_classes = numpy.array(
              [int(x) - 1 for x in ms.rules_class.get_selections()]
          )
          #
          # There should only be one in the vector, but if not, take
          # a majority vote (e.g., are there more class 1 objects than
          # class 2?)
          #
          is_not_nan = numpy.any(~numpy.isnan(scores), 1)
          objclass = numpy.argmax(scores[is_not_nan, :], 1).flatten()
          hit_count = numpy.sum(
              objclass[:, numpy.newaxis]
              == rules_classes[numpy.newaxis, :]
          )
          fail = hit_count > scores.shape[0] - hit_count
          source = IMAGE
          if len(scores) > 1:
              display_value = "%d of %d" % (hit_count, scores.shape[0])
          else:
              display_value = "--"
      elif ms.source_choice == S_CLASSIFIER:
          classifier = self.get_classifier(ms)
          target_idxs = [
              self.get_bin_labels(ms).index(_)
              for _ in ms.rules_class.get_selections()
          ]
          features = []
          image_features = workspace.measurements.get_feature_names(
              IMAGE
          )
          measurement_columns = (
              workspace.measurements.get_measurement_columns()
          )
          for feature_name in self.get_classifier_features(ms):
              feature_name = (
                  self.rules.Rule.return_fuzzy_measurement_name(
                      measurement_columns,
                      IMAGE,
                      feature_name,
                      False,
                      ms.allow_fuzzy,
                  )
              )
              features.append(feature_name)
  
          feature_vector = numpy.array(
              [
                  0
                  if feature_name not in image_features
                  else workspace.measurements[IMAGE, feature_name]
                  for feature_name in features
              ]
          ).reshape(1, len(features))
          predicted_class = classifier.predict(feature_vector)[0]
          predicted_idx = numpy.where(
              classifier.classes_ == predicted_class
          )[0][0]
          fail = predicted_idx in target_idxs
          display_value = self.get_bin_labels(ms)[predicted_idx]
          source = IMAGE
      else:
          raise NotImplementedError(
              "Source choice of %s not implemented" % ms.source_choice
          )
      is_rc = ms.source_choice in (S_RULES, S_CLASSIFIER)
      is_meas = not is_rc
      fail = (
          is_meas
          and (
              fail
              or (
                  ms.wants_minimum.value
                  and min_value < ms.minimum_value.value
              )
              or (
                  ms.wants_maximum.value
                  and max_value > ms.maximum_value.value
              )
          )
      ) or (is_rc and fail)
  
      return (
          (not fail),
          (
              source,
              ms.measurement.value
              if is_meas
              else ms.source_choice.value,
              display_value,
              "Fail" if fail else "Pass",
          ),
      )
  
imports: import logging
  import os
  import numpy
  from cellprofiler_core.constants.measurement import IMAGE, COLTYPE_INTEGER
  from cellprofiler_core.constants.module import IO_FOLDER_CHOICE_HELP_TEXT
  from cellprofiler_core.constants.workspace import DISPOSITION_CONTINUE, DISPOSITION_SKIP
  from cellprofiler_core.measurement import Measurements
  from cellprofiler_core.module import Module
  from cellprofiler_core.preferences import DEFAULT_INPUT_FOLDER_NAME
  from cellprofiler_core.setting import Binary
  from cellprofiler_core.setting import Divider
  from cellprofiler_core.setting import HiddenCount
  from cellprofiler_core.setting import Measurement
  from cellprofiler_core.setting import SettingsGroup
  from cellprofiler_core.setting import ValidationError
  from cellprofiler_core.setting.choice import Choice
  from cellprofiler_core.setting.do_something import DoSomething, RemoveSettingButton
  from cellprofiler_core.setting.multichoice import MultiChoice
  from cellprofiler_core.setting.subscriber import LabelSubscriber
  from cellprofiler_core.setting.text import Text, Filename, Directory, Float
  from cellprofiler.utilities.rules import Rules
label_desc: Use image node_id 20 for calling the FlagImage obj's underlying member method code with example usage: obj.eval_measurement(workspace, ms) and returns: unknown,  source,  unknown,  display_value,  unknown