code: def main():
      # parse cmd arguments
      parser = getParser()
      parser.parse_args()
      args = getArguments(parser)
  
      # prepare logger
      logger = Logger.getInstance()
      if args.debug:
          logger.setLevel(logging.DEBUG)
      elif args.verbose:
          logger.setLevel(logging.INFO)
  
      # load input image
      logger.info("Loading {}...".format(args.image))
      image_data, image_header = load(args.image)
  
      # check if supplied cut dimension is inside the input images dimensions
      if args.dimension < 0 or args.dimension >= image_data.ndim:
          logger.critical(
              "The supplied cut-dimensions {} is invalid. The input image has only {} dimensions.".format(
                  args.dimension, image_data.ndim
              )
          )
          raise ArgumentError(
              "The supplied cut-dimensions {} is invalid. The input image has only {} dimensions.".format(
                  args.dimension, image_data.ndim
              )
          )
  
      # prepare output filenames
      name_output = args.output.replace("{}", "{:03d}")
  
      # determine cut lines
      no_sub_volumes = (
          image_data.shape[args.dimension] / args.maxsize + 1
      )  # int-division is desired
      slices_per_volume = (
          image_data.shape[args.dimension] / no_sub_volumes
      )  # int-division is desired
  
      # construct processing dict for each sub-volume
      processing_array = []
      for i in range(no_sub_volumes):
          processing_array.append(
              {
                  "path": name_output.format(i + 1),
                  "cut": (
                      i * slices_per_volume,
                      (i + 1) * slices_per_volume,
                  ),
              }
          )
          if (
              no_sub_volumes - 1 == i
          ):  # last volume has to have increased cut end
              processing_array[i]["cut"] = (
                  processing_array[i]["cut"][0],
                  image_data.shape[args.dimension],
              )
  
      # construct base indexing list
      index = [slice(None) for _ in range(image_data.ndim)]
  
      # execute extraction of the sub-volumes
      logger.info("Extracting sub-volumes...")
      for dic in processing_array:
          # check if output images exists
          if not args.force:
              if os.path.exists(dic["path"]):
                  logger.warning(
                      "The output file {} already exists. Skipping this volume.".format(
                          dic["path"]
                      )
                  )
                  continue
  
          # extracting sub-volume
          index[args.dimension] = slice(dic["cut"][0], dic["cut"][1])
          volume = image_data[index]
  
          logger.debug(
              "Extracted volume is of shape {}.".format(volume.shape)
          )
  
          # saving sub-volume in same format as input image
          logger.info(
              "Saving cut {} as {}...".format(dic["cut"], dic["path"])
          )
          save(volume, dic["path"], image_header, args.force)
  
      logger.info("Successfully terminated.")
  
file_path: medpy/bin/medpy_extract_sub_volume_auto.py
imports: from argparse import RawTextHelpFormatter
  import argparse
  import logging
  import os
  from medpy.core import ArgumentError, Logger
  from medpy.io import load, save
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types