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)
  
      # copy the example image or generate empty image, depending on the modus
      if args.example:
          grid_image = scipy.zeros(
              args.example_image.shape, scipy.bool_
          )
          grid_header = args.example_header
      else:
          grid_image = scipy.zeros(args.shape, scipy.bool_)
          # !TODO: Find another solution for this
          # Saving and loading image once to generate a valid header
          tmp_dir = tempfile.mkdtemp()
          tmp_image = "{}/{}".format(
              tmp_dir, args.output.split("/")[-1]
          )
          save(grid_image, tmp_image)
          _, grid_header = load(tmp_image)
          try:
              os.remove(tmp_image)
              os.rmdir(tmp_dir)
          except Exception:
              pass
  
      # set the image attributes if supplied
      if args.pixelspacing:
          header.set_pixel_spacing(grid_header, args.pixelspacing)
      if args.offset:
          header.set_offset(grid_header, args.offset)
  
      # compute the right grid spacing for each dimension
      if args.real:
          grid_spacing = [
              int(round(sp / float(ps)))
              for sp, ps in zip(
                  args.spacing, header.get_pixel_spacing(grid_header)
              )
          ]
      else:
          grid_spacing = args.spacing
  
      # paint the grid into the empty image volume
      for dim in range(grid_image.ndim):
          if 0 == grid_spacing[dim]:
              continue  # skip dimension of 0 grid spacing supplied
          for offset in range(
              0, grid_image.shape[dim], grid_spacing[dim]
          ):
              slicer = [slice(None)] * grid_image.ndim
              slicer[dim] = slice(offset, offset + 1)
              grid_image[slicer] = True
  
      # saving resulting grid volume
      save(grid_image, args.output, grid_header, args.force)
  
file_path: medpy/bin/medpy_grid.py
imports: import os
  import argparse
  import logging
  import tempfile
  import scipy
  from medpy.core import Logger
  from medpy.io import load, save, header
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types