docstr: Spatiotemporal realignment class for fMRI series.
  
  This class gives a high-level interface to :class:`Realign4d`
  
  Parameters
  ----------
  images : image or list of images
      Single or multiple input 4d images representing one or several fMRI
      runs.
  tr : None or float or "header-allow-1.0"
      Inter-scan repetition time in seconds, i.e. the time elapsed between
      two consecutive scans. If None, an attempt is made to read the TR
      from the header, but an exception is thrown for values 0 or 1. A
      value of "header-allow-1.0" will signal to accept a header TR of 1.
  slice_times : str or callable or array-like
      If str, one of the function names in ``SLICETIME_FUNCTIONS``
      dictionary from :mod:`nipy.algorithms.slicetiming.timefuncs`.  If
      callable, a function taking two parameters: ``n_slices`` and ``tr``
      (number of slices in the images, inter-scan repetition time in
      seconds). This function returns a vector of times of slice
      acquisition $t_i$ for each slice $i$ in the volumes.  See
      :mod:`nipy.algorithms.slicetiming.timefuncs` for a collection of
      functions for common slice acquisition schemes. If array-like, then
      should be a slice time vector as above.
  slice_info : int or length 2 sequence
      If int, the axis in `images` that is the slice axis.  In a 4D image,
      this will often be axis = 2.  If a 2 sequence, then elements are
      ``(slice_axis, slice_direction)``, where ``slice_axis`` is the slice
      axis in the image as above, and ``slice_direction`` is 1 if the
      slices were acquired slice 0 first, slice -1 last, or -1 if acquired
      slice -1 first, slice 0 last.  If `slice_info` is an int, assume
      ``slice_direction`` == 1.
  affine_class : ``Affine`` class, optional
      transformation class to use to calculate transformations between
      the volumes. Default is :class:``Rigid``
docstr_tok: ["Spatiotemporal","realignment","class","for","fMRI","series",".","This","class","gives","a","high-level","interface","to",":","class",":","`","Realign4d","`","Parameters","--","--","--","--","--","images",":","image","or","list","of","images","Single","or","multiple","input","4d","images","representing","one","or","several","fMRI","runs",".","tr",":","None","or","float","or","``","header-allow-1.0","''","Inter-scan","repetition","time","in","seconds",",","i.e",".","the","time","elapsed","between","two","consecutive","scans",".","If","None",",","an","attempt","is","made","to","read","the","TR","from","the","header",",","but","an","exception","is","thrown","for","values","0","or","1",".","A","value","of","``","header-allow-1.0","''","will","signal","to","accept","a","header","TR","of","1.","slice_times",":","str","or","callable","or","array-like","If","str",",","one","of","the","function","names","in","``","SLICETIME_FUNCTIONS","``","dictionary","from",":","mod",":","`","nipy.algorithms.slicetiming.timefuncs","`",".","If","callable",",","a","function","taking","two","parameters",":","``","n_slices","``","and","``","tr","``","(","number","of","slices","in","the","images",",","inter-scan","repetition","time","in","seconds",")",".","This","function","returns","a","vector","of","times","of","slice","acquisition","$","t_i","$","for","each","slice","$","i","$","in","the","volumes",".","See",":","mod",":","`","nipy.algorithms.slicetiming.timefuncs","`","for","a","collection","of","functions","for","common","slice","acquisition","schemes",".","If","array-like",",","then","should","be","a","slice","time","vector","as","above",".","slice_info",":","int","or","length","2","sequence","If","int",",","the","axis","in","`","images","`","that","is","the","slice","axis",".","In","a","4D","image",",","this","will","often","be","axis","=","2",".","If","a","2","sequence",",","then","elements","are","``","(","slice_axis",",","slice_direction",")","``",",","where","``","slice_axis","``","is","the","slice","axis","in","the","image","as","above",",","and","``","slice_direction","``","is","1","if","the","slices","were","acquired","slice","0","first",",","slice","-1","last",",","or","-1","if","acquired","slice","-1","first",",","slice","0","last",".","If","`","slice_info","`","is","an","int",",","assume","``","slice_direction","``","==","1.","affine_class",":","``","Affine","``","class",",","optional","transformation","class","to","use","to","calculate","transformations","between","the","volumes",".","Default","is",":","class",":","``","Rigid","``"]
code: def __init__(
      self, images, tr, slice_times, slice_info, affine_class=Rigid
  ):
      """Spatiotemporal realignment class for fMRI series.
  
      This class gives a high-level interface to :class:`Realign4d`
  
      Parameters
      ----------
      images : image or list of images
          Single or multiple input 4d images representing one or several fMRI
          runs.
      tr : None or float or "header-allow-1.0"
          Inter-scan repetition time in seconds, i.e. the time elapsed between
          two consecutive scans. If None, an attempt is made to read the TR
          from the header, but an exception is thrown for values 0 or 1. A
          value of "header-allow-1.0" will signal to accept a header TR of 1.
      slice_times : str or callable or array-like
          If str, one of the function names in ``SLICETIME_FUNCTIONS``
          dictionary from :mod:`nipy.algorithms.slicetiming.timefuncs`.  If
          callable, a function taking two parameters: ``n_slices`` and ``tr``
          (number of slices in the images, inter-scan repetition time in
          seconds). This function returns a vector of times of slice
          acquisition $t_i$ for each slice $i$ in the volumes.  See
          :mod:`nipy.algorithms.slicetiming.timefuncs` for a collection of
          functions for common slice acquisition schemes. If array-like, then
          should be a slice time vector as above.
      slice_info : int or length 2 sequence
          If int, the axis in `images` that is the slice axis.  In a 4D image,
          this will often be axis = 2.  If a 2 sequence, then elements are
          ``(slice_axis, slice_direction)``, where ``slice_axis`` is the slice
          axis in the image as above, and ``slice_direction`` is 1 if the
          slices were acquired slice 0 first, slice -1 last, or -1 if acquired
          slice -1 first, slice 0 last.  If `slice_info` is an int, assume
          ``slice_direction`` == 1.
      affine_class : ``Affine`` class, optional
          transformation class to use to calculate transformations between
          the volumes. Default is :class:``Rigid``
      """
      if tr is None:
          tr = tr_from_header(images)
          if tr == 1:
              raise ValueError(
                  "A TR of 1 was found in the header. "
                  "This value often stands in for an unknown TR. "
                  "Please specify TR explicitly. Alternatively "
                  'consider setting TR to "header-allow-1.0".'
              )
      elif tr == "header-allow-1.0":
          tr = tr_from_header(images)
      if tr == 0:
          raise ValueError("Repetition time cannot be zero.")
      if slice_times is None:
          raise ValueError(
              "slice_times must be set for space/time "
              "registration; use SpaceRealign for space-only "
              "registration"
          )
      if slice_info is None:
          raise ValueError("slice_info cannot be None")
      try:
          len(slice_info)
      except TypeError:
          # Presumably an int
          slice_axis = slice_info
          slice_info = (slice_axis, 1)
      else:  # sequence
          slice_axis, slice_direction = slice_info
      if type(images) in (list, tuple):
          n_slices = images[0].shape[slice_axis]
      else:
          n_slices = images.shape[slice_axis]
      if isinstance(slice_times, str):
          slice_times = timefuncs.SLICETIME_FUNCTIONS[slice_times]
      if hasattr(slice_times, "__call__"):
          slice_times = slice_times(n_slices, tr)
      self._init(images, tr, slice_times, slice_info, affine_class)
  
imports: import os
  import warnings
  import numpy
  from nibabel import io_orientation
  from nibabel.affines import apply_affine
  from ...core.image.image_spaces import as_xyz_image, make_xyz_image, xyz_affine
  from ...io.nibcompat import get_header
  from ..slicetiming import timefuncs
  from ._registration import _cspline_sample3d, _cspline_sample4d, _cspline_transform
  from .affine import Affine, Rigid
  from .optimizer import configure_optimizer, use_derivatives
  from .type_check import check_type, check_type_and_shape
label_desc: Use image node_id 1 to create a new SpaceTimeRealign object from inherited base classes: Realign4d with example: obj = SpaceTimeRealign(images, tr, slice_times, slice_info, affine_class)