class_docstr: Class for MGH format image
class_docstr_tok: ["Class","for","MGH","format","image"]
docstr: Unconditionally set affine into the header
docstr_tok: ["Unconditionally","set","affine","into","the","header"]
code: def _affine2header(self):
      """Unconditionally set affine into the header"""
      hdr = self._header
      shape = np.array(self._dataobj.shape[:3])
  
      # for more information, go through save_mgh.m in FreeSurfer dist
      voxelsize = voxel_sizes(self._affine)
      Mdc = self._affine[:3, :3] / voxelsize
      c_ras = self._affine.dot(np.hstack((shape / 2.0, [1])))[:3]
  
      # Assign after we've had a chance to raise exceptions
      hdr["delta"] = voxelsize
      hdr["Mdc"] = Mdc.T
      hdr["Pxyz_c"] = c_ras
  
imports: from os.path import splitext
  import numpy
  from ..affines import from_matvec, voxel_sizes
  from ..arrayproxy import ArrayProxy, reshape_dataobj
  from ..batteryrunners import BatteryRunner, Report
  from ..filebasedimages import SerializableImage
  from ..fileholders import FileHolder
  from ..filename_parser import _stringify_path
  from ..openers import ImageOpener
  from ..spatialimages import HeaderDataError, SpatialHeader, SpatialImage
  from ..volumeutils import Recoder, array_from_file, array_to_file, endian_codes
  from ..wrapstruct import LabeledWrapStruct
label_desc: Use image node_id 6 for calling the MGHImage obj's underlying member method code with example usage: obj._affine2header() without return types