class_docstr: Write data and metadata into files on disk using ITK-python.
  
  .. code-block:: python
  
      import numpy as np
      from monai.data import ITKWriter
  
      np_data = np.arange(48).reshape(3, 4, 4)
  
      # write as 3d spatial image no channel
      writer = ITKWriter(output_dtype=np.float32)
      writer.set_data_array(np_data, channel_dim=None)
      # optionally set metadata affine
      writer.set_metadata({"affine": np.eye(4), "original_affine": -1 * np.eye(4)})
      writer.write("test1.nii.gz")
  
      # write as 2d image, channel-first
      writer = ITKWriter(output_dtype=np.uint8)
      writer.set_data_array(np_data, channel_dim=0)
      writer.set_metadata({"spatial_shape": (5, 5)})
      writer.write("test1.png")
class_docstr_tok: ["Write","data","and","metadata","into","files","on","disk","using","ITK-python",".","..","code-block",":",":","python","import","numpy","as","np","from","monai.data","import","ITKWriter","np_data","=","np.arange","(","48",")",".reshape","(","3",",","4",",","4",")","#","write","as","3d","spatial","image","no","channel","writer","=","ITKWriter","(","output_dtype=np.float32",")","writer.set_data_array","(","np_data",",","channel_dim=None",")","#","optionally","set","metadata","affine","writer.set_metadata","(","{","``","affine","''",":","np.eye","(","4",")",",","``","original_affine","''",":","-1","*","np.eye","(","4",")","}",")","writer.write","(","``","test1.nii.gz","''",")","#","write","as","2d","image",",","channel-first","writer","=","ITKWriter","(","output_dtype=np.uint8",")","writer.set_data_array","(","np_data",",","channel_dim=0",")","writer.set_metadata","(","{","``","spatial_shape","''",":","(","5",",","5",")","}",")","writer.write","(","``","test1.png","''",")"]
docstr: Args:
      output_dtype: output data type.
      affine_lps_to_ras: whether to convert the affine matrix from "LPS" to "RAS". Defaults to ``True``.
          Set to ``True`` to be consistent with ``NibabelWriter``,
          otherwise the affine matrix is assumed already in the ITK convention.
          Set to ``None`` to use ``data_array.meta[MetaKeys.SPACE]`` to determine the flag.
      kwargs: keyword arguments passed to ``ImageWriter``.
  
  The constructor will create ``self.output_dtype`` internally.
  ``affine`` and ``channel_dim`` are initialized as instance members (default ``None``, ``0``):
  
      - user-specified ``affine`` should be set in ``set_metadata``,
      - user-specified ``channel_dim`` should be set in ``set_data_array``.
docstr_tok: ["Args",":","output_dtype",":","output","data","type",".","affine_lps_to_ras",":","whether","to","convert","the","affine","matrix","from","``","LPS","''","to","``","RAS","''",".","Defaults","to","``","True","``",".","Set","to","``","True","``","to","be","consistent","with","``","NibabelWriter","``",",","otherwise","the","affine","matrix","is","assumed","already","in","the","ITK","convention",".","Set","to","``","None","``","to","use","``","data_array.meta","[","MetaKeys.SPACE","]","``","to","determine","the","flag",".","kwargs",":","keyword","arguments","passed","to","``","ImageWriter","``",".","The","constructor","will","create","``","self.output_dtype","``","internally",".","``","affine","``","and","``","channel_dim","``","are","initialized","as","instance","members","(","default","``","None","``",",","``","0","``",")",":","-","user-specified","``","affine","``","should","be","set","in","``","set_metadata","``",",","-","user-specified","``","channel_dim","``","should","be","set","in","``","set_data_array","``","."]
code: def __init__(
      self,
      output_dtype: DtypeLike = np.float32,
      affine_lps_to_ras: bool | None = True,
      **kwargs,
  ):
      """
      Args:
          output_dtype: output data type.
          affine_lps_to_ras: whether to convert the affine matrix from "LPS" to "RAS". Defaults to ``True``.
              Set to ``True`` to be consistent with ``NibabelWriter``,
              otherwise the affine matrix is assumed already in the ITK convention.
              Set to ``None`` to use ``data_array.meta[MetaKeys.SPACE]`` to determine the flag.
          kwargs: keyword arguments passed to ``ImageWriter``.
  
      The constructor will create ``self.output_dtype`` internally.
      ``affine`` and ``channel_dim`` are initialized as instance members (default ``None``, ``0``):
  
          - user-specified ``affine`` should be set in ``set_metadata``,
          - user-specified ``channel_dim`` should be set in ``set_data_array``.
      """
      super().__init__(
          output_dtype=output_dtype,
          affine_lps_to_ras=affine_lps_to_ras,
          affine=None,
          channel_dim=0,
          **kwargs,
      )
  
imports: from __future__ import annotations
  from collections.abc import Mapping, Sequence
  from typing import TYPE_CHECKING, Any, cast
  import numpy
  from monai.apps.utils import get_logger
  from monai.config import DtypeLike, NdarrayOrTensor, PathLike
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import affine_to_spacing, ensure_tuple, ensure_tuple_rep, orientation_ras_lps, to_affine_nd
  from monai.transforms.spatial.array import Resize, SpatialResample
  from monai.transforms.utils_pytorch_numpy_unification import ascontiguousarray, moveaxis
  from monai.utils import GridSampleMode, GridSamplePadMode, InterpolateMode, MetaKeys, OptionalImportError, SpaceKeys, convert_data_type, convert_to_tensor, get_equivalent_dtype, look_up_option, optional_import, require_pkg
label_desc: Use image node_id 1 to create a new ITKWriter object from inherited base classes: ImageWriter with example: obj = ITKWriter(output_dtype, affine_lps_to_ras)