code: def main():
      args = getArguments(getParser())
  
      # prepare logger
      logger = Logger.getInstance()
      if args.debug:
          logger.setLevel(logging.DEBUG)
      elif args.verbose:
          logger.setLevel(logging.INFO)
  
      data_3d, _ = load(args.input)
  
      # check parameters
      if args.dimension >= data_3d.ndim or args.dimension < 0:
          raise ArgumentError(
              "The image has only {} dimensions. The supplied target dimension {} exceeds this number.".format(
                  data_3d.ndim, args.dimension
              )
          )
      if not 0 == data_3d.shape[args.dimension] % args.offset:
          raise ArgumentError(
              "The number of slices {} in the target dimension {} of the image shape {} is not dividable by the supplied number of consecutive slices {}.".format(
                  data_3d.shape[args.dimension],
                  args.dimension,
                  data_3d.shape,
                  args.offset,
              )
          )
  
      # prepare empty target volume
      volumes_3d = data_3d.shape[args.dimension] / args.offset
      shape_4d = list(data_3d.shape)
      shape_4d[args.dimension] = volumes_3d
      data_4d = scipy.zeros(
          [args.offset] + shape_4d, dtype=data_3d.dtype
      )
  
      logger.debug(
          "Separating {} slices into {} 3D volumes of thickness {}.".format(
              data_3d.shape[args.dimension], volumes_3d, args.offset
          )
      )
  
      # iterate over 3D image and create sub volumes which are then added to the 4d volume
      for idx in range(args.offset):
          # collect the slices
          for sl in range(volumes_3d):
              idx_from = [slice(None), slice(None), slice(None)]
              idx_from[args.dimension] = slice(
                  idx + sl * args.offset, idx + sl * args.offset + 1
              )
              idx_to = [slice(None), slice(None), slice(None)]
              idx_to[args.dimension] = slice(sl, sl + 1)
              # print 'Slice {} to {}.'.format(idx_from, idx_to)
              data_4d[idx][idx_to] = data_3d[idx_from]
  
      # flip dimensions such that the newly created is the last
      data_4d = scipy.swapaxes(data_4d, 0, 3)
  
      # save resulting 4D volume
      save(data_4d, args.output, False, args.force)
  
      logger.info("Successfully terminated.")
  
file_path: medpy/bin/medpy_dicom_to_4D.py
imports: import argparse
  import logging
  import scipy
  from medpy.core import Logger
  from medpy.io import load, save
  from medpy.core.exceptions import ArgumentError
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types