docs: def _expand_if_needed(self, dims, write_dims, start, offset):
          """
          expand the on-disk image if the indended write will extend
          beyond the existing dimensions
          """
          from operator import mul
  
          if numpy.isscalar(start):
              start_is_scalar = True
          else:
              start_is_scalar = False
  
          existing_size = reduce(mul, dims, 1)
          required_size = offset + reduce(mul, write_dims, 1)
  
          if required_size > existing_size:
              print(
                  "    required size:", required_size,
                  "existing size:", existing_size)
              # we need to expand the image
              ndim = len(dims)
              idim = len(write_dims)
  
              if start_is_scalar:
                  if start == 0:
                      start = [0]*ndim
                  else:
                      raise ValueError(
                          "When expanding "
                          "an existing image while writing, the start keyword "
                          "must have the same number of dimensions "
                          "as the image or be exactly 0, got %s " % start)
  
              if idim != ndim:
                  raise ValueError(
                      "When expanding "
                      "an existing image while writing, the input image "
                      "must have the same number of dimensions "
                      "as the original.  "
                      "Got %d instead of %d" % (idim, ndim))
              new_dims = []
              for i in xrange(ndim):
                  required_dim = start[i] + write_dims[i]
  
                  if required_dim < dims[i]:
                      # careful not to shrink the image!
                      dimsize = dims[i]
                  else:
                      dimsize = required_dim
  
                  new_dims.append(dimsize)
  
              print("    reshaping image to:", new_dims)
              self.reshape(new_dims)