code: def split_dataset(
      datastore: Datastore,
      cache_dir,
      source,
      groups,
      tile_size,
      max_region=(10240, 10240),
      limit=0,
      randomize=True,
      crop_size=0,
  ):
      ds = datastore.datalist()
      output_dir = cache_dir
      if output_dir:
          shutil.rmtree(output_dir, ignore_errors=True)
  
      if source == "none":
          pass
      elif source == "consep":
          logger.info("Prepare from CoNSeP Dataset")
  
          ds_new = []
          for d in tqdm(ds):
              ds_new.extend(
                  split_consep_dataset(
                      d, output_dir, crop_size=crop_size
                  )
              )
              if 0 < limit < len(ds_new):
                  ds_new = ds_new[:limit]
                  break
          ds = ds_new
          logger.info(f"Total Dataset Records: {len(ds)}")
      elif source == "consep_nuclei":
          logger.info("Prepare from CoNSeP Dataset (Flatten by Nuclei)")
  
          ds_new = []
          for d in tqdm(ds):
              ds_new.extend(
                  split_consep_nuclei_dataset(
                      d,
                      output_dir,
                      crop_size=crop_size if crop_size else 128,
                  )
              )
              if 0 < limit < len(ds_new):
                  ds_new = ds_new[:limit]
                  break
          ds = ds_new
          logger.info(f"Total Dataset Records: {len(ds)}")
      elif source == "pannuke":
          logger.info("Prepare from PanNuke Dataset")
  
          ds_new = []
          for i in range(len(ds)):
              image = ds[i]["image"]
              label = ds[i]["label"]
              logger.info(
                  f"{image} => PANNuke (For Developer Mode only):: Split data; groups: {groups}"
              )
              d = split_pannuke_dataset(
                  image, label, output_dir, groups
              )
              logger.info(
                  f"{image} => Total Dataset Records: {len(ds)}"
              )
              ds_new.extend(d)
          ds = ds_new
          logger.info(f"Total Dataset Records: {len(ds)}")
      else:
          logger.info(
              f"Split data based on tile size: {tile_size}; groups: {groups}"
          )
          ds_new = []
          count = 0
          if limit > 0:
              ds = random.sample(ds, limit) if randomize else ds[:limit]
          for d in tqdm(ds):
              if isinstance(datastore, DSADatastore):
                  ds_new.extend(
                      split_dsa_dataset(
                          datastore,
                          d,
                          output_dir,
                          groups,
                          tile_size,
                          max_region,
                      )
                  )
              else:
                  ds_new.extend(
                      split_local_dataset(
                          datastore,
                          d,
                          output_dir,
                          groups,
                          tile_size,
                          max_region,
                      )
                  )
              count += 1
              if 0 < limit < count:
                  break
          ds = ds_new
  
      logger.info(f"+++ Total Records: {len(ds)}")
      return ds
  
imports: import copy
  import logging
  import os
  import random
  import shutil
  import xml.etree.ElementTree
  from io import BytesIO
  from math import ceil
  import cv2
  import numpy
  import openslide
  import scipy
  from PIL import Image
  from tqdm import tqdm
  from monailabel.datastore.dsa import DSADatastore
  from monailabel.datastore.local import LocalDatastore
  from monailabel.interfaces.datastore import Datastore
  from monailabel.utils.others.generic import get_basename, get_basename_no_ext, is_openslide_supported
label_desc: Use image node_id 1 for calling a global function with example usage: split_dataset(datastore, cache_dir, source, groups, tile_size, max_region, limit, randomize, crop_size) and returns: ds