code: def test_measure_checkerboarded_worm():
      r = numpy.random.RandomState()
      r.seed(42)
      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, 4, 7, 4, 1])
      workspace, module = make_workspace(
          control_points, lengths, radii, image
      )
      assert isinstance(
          module, cellprofiler.modules.straightenworms.StraightenWorms
      )
      module.width.value = 21
      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)
      image = workspace.image_set.get_image(
          STRAIGHTENED_IMAGE_NAME
      ).pixel_data
      f1 = 1.0 / 3.0
      f2 = 2.0 / 3.0
      stripes = [
          (9, ((10, 11, 2, 1),)),
          (
              10,
              (
                  (8, 9, 1, 1),
                  (9, 10, 1, f2),
                  (9, 10, 2, f1),
                  (10, 11, 2, 1),
                  (11, 12, 2, f1),
                  (11, 12, 3, f2),
                  (12, 13, 3, 1),
              ),
          ),
          (
              11,
              (
                  (7, 9, 1, 1),
                  (9, 10, 1, f1),
                  (9, 10, 2, f2),
                  (10, 11, 2, 1),
                  (11, 12, 2, f2),
                  (11, 12, 3, f1),
                  (12, 14, 3, 1),
              ),
          ),
          (12, ((6, 9, 1, 1), (9, 12, 2, 1), (12, 15, 3, 1))),
          (
              13,
              (
                  (5, 8, 1, 1),
                  (8, 9, 1, f2),
                  (8, 9, 2, f1),
                  (9, 12, 2, 1),
                  (12, 13, 2, f1),
                  (12, 13, 3, f2),
                  (13, 16, 3, 1),
              ),
          ),
          (
              14,
              (
                  (4, 8, 1, 1),
                  (8, 9, 1, f1),
                  (8, 9, 2, f2),
                  (9, 12, 2, 1),
                  (12, 13, 2, f2),
                  (12, 13, 3, f1),
                  (13, 17, 3, 1),
              ),
          ),
          (15, ((4, 8, 1, 1), (8, 13, 2, 1), (13, 17, 3, 1))),
          (16, ((3, 8, 1, 1), (8, 13, 2, 1), (13, 18, 3, 1))),
          (17, ((4, 8, 1, 1), (8, 13, 2, 1), (13, 17, 3, 1))),
          (
              18,
              (
                  (4, 8, 1, 1),
                  (8, 9, 1, f1),
                  (8, 9, 2, f2),
                  (9, 12, 2, 1),
                  (12, 13, 2, f2),
                  (12, 13, 3, f1),
                  (13, 17, 3, 1),
              ),
          ),
          (
              19,
              (
                  (5, 8, 1, 1),
                  (8, 9, 1, f2),
                  (8, 9, 2, f1),
                  (9, 12, 2, 1),
                  (12, 13, 2, f1),
                  (12, 13, 3, f2),
                  (13, 16, 3, 1),
              ),
          ),
          (20, ((6, 9, 1, 1), (9, 12, 2, 1), (12, 15, 3, 1))),
          (
              21,
              (
                  (7, 9, 1, 1),
                  (9, 10, 1, f1),
                  (9, 10, 2, f2),
                  (10, 11, 2, 1),
                  (11, 12, 2, f2),
                  (11, 12, 3, f1),
                  (12, 14, 3, 1),
              ),
          ),
          (
              22,
              (
                  (8, 9, 1, 1),
                  (9, 10, 1, f2),
                  (9, 10, 2, f1),
                  (10, 11, 2, 1),
                  (11, 12, 2, f1),
                  (11, 12, 3, f2),
                  (12, 13, 3, 1),
              ),
          ),
          (23, ((10, 11, 2, 1),)),
      ]
      segments = [
          [(9, 1.0), (10, 1.0), (11, 1.0), (12, 0.75)],
          [(12, 0.25), (13, 1.0), (14, 1.0), (15, 1.0), (16, 0.5)],
          [(16, 0.50), (17, 1.0), (18, 1.0), (19, 1.0), (20, 0.25)],
          [(20, 0.75), (21, 1.0), (22, 1.0), (23, 1.0)],
      ]
  
      i_w = numpy.zeros((image.shape[0], image.shape[1], 4))
      j_w = numpy.zeros((image.shape[0], image.shape[1], 3))
      mask = numpy.zeros(image.shape, bool)
      for i, sstripes in stripes:
          for jstart, jend, idx, w in sstripes:
              for j in range(jstart, jend):
                  j_w[i, j, idx - 1] = w
                  mask[i, j] = True
  
      for idx, segment in enumerate(segments):
          for i, w in segment:
              i_w[i, mask[i, :], idx] = w
  
      s2 = lambda x: numpy.sum(numpy.sum(x, 0), 0)
      weights = s2(i_w)
      expected_means = s2(image[:, :, numpy.newaxis] * i_w) / weights
      counts = s2(i_w > 0)
      expected_sds = numpy.sqrt(
          s2(
              i_w
              * (
                  image[:, :, numpy.newaxis]
                  - expected_means[numpy.newaxis, numpy.newaxis, :]
              )
              ** 2
          )
          / weights
          * counts
          / (counts - 1)
      )
      for i in range(4):
          for ftr, expected in (
              (
                  cellprofiler.modules.straightenworms.FTR_MEAN_INTENSITY,
                  expected_means,
              ),
              (
                  cellprofiler.modules.straightenworms.FTR_STD_INTENSITY,
                  expected_sds,
              ),
          ):
              value = m.get_current_measurement(
                  OBJECTS_NAME,
                  "_".join(
                      (
                          cellprofiler.modules.straightenworms.C_WORM,
                          ftr,
                          STRAIGHTENED_IMAGE_NAME,
                          module.get_scale_name(None, i),
                      )
                  ),
              )
              assert len(value) == 1
              assert round(abs(value[0] - expected[i]), 7) == 0
      weights = s2(j_w)
      expected_means = s2(image[:, :, numpy.newaxis] * j_w) / weights
      counts = s2(j_w > 0)
      expected_sds = numpy.sqrt(
          s2(
              j_w
              * (
                  image[:, :, numpy.newaxis]
                  - expected_means[numpy.newaxis, numpy.newaxis, :]
              )
              ** 2
          )
          / weights
          * counts
          / (counts - 1)
      )
      for i in range(3):
          for ftr, expected in (
              (
                  cellprofiler.modules.straightenworms.FTR_MEAN_INTENSITY,
                  expected_means,
              ),
              (
                  cellprofiler.modules.straightenworms.FTR_STD_INTENSITY,
                  expected_sds,
              ),
          ):
              value = m.get_current_measurement(
                  OBJECTS_NAME,
                  "_".join(
                      (
                          cellprofiler.modules.straightenworms.C_WORM,
                          ftr,
                          STRAIGHTENED_IMAGE_NAME,
                          module.get_scale_name(i, None),
                      )
                  ),
              )
              assert len(value) == 1
              assert round(abs(value[0] - expected[i]), 7) == 0
  
      ww = i_w[:, :, :, numpy.newaxis] * j_w[:, :, numpy.newaxis, :]
      weights = s2(ww)
      expected_means = (
          s2(image[:, :, numpy.newaxis, numpy.newaxis] * ww) / weights
      )
      counts = s2(ww > 0)
      expected_sds = numpy.sqrt(
          s2(
              ww
              * (
                  image[:, :, numpy.newaxis, numpy.newaxis]
                  - expected_means[numpy.newaxis, numpy.newaxis, :, :]
              )
              ** 2
          )
          / weights
          * counts
          / (counts - 1)
      )
      for stripe in range(3):
          for segment in range(4):
              for ftr, expected in (
                  (
                      cellprofiler.modules.straightenworms.FTR_MEAN_INTENSITY,
                      expected_means,
                  ),
                  (
                      cellprofiler.modules.straightenworms.FTR_STD_INTENSITY,
                      expected_sds,
                  ),
              ):
                  mname = "_".join(
                      (
                          cellprofiler.modules.straightenworms.C_WORM,
                          ftr,
                          STRAIGHTENED_IMAGE_NAME,
                          module.get_scale_name(stripe, segment),
                      )
                  )
                  value = m.get_current_measurement(OBJECTS_NAME, mname)
                  assert len(value) == 1
                  assert (
                      round(
                          abs(value[0] - expected[segment, stripe]), 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 16 for calling a global function with example usage: test_measure_checkerboarded_worm() without return types