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)
  
      # check if output image exists
      if not args.force:
          if os.path.exists(args.output + args.image[-4:]):
              logger.warning(
                  "The output file {} already exists. Breaking.".format(
                      args.output + args.image[-4:]
                  )
              )
              exit(1)
  
      # load images
      image_data, image_header = load(args.image)
  
      # check image dimensions against sub-volume dimensions
      if len(image_data.shape) != len(args.volume):
          logger.critical(
              "The supplied input image is of different dimension as the sub volume requested ({} to {})".format(
                  len(image_data.shape), len(args.volume)
              )
          )
          raise ArgumentError(
              "The supplied input image is of different dimension as the sub volume requested ({} to {})".format(
                  len(image_data.shape), len(args.volume)
              )
          )
  
      # execute extraction of the sub-area
      logger.info("Extracting sub-volume...")
      index = [slice(x[0], x[1]) for x in args.volume]
      volume = image_data[index]
  
      # check if the output image contains data
      if 0 == len(volume):
          logger.exception(
              "The extracted sub-volume is of zero-size. This usual means that the supplied volume coordinates and the image coordinates do not intersect. Exiting the application."
          )
          sys.exit(-1)
  
      # squeeze extracted sub-volume for the case in which one dimensions has been eliminated
      volume = scipy.squeeze(volume)
  
      logger.debug(
          "Extracted volume is of shape {}.".format(volume.shape)
      )
  
      # save results in same format as input image
      save(volume, args.output, image_header, args.force)
  
      logger.info("Successfully terminated.")
  
file_path: medpy/bin/medpy_extract_sub_volume.py
imports: from argparse import RawTextHelpFormatter
  import argparse
  import logging
  import sys
  import os
  import scipy
  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