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: Resample ``data_array`` to ``output_spatial_shape`` if needed.
  Args:
      data_array: input data array. This method assumes the 'channel-last' format.
      output_spatial_shape: output spatial shape.
      mode: interpolation mode, default is ``InterpolateMode.BICUBIC``.
docstr_tok: ["Resample","``","data_array","``","to","``","output_spatial_shape","``","if","needed",".","Args",":","data_array",":","input","data","array",".","This","method","assumes","the","'channel-last","'","format",".","output_spatial_shape",":","output","spatial","shape",".","mode",":","interpolation","mode",",","default","is","``","InterpolateMode.BICUBIC","``","."]
code: def resample_and_clip(
      cls,
      data_array: NdarrayOrTensor,
      output_spatial_shape: Sequence[int] | None = None,
      mode: str = InterpolateMode.BICUBIC,
  ) -> np.ndarray:
      """
      Resample ``data_array`` to ``output_spatial_shape`` if needed.
      Args:
          data_array: input data array. This method assumes the 'channel-last' format.
          output_spatial_shape: output spatial shape.
          mode: interpolation mode, default is ``InterpolateMode.BICUBIC``.
      """
  
      data: np.ndarray = convert_data_type(data_array, np.ndarray)[0]
      if output_spatial_shape is not None:
          output_spatial_shape_ = ensure_tuple_rep(
              output_spatial_shape, 2
          )
          mode = look_up_option(mode, InterpolateMode)
          align_corners = (
              None
              if mode in (InterpolateMode.NEAREST, InterpolateMode.AREA)
              else False
          )
          xform = Resize(
              spatial_size=output_spatial_shape_,
              mode=mode,
              align_corners=align_corners,
          )
          _min, _max = np.min(data), np.max(data)
          if len(data.shape) == 3:
              data = np.moveaxis(data, -1, 0)  # to channel first
              data = convert_data_type(xform(data), np.ndarray)[0]  # type: ignore
              data = np.moveaxis(data, 0, -1)
          else:  # (H, W)
              data = np.expand_dims(data, 0)  # make a channel
              data = convert_data_type(xform(data), np.ndarray)[0][0]  # type: ignore
          if mode != InterpolateMode.NEAREST:
              data = np.clip(data, _min, _max)
      return data
  
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 6 for calling the PILWriter obj's underlying member method code with example usage: obj.resample_and_clip(cls, data_array, output_spatial_shape, mode) and returns: data