docstr: Classify objects based on one measurement
docstr_tok: ["Classify","objects","based","on","one","measurement"]
code: def run_single_measurement(self, group, workspace):
      """Classify objects based on one measurement"""
      object_name = group.object_name.value
      feature = group.measurement.value
      objects = workspace.object_set.get_objects(object_name)
      measurements = workspace.measurements
      values = measurements.get_current_measurement(
          object_name, feature
      )
      #
      # Pad values if too few (defensive programming).
      #
      if len(values) < objects.count:
          values = numpy.hstack(
              (values, [numpy.NaN] * (objects.count - len(values)))
          )
      if group.bin_choice == BC_EVEN:
          low_threshold = group.low_threshold.value
          high_threshold = group.high_threshold.value
          if low_threshold >= high_threshold:
              raise ValueError(
                  "Lower Threshold must be less than Upper Threshold"
              )
          bin_count = group.bin_count.value
          thresholds = (
              numpy.arange(bin_count + 1)
              * (high_threshold - low_threshold)
              / float(bin_count)
              + low_threshold
          )
      else:
          thresholds = [
              float(x.strip())
              for x in group.custom_thresholds.value.split(",")
          ]
      #
      # Put infinities at either end of the thresholds so we can bin the
      # low and high bins
      #
      thresholds = numpy.hstack(
          (
              [-numpy.inf] if group.wants_low_bin else [],
              thresholds,
              [numpy.inf] if group.wants_high_bin else [],
          )
      )
      #
      # Do a cross-product of objects and threshold comparisons
      #
      ob_idx, th_idx = numpy.mgrid[
          0 : len(values), 0 : len(thresholds) - 1
      ]
      bin_hits = (values[ob_idx] > thresholds[th_idx]) & (
          values[ob_idx] <= thresholds[th_idx + 1]
      )
      num_values = len(values)
      for bin_idx, feature_name in enumerate(group.bin_feature_names()):
          measurement_name = "_".join((M_CATEGORY, feature_name))
          measurements.add_measurement(
              object_name,
              measurement_name,
              bin_hits[:, bin_idx].astype(int),
          )
          measurement_name = "_".join(
              (M_CATEGORY, feature_name, F_NUM_PER_BIN)
          )
          num_hits = bin_hits[:, bin_idx].sum()
          measurements.add_measurement(
              IMAGE, measurement_name, num_hits
          )
          measurement_name = "_".join(
              (M_CATEGORY, feature_name, F_PCT_PER_BIN)
          )
          measurements.add_measurement(
              IMAGE,
              measurement_name,
              100.0 * float(num_hits) / num_values
              if num_values > 0
              else 0,
          )
      if group.wants_images or self.show_window:
          colors = self.get_colors(bin_hits.shape[1])
          object_bins = numpy.sum(bin_hits * th_idx, 1) + 1
          object_color = numpy.hstack(([0], object_bins))
          object_color[numpy.hstack((False, numpy.isnan(values)))] = 0
          labels = object_color[objects.segmented]
          if group.wants_images:
              image = colors[labels, :3]
              workspace.image_set.add(
                  group.image_name.value,
                  Image(image, parent_image=objects.parent_image),
              )
  
          if self.show_window:
              workspace.display_data.bins.append(
                  object_bins[~numpy.isnan(values)]
              )
              workspace.display_data.labels.append(labels)
              workspace.display_data.values.append(
                  values[~numpy.isnan(values)]
              )
  
imports: import functools
  import os
  import numpy
  from cellprofiler.modules import _help
  from cellprofiler.utilities.rules import Rules
  from cellprofiler_core.constants.measurement import COLTYPE_FLOAT, M_LOCATION_CENTER_X, M_LOCATION_CENTER_Y, COLTYPE_VARCHAR, C_COUNT, C_CHILDREN, C_LOCATION, C_NUMBER, C_PARENT, FTR_OBJECT_NUMBER, FTR_CENTER_X, FTR_CENTER_Y, FTR_CENTER_Z
  from cellprofiler_core.constants.measurement import COLTYPE_INTEGER
  from cellprofiler_core.constants.measurement import IMAGE
  from cellprofiler_core.image import Image
  from cellprofiler_core.module import Module
  from cellprofiler_core.object import Objects
  from cellprofiler_core.preferences import get_default_colormap, get_headless
  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
  from cellprofiler_core.setting.do_something import RemoveSettingButton
  from cellprofiler_core.setting.subscriber import LabelSubscriber
  from cellprofiler_core.setting.text import Alphanumeric, Directory, Filename, LabelName
  from cellprofiler_core.setting.text import Float
  from cellprofiler_core.setting.text import ImageName
  from cellprofiler_core.setting.text import Integer
  from cellprofiler_core.setting.text import Text
  from cellprofiler_core.constants.measurement import FF_CHILDREN_COUNT
  from cellprofiler_core.constants.measurement import FF_COUNT
  from cellprofiler_core.constants.measurement import FF_PARENT
  from cellprofiler_core.module.image_segmentation import ImageSegmentation
label_desc: Use image node_id 13 for calling the ClassifyObjects obj's underlying member method code with example usage: obj.run_single_measurement(group, workspace) without return types