code: def test_measure_one_worm():
      r = numpy.random.RandomState()
      r.seed(0)
      image = r.uniform(size=(60, 30))
      control_points = numpy.array(
          [
              [[21], [15]],
              [[24], [15]],
              [[27], [15]],
              [[30], [15]],
              [[33], [15]],
          ]
      )
      lengths = numpy.array([12])
      radii = numpy.array([1, 3, 5, 3, 1])
      workspace, module = make_workspace(
          control_points, lengths, radii, image
      )
      assert isinstance(
          module, cellprofiler.modules.straightenworms.StraightenWorms
      )
      module.width.value = 11
      module.wants_measurements.value = True
      module.number_of_segments.value = 4
      module.number_of_stripes.value = 3
      module.run(workspace)
      m = workspace.measurements
      assert isinstance(m, cellprofiler_core.measurement.Measurements)
      oo = workspace.object_set.get_objects(OBJECTS_NAME)
      #
      # The worm goes from 20 to 34. Each segment is 15 / 4 = 3 3/4 long
      #
      # 20, 21, and 22 are in 1 as is 3/4 of 23
      # 1/4 of 23 is in 2 as is 24, 25 and 26 and 1/2 of 27
      # 1/2 of 27 is in 3 as is 28, 29, 30 and 1/4 of 31
      # 3/4 of 31 is in 4 as is 32, 33, and 34
      #
      segments = [
          [(20, 1.0), (21, 1.0), (22, 1.0), (23, 0.75)],
          [(23, 0.25), (24, 1.0), (25, 1.0), (26, 1.0), (27, 0.5)],
          [(27, 0.50), (28, 1.0), (29, 1.0), (30, 1.0), (31, 0.25)],
          [(31, 0.75), (32, 1.0), (33, 1.0), (34, 1.0)],
      ]
  
      def weighted_mean(img, segments, mask):
          accumulator = 0.0
          weight_accumulator = 0.0
          for i, w in segments:
              piece = img[i, mask[i, :]]
              accumulator += numpy.sum(piece) * w
              weight_accumulator += w * numpy.sum(mask[i, :])
          return accumulator / weight_accumulator
  
      def weighted_std(img, segments, mask):
          mean = weighted_mean(img, segments, mask)
          accumulator = 0.0
          weight_accumulator = 0.0
          pixel_count = 0.0
          for i, w in segments:
              piece = img[i, mask[i, :]]
              accumulator += numpy.sum((piece - mean) ** 2) * w
              weight_accumulator += w * numpy.sum(mask[i, :])
              pixel_count += numpy.sum(mask[i, :])
          return numpy.sqrt(
              accumulator
              / weight_accumulator
              / (pixel_count - 1)
              * pixel_count
          )
  
      for i, segment in enumerate(segments):
          for ftr, function in (
              (
                  cellprofiler.modules.straightenworms.FTR_MEAN_INTENSITY,
                  weighted_mean,
              ),
              (
                  cellprofiler.modules.straightenworms.FTR_STD_INTENSITY,
                  weighted_std,
              ),
          ):
              mname = "_".join(
                  (
                      cellprofiler.modules.straightenworms.C_WORM,
                      ftr,
                      STRAIGHTENED_IMAGE_NAME,
                      module.get_scale_name(None, i),
                  )
              )
              v = m.get_current_measurement(OBJECTS_NAME, mname)
              expected = function(image, segment, oo.segmented == 1)
              assert len(v) == 1
              assert round(abs(v[0] - expected), 7) == 0
  
imports: import centrosome.cpmorphology
  import numpy
  import six.moves
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  import cellprofiler_core.modules
  from cellprofiler_core.constants.measurement import C_COUNT, M_LOCATION_CENTER_X, M_LOCATION_CENTER_Y, M_NUMBER_OBJECT_NUMBER, C_LOCATION, C_NUMBER, FTR_CENTER_X, FTR_CENTER_Y, FTR_OBJECT_NUMBER, COLTYPE_FLOAT
  import cellprofiler.modules.straightenworms
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.setting
  import cellprofiler_core.workspace
  import cellprofiler_core.preferences
  import tests.frontend.modules
label_desc: Use image node_id 15 for calling a global function with example usage: test_measure_one_worm() and returns: unknown, numpy