docstr: Save the pipeline in Batch_data.mat
  
  Save the pickled image_set_list state in a setting and put this
  module in batch mode.
  
  if outf is not None, it is used as a file object destination.
docstr_tok: ["Save","the","pipeline","in","Batch_data.mat","Save","the","pickled","image_set_list","state","in","a","setting","and","put","this","module","in","batch","mode",".","if","outf","is","not","None",",","it","is","used","as","a","file","object","destination","."]
code: def save_pipeline(self, workspace, outf=None):
      """Save the pipeline in Batch_data.mat
  
      Save the pickled image_set_list state in a setting and put this
      module in batch mode.
  
      if outf is not None, it is used as a file object destination.
      """
      if outf is None:
          if self.wants_default_output_directory.value:
              path = get_default_output_directory()
          else:
              path = get_absolute_path(
                  self.custom_output_directory.value
              )
              os.makedirs(path, exist_ok=True)
          h5_path = os.path.join(path, F_BATCH_DATA_H5)
      else:
          h5_path = outf
  
      image_set_list = workspace.image_set_list
      pipeline = workspace.pipeline
      m = Measurements(copy=workspace.measurements, filename=h5_path)
      try:
          assert isinstance(pipeline, Pipeline)
          assert isinstance(m, Measurements)
  
          orig_pipeline = pipeline
          pipeline = pipeline.copy()
          # this use of workspace.frame is okay, since we're called from
          # prepare_run which happens in the main wx thread.
          target_workspace = Workspace(
              pipeline,
              None,
              None,
              None,
              m,
              image_set_list,
              workspace.frame,
          )
          pipeline.prepare_to_create_batch(
              target_workspace, self.alter_path
          )
          bizarro_self = pipeline.module(self.module_num)
          bizarro_self.revision.value = int(
              re.sub(r"\.|rc\d{1}|b\d{1}", "", cellprofiler.__version__)
          )
          if self.wants_default_output_directory:
              bizarro_self.custom_output_directory.value = (
                  self.alter_path(get_default_output_directory())
              )
          bizarro_self.default_image_directory.value = self.alter_path(
              get_default_image_directory()
          )
          bizarro_self.batch_mode.value = True
          pipeline.write_pipeline_measurement(m)
          orig_pipeline.write_pipeline_measurement(
              m, user_pipeline=True
          )
          #
          # Write the path mappings to the batch measurements
          #
          m.write_path_mappings(
              [
                  (
                      mapping.local_directory.value,
                      mapping.remote_directory.value,
                  )
                  for mapping in self.mappings
              ]
          )
          return h5_path
      finally:
          m.close()
  
imports: import logging
  import os
  import re
  import sys
  import zlib
  import numpy
  from cellprofiler_core.constants.measurement import F_BATCH_DATA_H5
  from cellprofiler_core.measurement import Measurements
  from cellprofiler_core.module import Module
  from cellprofiler_core.pipeline import Pipeline
  from cellprofiler_core.preferences import get_absolute_path
  from cellprofiler_core.preferences import get_default_image_directory
  from cellprofiler_core.preferences import get_default_output_directory
  from cellprofiler_core.preferences import get_headless
  from cellprofiler_core.preferences import set_default_image_directory
  from cellprofiler_core.preferences import set_default_output_directory
  from cellprofiler_core.setting import Binary
  from cellprofiler_core.setting import Divider
  from cellprofiler_core.setting import Setting
  from cellprofiler_core.setting import SettingsGroup
  from cellprofiler_core.setting import ValidationError
  from cellprofiler_core.setting.do_something import DoSomething
  from cellprofiler_core.setting.do_something import RemoveSettingButton
  from cellprofiler_core.setting.text import Text, Integer
  from cellprofiler_core.workspace import Workspace
  import cellprofiler
label_desc: Use image node_id 13 for calling the CreateBatchFiles obj's underlying member method code with example usage: obj.save_pipeline(workspace, outf) and returns: h5_path