docs: def to_mgh(obj, like=None, header=None, affine=None, extra=Ellipsis):
      '''
      to_mgh(obj) yields an MGHmage object that is as equivalent as possible to the given object obj.
        If obj is an MGHImage already and no changes are requested, then it is returned unmolested;
        otherwise, the optional arguments can be used to edit the header, affine, and exta.
  
      The following options are accepted:
        * like (default: None) may be provided to give a guide for the various header- and meta-data
          that is included in the image. If this is a nifti image object, its meta-data are used; if
          this is a subject, then the meta-data are deduced from the subject's voxel and native
          orientation matrices. All other specific options below override anything deduced from the
          like argument.
        * header (default: None) may be a Nifti1 or Niti2 image header to be used as the nifti header
          or to replace the header in a new image.
        * affine (default: None) may specify the affine transform to be given to the image object.
        * extra (default: Ellipsis) may specify an extra mapping for storage with the image data; the
          default value Ellipsis indicates that such a mapping should be left as is if it already
          exists in the obj or in the like option and should otherwise be empty.
      '''
      obj0 = obj
      # First go from like to explicit versions of affine and header:
      if like is not None:
          if isinstance(like, nib.analyze.AnalyzeHeader) or isinstance(obj, fsmgh.MGHHeader):
              if header is None: header = like
          elif isinstance(like, nib.analyze.SpatialImage):
              if header is None: header = like.header
              if affine is None: affine = like.affine
              if extra is Ellipsis: extra = like.extra
          elif isinstance(like, mri.Subject):
              if affine is None: affine = like.voxel_to_native_matrix
          else:
              raise ValueError('Could not interpret like argument with type %s' % type(like))
      # check to make sure that we have to change something:
      elif (isinstance(obj, fsmgh.MGHImage)):
          if ((header is None or obj.header is header) and
              (extra is Ellipsis or extra == obj.extra or (extra is None and len(obj.extra) == 0))):
              return obj
      # okay, now look at the header and affine etc.
      if header is None:
          if isinstance(obj, nib.analyze.SpatialImage):
              header = obj.header
          else:
              header = None
      if affine is None:
          if isinstance(obj, nib.analyze.SpatialImage):
              affine = obj.affine
          else:
              affine = np.eye(4)
      if extra is None: extra = {}
      # Figure out what the data is
      if isinstance(obj, nib.analyze.SpatialImage):
          obj = obj.dataobj
      else:
          obj = np.asarray(obj)
      if len(obj.shape) < 3: obj = np.asarray([[obj]])
      # make sure the dtype isn't a high-bit integer or float
      if np.issubdtype(obj.dtype, np.integer) and obj.dtype.itemsize > 4:
          obj = np.asarray(obj, dtype=np.int32)
      elif np.issubdtype(obj.dtype, np.floating) and obj.dtype.itemsize > 4:
          obj = np.asarray(obj, dtype=np.float32)
      # Okay, make a new object now...
      obj = fsmgh.MGHImage(obj, affine, header=header, extra=extra)
      # Okay, that's it!
      return obj