class_docstr: Template class for volumetric (3D/4D) images
class_docstr_tok: ["Template","class","for","volumetric","(","3D\/4D",")","images"]
docstr: Harmonize header with image data and affine
  
  >>> data = np.zeros((2,3,4))
  >>> affine = np.diag([1.0,2.0,3.0,1.0])
  >>> img = SpatialImage(data, affine)
  >>> img.shape == (2, 3, 4)
  True
  >>> img.update_header()
  >>> img.header.get_data_shape() == (2, 3, 4)
  True
  >>> img.header.get_zooms()
  (1.0, 2.0, 3.0)
docstr_tok: ["Harmonize","header","with","image","data","and","affine",">",">",">","data","=","np.zeros","(","(","2,3,4",")",")",">",">",">","affine","=","np.diag","(","[","1.0,2.0,3.0,1.0","]",")",">",">",">","img","=","SpatialImage","(","data",",","affine",")",">",">",">","img.shape","==","(","2",",","3",",","4",")","True",">",">",">","img.update_header","(",")",">",">",">","img.header.get_data_shape","(",")","==","(","2",",","3",",","4",")","True",">",">",">","img.header.get_zooms","(",")","(","1.0",",","2.0",",","3.0",")"]
code: def update_header(self) -> None:
      """Harmonize header with image data and affine
  
      >>> data = np.zeros((2,3,4))
      >>> affine = np.diag([1.0,2.0,3.0,1.0])
      >>> img = SpatialImage(data, affine)
      >>> img.shape == (2, 3, 4)
      True
      >>> img.update_header()
      >>> img.header.get_data_shape() == (2, 3, 4)
      True
      >>> img.header.get_zooms()
      (1.0, 2.0, 3.0)
      """
      hdr = self._header
      shape = self._dataobj.shape
      # We need to update the header if the data shape has changed.  It's a
      # bit difficult to change the data shape using the standard API, but
      # maybe it happened
      if hdr.get_data_shape() != shape:
          hdr.set_data_shape(shape)
      # If the affine is not None, and it is different from the main affine
      # in the header, update the header
      if self._affine is None:
          return
      if np.allclose(self._affine, hdr.get_best_affine()):
          return
      self._affine2header()
  
imports: from __future__ import annotations
  import io
  import typing
  from collections.abc import Sequence
  from typing import Literal
  import numpy
  from .arrayproxy import ArrayLike
  from .casting import sctypes_aliases
  from .dataobj_images import DataobjImage
  from .filebasedimages import FileBasedHeader, FileBasedImage
  from .fileholders import FileMap
  from .fileslice import canonical_slicers
  from .orientations import apply_orientation, inv_ornt_aff
  from .viewers import OrthoSlicer3D
  from .volumeutils import shape_zoom_affine
label_desc: Use image node_id 3 for calling the SpatialImage obj's underlying member method code with example usage: obj.update_header() without return types