class_docstr: Write image data into files on disk using pillow.
  
  It's based on the Image module in PIL library:
  https://pillow.readthedocs.io/en/stable/reference/Image.html
  
  .. code-block:: python
  
      import numpy as np
      from monai.data import PILWriter
  
      np_data = np.arange(48).reshape(3, 4, 4)
      writer = PILWriter(np.uint8)
      writer.set_data_array(np_data, channel_dim=0)
      writer.write("test1.png", verbose=True)
class_docstr_tok: ["Write","image","data","into","files","on","disk","using","pillow",".","It","'s","based","on","the","Image","module","in","PIL","library",":","https",":","\/\/pillow.readthedocs.io\/en\/stable\/reference\/Image.html","..","code-block",":",":","python","import","numpy","as","np","from","monai.data","import","PILWriter","np_data","=","np.arange","(","48",")",".reshape","(","3",",","4",",","4",")","writer","=","PILWriter","(","np.uint8",")","writer.set_data_array","(","np_data",",","channel_dim=0",")","writer.write","(","``","test1.png","''",",","verbose=True",")"]
docstr: Convert ``data_array`` into 'channel-last' numpy ndarray.
  
  Args:
      data_array: input data array with the channel dimension specified by ``channel_dim``.
      channel_dim: channel dimension of the data array. Defaults to 0.
          ``None`` indicates data without any channel dimension.
      squeeze_end_dims: if ``True``, any trailing singleton dimensions will be removed.
      contiguous: if ``True``, the data array will be converted to a contiguous array. Default is ``False``.
      kwargs: keyword arguments passed to ``self.convert_to_channel_last``,
          currently support ``spatial_ndim``, defauting to ``2``.
docstr_tok: ["Convert","``","data_array","``","into","'channel-last","'","numpy","ndarray",".","Args",":","data_array",":","input","data","array","with","the","channel","dimension","specified","by","``","channel_dim","``",".","channel_dim",":","channel","dimension","of","the","data","array",".","Defaults","to","0",".","``","None","``","indicates","data","without","any","channel","dimension",".","squeeze_end_dims",":","if","``","True","``",",","any","trailing","singleton","dimensions","will","be","removed",".","contiguous",":","if","``","True","``",",","the","data","array","will","be","converted","to","a","contiguous","array",".","Default","is","``","False","``",".","kwargs",":","keyword","arguments","passed","to","``","self.convert_to_channel_last","``",",","currently","support","``","spatial_ndim","``",",","defauting","to","``","2","``","."]
code: def set_data_array(
      self,
      data_array: NdarrayOrTensor,
      channel_dim: int | None = 0,
      squeeze_end_dims: bool = True,
      contiguous: bool = False,
      **kwargs,
  ):
      """
      Convert ``data_array`` into 'channel-last' numpy ndarray.
  
      Args:
          data_array: input data array with the channel dimension specified by ``channel_dim``.
          channel_dim: channel dimension of the data array. Defaults to 0.
              ``None`` indicates data without any channel dimension.
          squeeze_end_dims: if ``True``, any trailing singleton dimensions will be removed.
          contiguous: if ``True``, the data array will be converted to a contiguous array. Default is ``False``.
          kwargs: keyword arguments passed to ``self.convert_to_channel_last``,
              currently support ``spatial_ndim``, defauting to ``2``.
      """
      self.data_obj = self.convert_to_channel_last(
          data=data_array,
          channel_dim=channel_dim,
          squeeze_end_dims=squeeze_end_dims,
          spatial_ndim=kwargs.pop("spatial_ndim", 2),
          contiguous=contiguous,
      )
  
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 2 for calling the PILWriter obj's underlying member method code with example usage: obj.set_data_array(data_array, channel_dim, squeeze_end_dims, contiguous) without return types