code: def test_natural():
      # Use natural objects.
      #
      # Put objects near the edges of the circle and make sure
      # they are filtered out.
      #
      # Randomly distribute points in objects to keep between
      # two different groups of objects.
      #
      d = cellprofiler.modules.definegrid.DefineGrid()
      d.ordering.value = cellprofiler.modules.definegrid.NUM_BY_COLUMNS
      #
      # Grid with x spacing = 10, y spacing = 20
      #
      diameter = 6
      gridding = d.build_grid_info(15, 25, 1, 1, 32, 45, 2, 2)
      guide_labels = make_rectangular_grid(gridding)
      i, j = numpy.mgrid[
          0 : guide_labels.shape[0], 0 : guide_labels.shape[1]
      ]
      ispot, jspot = numpy.mgrid[
          0 : gridding.rows, 0 : gridding.columns
      ]
      y_locations = numpy.zeros(numpy.max(gridding.spot_table) + 1, int)
      y_locations[gridding.spot_table.flatten()] = gridding.y_locations[
          ispot.flatten()
      ]
      x_locations = numpy.zeros(numpy.max(gridding.spot_table) + 1, int)
      x_locations[gridding.spot_table.flatten()] = gridding.x_locations[
          jspot.flatten()
      ]
      #
      # save some bad places - at the corners of the grids
      #
      bad_x_locations = (x_locations - gridding.x_spacing / 2).astype(
          int
      )
      bad_y_locations = (y_locations - gridding.y_spacing / 2).astype(
          int
      )
      #
      # Perturb the X and Y locations and diameters randomly
      #
      numpy.random.seed(0)
      x_locations += (
          numpy.random.uniform(size=x_locations.shape[0]) * 3 - 1
      ).astype(int)
      y_locations += (
          numpy.random.uniform(size=y_locations.shape[0]) * 3 - 1
      ).astype(int)
      random_diameters = (
          numpy.random.uniform(size=y_locations.shape[0] + 1) * 4 * 3
      )
      idist = i - y_locations[guide_labels]
      jdist = j - x_locations[guide_labels]
      guide_labels[
          idist**2 + jdist**2
          > ((random_diameters[guide_labels] + 1) / 2) ** 2
      ] = 0
      expected = guide_labels.copy()
      guide_labels[guide_labels != 0] += (
          gridding.rows
          * gridding.columns
          * (
              numpy.random.uniform(size=numpy.sum(guide_labels != 0))
              > 0.5
          )
      )
      #
      # Take 1/2 of the points and assign them to a second class of objects.
      # All of the objects should be merged.
      #
      #
      # Add objects in bad places
      #
      for i_off in (-1, 0, 1):
          for j_off in (-1, 0, 1):
              guide_labels[
                  bad_y_locations + i_off, bad_x_locations + j_off
              ] = (
                  numpy.arange(len(bad_y_locations))
                  + gridding.rows * gridding.columns * 2
                  + 1
              )
      #
      # Scramble the label numbers
      #
      p = numpy.random.permutation(
          numpy.arange(numpy.max(guide_labels) + 1)
      )
      p[p == 0] = p[0]
      p[0] = 0
      guide_labels = p[guide_labels]
      #
      # run the module
      #
      workspace, module = make_workspace(gridding, guide_labels)
      assert isinstance(
          module,
          cellprofiler.modules.identifyobjectsingrid.IdentifyObjectsInGrid,
      )
      module.diameter_choice.value = (
          cellprofiler.modules.identifyobjectsingrid.AM_MANUAL
      )
      module.diameter.value = diameter
      module.shape_choice.value = (
          cellprofiler.modules.identifyobjectsingrid.SHAPE_NATURAL
      )
      module.run(workspace)
      labels = workspace.object_set.get_objects(
          OUTPUT_OBJECTS_NAME
      ).segmented
      assert numpy.all(
          labels == expected[0 : labels.shape[0], 0 : labels.shape[1]]
      )
      m = workspace.measurements
      assert isinstance(m, cellprofiler_core.measurement.Measurements)
      xm = m.get_current_measurement(
          OUTPUT_OBJECTS_NAME, "Location_Center_X"
      )
      assert numpy.all(xm == x_locations[1:])
      ym = m.get_current_measurement(
          OUTPUT_OBJECTS_NAME, "Location_Center_Y"
      )
      assert numpy.all(ym == y_locations[1:])
      count = m.get_current_image_measurement(
          "Count_%s" % OUTPUT_OBJECTS_NAME
      )
      assert count == gridding.rows * gridding.columns
  
file_path: CellProfiler/tests/frontend/modules/test_identifyobjectsingrid.py
imports: import numpy
  import cellprofiler_core.utilities.grid
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  import cellprofiler.modules.definegrid
  import cellprofiler.modules.identifyobjectsingrid
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.workspace
label_desc: Use image node_id 8 for calling a global function with example usage: test_natural() without return types