def get_aif_shift(time_series, bolus_arrival_index):
    """
    Calculates the arterial input function offset as:

    *t*\\ :sub:`arrival` - *t*\\ :sub:`0`

    where *t*\\ :sub:`0` is the first slice acquisition time
    and *t*\\ :sub:`arrival` averages the acquisition times at
    and immediately following bolus arrival.

    :param time_series: the modeling input 4D NIfTI image file path
    :param bolus_arrival_index: the bolus uptake series index
    :return: the parameter CSV file path
    """
    import os
    import csv
    import nibabel as nb
    import numpy as np
    from dcmstack.dcmmeta import NiftiWrapper
    from dcmstack import dcm_time_to_sec
    ts_nii = nb.load(time_series)
    ts_nw = NiftiWrapper(ts_nii)
    acq_time0 = dcm_time_to_sec(ts_nw.get_meta('AcquisitionTime', (0, 0, 0, 0))
        )
    acq_time1 = dcm_time_to_sec(ts_nw.get_meta('AcquisitionTime', (0, 0, 0,
        bolus_arrival_index)))
    acq_time2 = dcm_time_to_sec(ts_nw.get_meta('AcquisitionTime', (0, 0, 0,
        bolus_arrival_index + 1)))
    return (acq_time1 + acq_time2) / 2.0 - acq_time0
