class_docstr: Slicing interface that returns a new image with an updated affine
  
  Checks that an image's first three axes are spatial
class_docstr_tok: ["Slicing","interface","that","returns","a","new","image","with","an","updated","affine","Checks","that","an","image","'s","first","three","axes","are","spatial"]
docstr: Retrieve affine for current image, if sliced by a given index
  
  Applies scaling if down-sampling is applied, and adjusts the intercept
  to account for any cropping.
  
  Parameters
  ----------
  slicer : object
      something that can be used to slice an array as in
      ``arr[sliceobj]``
  
  Returns
  -------
  affine : (4,4) ndarray
      Affine with updated scale and intercept
docstr_tok: ["Retrieve","affine","for","current","image",",","if","sliced","by","a","given","index","Applies","scaling","if","down-sampling","is","applied",",","and","adjusts","the","intercept","to","account","for","any","cropping",".","Parameters","--","--","--","--","--","slicer",":","object","something","that","can","be","used","to","slice","an","array","as","in","``","arr","[","sliceobj","]","``","Returns","--","--","--","-","affine",":","(","4,4",")","ndarray","Affine","with","updated","scale","and","intercept"]
code: def slice_affine(self, slicer: object) -> np.ndarray:
      """Retrieve affine for current image, if sliced by a given index
  
      Applies scaling if down-sampling is applied, and adjusts the intercept
      to account for any cropping.
  
      Parameters
      ----------
      slicer : object
          something that can be used to slice an array as in
          ``arr[sliceobj]``
  
      Returns
      -------
      affine : (4,4) ndarray
          Affine with updated scale and intercept
      """
      slicer = self.check_slicing(slicer, return_spatial=True)
  
      # Transform:
      # sx  0  0 tx
      #  0 sy  0 ty
      #  0  0 sz tz
      #  0  0  0  1
      transform = np.eye(4, dtype=int)
  
      for i, subslicer in enumerate(slicer):
          if isinstance(subslicer, slice):
              if subslicer.step == 0:
                  raise ValueError("slice step cannot be 0")
              transform[i, i] = (
                  subslicer.step if subslicer.step is not None else 1
              )
              transform[i, 3] = subslicer.start or 0
          # If slicer is None, nothing to do
  
      return self.img.affine.dot(transform)
  
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 4 for calling the SpatialFirstSlicer obj's underlying member method code with example usage: obj.slice_affine(slicer) and returns: self