def spm_hrf_compat(t,<EOL>peak_delay=<NUM_LIT:6>,<EOL>under_delay=<NUM_LIT:16>,<EOL>peak_disp=<NUM_LIT:1>,<EOL>under_disp=<NUM_LIT:1>,<EOL>p_u_ratio=<NUM_LIT:6>,<EOL>normalize=True,<EOL>):
if len([v for v in [peak_delay, peak_disp, under_delay, under_disp]<EOL>if v <= <NUM_LIT:0>]):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>hrf = np.zeros(t.shape, dtype=np.float)<EOL>pos_t = t[t > <NUM_LIT:0>]<EOL>peak = sps.gamma.pdf(pos_t,<EOL>peak_delay / peak_disp,<EOL>loc=<NUM_LIT:0>,<EOL>scale=peak_disp)<EOL>undershoot = sps.gamma.pdf(pos_t,<EOL>under_delay / under_disp,<EOL>loc=<NUM_LIT:0>,<EOL>scale=under_disp)<EOL>hrf[t > <NUM_LIT:0>] = peak - undershoot / p_u_ratio<EOL>if not normalize:<EOL><INDENT>return hrf<EOL><DEDENT>return hrf / np.max(hrf)<EOL>
SPM HRF function from sum of two gamma PDFs

    Parameters
    ----------
    t : array-like
        vector of times at which to sample HRF
    peak_delay : float, optional
        delay of peak
    peak_disp : float, optional
        width (dispersion) of peak
    under_delay : float, optional
        delay of undershoot
    under_disp : float, optional
        width (dispersion) of undershoot
    p_u_ratio : float, optional
        peak to undershoot ratio.  Undershoot divided by this value before
        subtracting from peak.
    normalize : {True, False}, optional
        If True, divide HRF values by their sum before returning. SPM does this
        by default.

    Returns
    -------
    hrf : array
        vector length ``len(t)`` of samples from HRF at times `t`

    Notes
    -----
    [1] This function is designed to be partially compatible with SPMs
    `spm_hrf.m` function.
    [2] The SPN HRF is a *peak* gamma PDF (with location `peak_delay` and
    dispersion `peak_disp`), minus an *undershoot* gamma PDF (with location
    `under_delay` and dispersion `under_disp`, and divided by the `p_u_ratio`).
    [3] See ``spm_hrf.m`` in the SPM distribution.

    References:
    -----
    [1] http://nipy.org/
    [2] https://github.com/fabianp/hrf_estimation