docstr: Spatiotemporal realignment class for fMRI series. This class
  is similar to `Realign4d` but provides a more flexible API for
  initialization in order to make it easier to declare slice
  acquisition times for standard sequences.
  
  Warning: this class is deprecated; please use :class:`SpaceTimeRealign`
  instead.
  
  Parameters
  ----------
  images : image or list of images
    Single or multiple input 4d images representing one or
    several fMRI runs.
  
  slice_order : str or array-like
    If str, one of {'ascending', 'descending'}. If array-like,
    then the order in which the slices were collected in
    time. For instance, the following represents an ascending
    contiguous sequence:
  
    slice_order = [0, 1, 2, ...]
  
    Note that `slice_order` differs from the argument used
    e.g. in the SPM slice timing routine in that it maps spatial
    slice positions to slice times. It is a mapping from space
    to time, while SPM conventionally uses the reverse mapping
    from time to space. For example, for an interleaved sequence
    with 10 slices, where we acquired slice 0 (in space) first,
    then slice 2 (in space) etc, `slice_order` would be [0, 5,
    1, 6, 2, 7, 3, 8, 4, 9]
  
    Using `slice_order` assumes that the inter-slice acquisition
    time is constant throughout acquisition. If this is not the
    case, use the `slice_times` argument instead and leave
    `slice_order` to None.
  
  tr : float
    Inter-scan repetition time, i.e. the time elapsed between
    two consecutive scans. The unit in which `tr` is given is
    arbitrary although it needs to be consistent with the
    `tr_slices` and `start` arguments if provided. If None, `tr`
    is computed internally assuming a regular slice acquisition
    scheme.
  
  tr_slices : float
    Inter-slice repetition time, same as `tr` for slices. If
    None, acquisition is assumed regular and `tr_slices` is set
    to `tr` divided by the number of slices.
  
  start : float
    Starting acquisition time (time of the first acquired slice)
    respective to the time origin for resampling. `start` is
    assumed to be given in the same unit as `tr`. Setting
    `start=0` means that the resampled data will be synchronous
    with the first acquired slice. Setting `start=-tr/2` means
    that the resampled data will be synchronous with the slice
    acquired at half repetition time.
  
  time_interp: bool
    Tells whether time interpolation is used or not within the
    realignment algorithm. If False, slices are considered to be
    acquired all at the same time, thus no slice timing
    correction will be performed.
  
  interleaved : bool
    Deprecated argument.
  
    Tells whether slice acquisition order is interleaved in a
    certain sense. Setting `interleaved` to True or False will
    trigger an error unless `slice_order` is 'ascending' or
    'descending' and `slice_times` is None.
  
    If slice_order=='ascending' and interleaved==True, the
    assumed slice order is (assuming 10 slices):
  
    [0, 5, 1, 6, 2, 7, 3, 8, 4, 9]
  
    If slice_order=='descending' and interleaved==True, the
    assumed slice order is:
  
    [9, 4, 8, 3, 7, 2, 6, 1, 5, 0]
  
    WARNING: given that there exist other types of interleaved
    acquisitions depending on scanner settings and
    manufacturers, you should refrain from using the
    `interleaved` keyword argument unless you are sure what you
    are doing. It is generally safer to explicitly input
    `slice_order` or `slice_times`.
  
  slice_times : None, str or array-like
  
    This argument can be used instead of `slice_order`,
    `tr_slices`, `start` and `time_interp` altogether.
  
    If None, slices are assumed to be acquired simultaneously
    hence no slice timing correction is performed. If
    array-like, then `slice_times` gives the slice acquisition
    times along the slice axis in units that are consistent with
    the provided `tr`.
  
    Generally speaking, the following holds for sequences with
    constant inter-slice repetition time `tr_slices`:
  
    `slice_times` = `start` + `tr_slices` * `slice_order`
  
    For other sequences such as, e.g., sequences with
    simultaneously acquired slices, it is necessary to input
    `slice_times` explicitly along with `tr`.
  
  slice_info : None or tuple, optional
    None, or a tuple with slice axis as the first element and
    direction as the second, for instance (2, 1). If None, then
    the slice axis and direction are guessed from the first
    run's affine assuming that slices are collected along the
    closest axis to the z-axis. This means that we assume by
    default an axial acquisition with slice axis pointing from
    bottom to top of the head.
docstr_tok: ["Spatiotemporal","realignment","class","for","fMRI","series",".","This","class","is","similar","to","`","Realign4d","`","but","provides","a","more","flexible","API","for","initialization","in","order","to","make","it","easier","to","declare","slice","acquisition","times","for","standard","sequences",".","Warning",":","this","class","is","deprecated",";","please","use",":","class",":","`","SpaceTimeRealign","`","instead",".","Parameters","--","--","--","--","--","images",":","image","or","list","of","images","Single","or","multiple","input","4d","images","representing","one","or","several","fMRI","runs",".","slice_order",":","str","or","array-like","If","str",",","one","of","{","'ascending","'",",","'descending","'","}",".","If","array-like",",","then","the","order","in","which","the","slices","were","collected","in","time",".","For","instance",",","the","following","represents","an","ascending","contiguous","sequence",":","slice_order","=","[","0",",","1",",","2",",","...","]","Note","that","`","slice_order","`","differs","from","the","argument","used","e.g",".","in","the","SPM","slice","timing","routine","in","that","it","maps","spatial","slice","positions","to","slice","times",".","It","is","a","mapping","from","space","to","time",",","while","SPM","conventionally","uses","the","reverse","mapping","from","time","to","space",".","For","example",",","for","an","interleaved","sequence","with","10","slices",",","where","we","acquired","slice","0","(","in","space",")","first",",","then","slice","2","(","in","space",")","etc",",","`","slice_order","`","would","be","[","0",",","5",",","1",",","6",",","2",",","7",",","3",",","8",",","4",",","9","]","Using","`","slice_order","`","assumes","that","the","inter-slice","acquisition","time","is","constant","throughout","acquisition",".","If","this","is","not","the","case",",","use","the","`","slice_times","`","argument","instead","and","leave","`","slice_order","`","to","None",".","tr",":","float","Inter-scan","repetition","time",",","i.e",".","the","time","elapsed","between","two","consecutive","scans",".","The","unit","in","which","`","tr","`","is","given","is","arbitrary","although","it","needs","to","be","consistent","with","the","`","tr_slices","`","and","`","start","`","arguments","if","provided",".","If","None",",","`","tr","`","is","computed","internally","assuming","a","regular","slice","acquisition","scheme",".","tr_slices",":","float","Inter-slice","repetition","time",",","same","as","`","tr","`","for","slices",".","If","None",",","acquisition","is","assumed","regular","and","`","tr_slices","`","is","set","to","`","tr","`","divided","by","the","number","of","slices",".","start",":","float","Starting","acquisition","time","(","time","of","the","first","acquired","slice",")","respective","to","the","time","origin","for","resampling",".","`","start","`","is","assumed","to","be","given","in","the","same","unit","as","`","tr","`",".","Setting","`","start=0","`","means","that","the","resampled","data","will","be","synchronous","with","the","first","acquired","slice",".","Setting","`","start=-tr\/2","`","means","that","the","resampled","data","will","be","synchronous","with","the","slice","acquired","at","half","repetition","time",".","time_interp",":","bool","Tells","whether","time","interpolation","is","used","or","not","within","the","realignment","algorithm",".","If","False",",","slices","are","considered","to","be","acquired","all","at","the","same","time",",","thus","no","slice","timing","correction","will","be","performed",".","interleaved",":","bool","Deprecated","argument",".","Tells","whether","slice","acquisition","order","is","interleaved","in","a","certain","sense",".","Setting","`","interleaved","`","to","True","or","False","will","trigger","an","error","unless","`","slice_order","`","is","'ascending","'","or","'descending","'","and","`","slice_times","`","is","None",".","If","slice_order=='ascending","'","and","interleaved==True",",","the","assumed","slice","order","is","(","assuming","10","slices",")",":","[","0",",","5",",","1",",","6",",","2",",","7",",","3",",","8",",","4",",","9","]","If","slice_order=='descending","'","and","interleaved==True",",","the","assumed","slice","order","is",":","[","9",",","4",",","8",",","3",",","7",",","2",",","6",",","1",",","5",",","0","]","WARNING",":","given","that","there","exist","other","types","of","interleaved","acquisitions","depending","on","scanner","settings","and","manufacturers",",","you","should","refrain","from","using","the","`","interleaved","`","keyword","argument","unless","you","are","sure","what","you","are","doing",".","It","is","generally","safer","to","explicitly","input","`","slice_order","`","or","`","slice_times","`",".","slice_times",":","None",",","str","or","array-like","This","argument","can","be","used","instead","of","`","slice_order","`",",","`","tr_slices","`",",","`","start","`","and","`","time_interp","`","altogether",".","If","None",",","slices","are","assumed","to","be","acquired","simultaneously","hence","no","slice","timing","correction","is","performed",".","If","array-like",",","then","`","slice_times","`","gives","the","slice","acquisition","times","along","the","slice","axis","in","units","that","are","consistent","with","the","provided","`","tr","`",".","Generally","speaking",",","the","following","holds","for","sequences","with","constant","inter-slice","repetition","time","`","tr_slices","`",":","`","slice_times","`","=","`","start","`","+","`","tr_slices","`","*","`","slice_order","`","For","other","sequences","such","as",",","e.g.",",","sequences","with","simultaneously","acquired","slices",",","it","is","necessary","to","input","`","slice_times","`","explicitly","along","with","`","tr","`",".","slice_info",":","None","or","tuple",",","optional","None",",","or","a","tuple","with","slice","axis","as","the","first","element","and","direction","as","the","second",",","for","instance","(","2",",","1",")",".","If","None",",","then","the","slice","axis","and","direction","are","guessed","from","the","first","run","'s","affine","assuming","that","slices","are","collected","along","the","closest","axis","to","the","z-axis",".","This","means","that","we","assume","by","default","an","axial","acquisition","with","slice","axis","pointing","from","bottom","to","top","of","the","head","."]
code: def __init__(
      self,
      images,
      slice_order=None,
      tr=None,
      tr_slices=None,
      start=0.0,
      interleaved=None,
      time_interp=None,
      slice_times=None,
      affine_class=Rigid,
      slice_info=None,
  ):
      """
      Spatiotemporal realignment class for fMRI series. This class
      is similar to `Realign4d` but provides a more flexible API for
      initialization in order to make it easier to declare slice
      acquisition times for standard sequences.
  
      Warning: this class is deprecated; please use :class:`SpaceTimeRealign`
      instead.
  
      Parameters
      ----------
      images : image or list of images
        Single or multiple input 4d images representing one or
        several fMRI runs.
  
      slice_order : str or array-like
        If str, one of {'ascending', 'descending'}. If array-like,
        then the order in which the slices were collected in
        time. For instance, the following represents an ascending
        contiguous sequence:
  
        slice_order = [0, 1, 2, ...]
  
        Note that `slice_order` differs from the argument used
        e.g. in the SPM slice timing routine in that it maps spatial
        slice positions to slice times. It is a mapping from space
        to time, while SPM conventionally uses the reverse mapping
        from time to space. For example, for an interleaved sequence
        with 10 slices, where we acquired slice 0 (in space) first,
        then slice 2 (in space) etc, `slice_order` would be [0, 5,
        1, 6, 2, 7, 3, 8, 4, 9]
  
        Using `slice_order` assumes that the inter-slice acquisition
        time is constant throughout acquisition. If this is not the
        case, use the `slice_times` argument instead and leave
        `slice_order` to None.
  
      tr : float
        Inter-scan repetition time, i.e. the time elapsed between
        two consecutive scans. The unit in which `tr` is given is
        arbitrary although it needs to be consistent with the
        `tr_slices` and `start` arguments if provided. If None, `tr`
        is computed internally assuming a regular slice acquisition
        scheme.
  
      tr_slices : float
        Inter-slice repetition time, same as `tr` for slices. If
        None, acquisition is assumed regular and `tr_slices` is set
        to `tr` divided by the number of slices.
  
      start : float
        Starting acquisition time (time of the first acquired slice)
        respective to the time origin for resampling. `start` is
        assumed to be given in the same unit as `tr`. Setting
        `start=0` means that the resampled data will be synchronous
        with the first acquired slice. Setting `start=-tr/2` means
        that the resampled data will be synchronous with the slice
        acquired at half repetition time.
  
      time_interp: bool
        Tells whether time interpolation is used or not within the
        realignment algorithm. If False, slices are considered to be
        acquired all at the same time, thus no slice timing
        correction will be performed.
  
      interleaved : bool
        Deprecated argument.
  
        Tells whether slice acquisition order is interleaved in a
        certain sense. Setting `interleaved` to True or False will
        trigger an error unless `slice_order` is 'ascending' or
        'descending' and `slice_times` is None.
  
        If slice_order=='ascending' and interleaved==True, the
        assumed slice order is (assuming 10 slices):
  
        [0, 5, 1, 6, 2, 7, 3, 8, 4, 9]
  
        If slice_order=='descending' and interleaved==True, the
        assumed slice order is:
  
        [9, 4, 8, 3, 7, 2, 6, 1, 5, 0]
  
        WARNING: given that there exist other types of interleaved
        acquisitions depending on scanner settings and
        manufacturers, you should refrain from using the
        `interleaved` keyword argument unless you are sure what you
        are doing. It is generally safer to explicitly input
        `slice_order` or `slice_times`.
  
      slice_times : None, str or array-like
  
        This argument can be used instead of `slice_order`,
        `tr_slices`, `start` and `time_interp` altogether.
  
        If None, slices are assumed to be acquired simultaneously
        hence no slice timing correction is performed. If
        array-like, then `slice_times` gives the slice acquisition
        times along the slice axis in units that are consistent with
        the provided `tr`.
  
        Generally speaking, the following holds for sequences with
        constant inter-slice repetition time `tr_slices`:
  
        `slice_times` = `start` + `tr_slices` * `slice_order`
  
        For other sequences such as, e.g., sequences with
        simultaneously acquired slices, it is necessary to input
        `slice_times` explicitly along with `tr`.
  
      slice_info : None or tuple, optional
        None, or a tuple with slice axis as the first element and
        direction as the second, for instance (2, 1). If None, then
        the slice axis and direction are guessed from the first
        run's affine assuming that slices are collected along the
        closest axis to the z-axis. This means that we assume by
        default an axial acquisition with slice axis pointing from
        bottom to top of the head.
      """
      warnings.warn(
          "Please use SpaceTimeRealign instead of this class; "
          "We will soon remove this class",
          FutureWarning,
          stacklevel=2,
      )
      # if slice_times not None, make sure that parameters redundant
      # with slice times all have their default value
      if slice_times is not None:
          if (
              slice_order is not None
              or tr_slices is not None
              or start != 0.0
              or time_interp is not None
              or interleaved is not None
          ):
              raise ValueError(
                  "Attempting to set both `slice_times` "
                  "and other arguments redundant with it"
              )
          if tr is None:
              if len(slice_times) > 1:
                  tr = (
                      slice_times[-1]
                      + slice_times[1]
                      - 2 * slice_times[0]
                  )
              else:
                  tr = 2 * slice_times[0]
              warnings.warn(
                  "No `tr` entered. Assuming regular acquisition"
                  " with tr=%f" % tr
              )
      # case where slice_time is None
      else:
          # assume regular slice acquisition, therefore tr is
          # arbitrary
          if tr is None:
              tr = 1.0
          # if no slice order provided, assume synchronous slices
          if slice_order is None:
              if not time_interp == False:
                  raise ValueError(
                      "Slice order is requested "
                      "with time interpolation switched on"
                  )
              slice_times = 0.0
          else:
              # if slice_order is a key word, replace it with the
              # appropriate array of slice indices
              if slice_order in ("ascending", "descending"):
                  if isinstance(images, (list, tuple, np.array)):
                      xyz_img = as_xyz_image(images[0])
                  else:
                      xyz_img = as_xyz_image(images)
  
                  slice_axis, _ = guess_slice_axis_and_direction(
                      slice_info, xyz_affine(xyz_img)
                  )
                  nslices = xyz_img.shape[slice_axis]
                  if interleaved:
                      warnings.warn(
                          "`interleaved` keyword argument is "
                          "deprecated",
                          FutureWarning,
                          stacklevel=2,
                      )
                      aux = np.argsort(
                          list(range(0, nslices, 2))
                          + list(range(1, nslices, 2))
                      )
                  else:
                      aux = np.arange(nslices)
                  if slice_order == "descending":
                      aux = aux[::-1]
                  slice_order = aux
              # if slice_order is provided explicitly, issue a
              # warning and make sure interleaved is set to None
              else:
                  warnings.warn(
                      "Please make sure you are NOT using "
                      "SPM-style slice order declaration"
                  )
                  if interleaved is not None:
                      raise ValueError(
                          "`interleaved` should be None when "
                          "providing explicit slice order"
                      )
                  slice_order = np.asarray(slice_order)
              if tr_slices is None:
                  tr_slices = float(tr) / float(len(slice_order))
              if start is None:
                  start = 0.0
              slice_times = start + tr_slices * slice_order
  
      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 FmriRealign4d object from inherited base classes: Realign4d with example: obj = FmriRealign4d(images, slice_order, tr, tr_slices, start, interleaved, time_interp, slice_times, affine_class, slice_info)