code: def make_workspace(mdict, controls_measurement, dose_measurements=[]):
      """Make a workspace and module for running CalculateStatistics
  
      mdict - a two-level dictionary that mimics the measurements structure
              for instance:
              mdict = { cpmeas.Image: { "M1": [ 1,2,3] }}
              for the measurement M1 with values for 3 image sets
      controls_measurement - the name of the controls measurement
      """
      module = (
          cellprofiler.modules.calculatestatistics.CalculateStatistics()
      )
      module.set_module_num(1)
      module.grouping_values.value = controls_measurement
  
      pipeline = cellprofiler_core.pipeline.Pipeline()
      pipeline.add_module(module)
  
      m = cellprofiler_core.measurement.Measurements()
      nimages = None
      for object_name in list(mdict.keys()):
          odict = mdict[object_name]
          for feature in list(odict.keys()):
              m.add_all_measurements(
                  object_name, feature, odict[feature]
              )
              if nimages is None:
                  nimages = len(odict[feature])
              else:
                  assert nimages == len(odict[feature])
              if (
                  object_name == "Image"
                  and feature in dose_measurements
              ):
                  if len(module.dose_values) > 1:
                      module.add_dose_value()
                  dv = module.dose_values[-1]
                  dv.measurement.value = feature
      m.image_set_number = nimages
      image_set_list = cellprofiler_core.image.ImageSetList()
      for i in range(nimages):
          image_set = image_set_list.get_image_set(i)
      workspace = cellprofiler_core.workspace.Workspace(
          pipeline,
          module,
          image_set,
          cellprofiler_core.object.ObjectSet(),
          m,
          image_set_list,
      )
      return workspace, module
  
file_path: CellProfiler/tests/frontend/modules/test_calculatestatistics.py
imports: import os
  import tempfile
  import numpy
  import six.moves
  import cellprofiler_core.image
  import cellprofiler_core.measurement
  import cellprofiler.modules.calculatestatistics
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.preferences
  import cellprofiler_core.setting
  import cellprofiler_core.workspace
  import tests.frontend.modules
label_desc: Use image node_id 2 for calling a global function with example usage: make_workspace(mdict, controls_measurement, dose_measurements) and returns: workspace,  module