Fork me on GitHub

pyhrf.sandbox.physio_params module

pyhrf.sandbox.physio_params.buildOrder1FiniteDiffMatrix_central(size, dt)

Returns a toeplitz matrix for central differences to correct for errors on the first and last points (due to the fact that there is no rf[-1] or rf[size] to average with):

  • uses the last point to calculate the first and vise-versa
  • this is acceptable bc the rf is assumed to begin & end at steady state (thus the first and last points should both be zero)
pyhrf.sandbox.physio_params.calc_linear_rfs(simu_brf, simu_prf, phy_params, dt, normalized_rfs=True)

Calculate ‘prf given brf’ and ‘brf given prf’ based on the a linearization around steady state of the physiological model as described in Friston 2000

Input:
  • simu_brf, simu_prf: brf and prf from the physiological simulation
    from which you wish to calculate the respective prf and brf. Assumed to be of size (1,hrf.size)
  • phy_params
  • normalized_rfs: set to True if simu_hrfs are normalized
Output:
  • calc_brf, calc_prf: np.arrays of shape (hrf.size, 1)
  • q_linear, v_linear: q and v calculated according to the linearized model

Note: These calculations do not account for any rescaling between brf and prf. This means the input simu_brf, simu_prf should NOT be rescaled.

** Warning**:
  • this function assumes prf.size == brf.size and uses this to build D, I
  • if making modifications: calc_brf, calc_prf have a truncation error (due to the finite difference matrix used) on the order of O(dt)^2. If for any reason a hack is later implemented to set the y-intecepts of brf_calc, prf_calc to zero by setting the first row of X4, X3 = 0, this will raise a singular matrix error in the calculation of calc_prf (due to X.I command), so this error is helpful in this case
pyhrf.sandbox.physio_params.create_bold_from_hbr_and_cbv(physiological_params, hbr, cbv)

Compute BOLD signal from HbR and blood volume variations obtained by a physiological model

pyhrf.sandbox.physio_params.create_evoked_physio_signals(physiological_params, paradigm, neural_efficacies, dt, integration_step=0.05)

Generate evoked hemodynamics signals by integrating a physiological model.

Parameters:
  • physiological_params (dict (<pname (str)> : <pvalue (float)>)) – parameters of the physiological model. In jde.sandbox.physio see PHY_PARAMS_FRISTON00, PHY_PARAMS_FMRII
  • paradigm (pyhrf.paradigm.Paradigm) – the experimental paradigm
  • neural_efficacies (np.ndarray (nb_conditions, nb_voxels, float)) – neural efficacies involved in flow inducing signal.
  • dt (float) – temporal resolution of the output signals, in second
  • integration_step (float) – time step used for integration, in second
Returns:

All generated signals, indexes of the first axis correspond to:

  • 0: flow inducing
  • 1: inflow
  • 2: blood volume
  • 3: [HbR]

Return type:

np.array((nb_signals, nb_scans, nb_voxels), float)

pyhrf.sandbox.physio_params.create_k_parameters(physiological_params)

Create field strength dependent parameters k1, k2, k3

pyhrf.sandbox.physio_params.create_omega_prf(primary_brf, dt, phy_params)

create prf from omega and brf

pyhrf.sandbox.physio_params.create_physio_brf(physiological_params, response_dt=0.5, response_duration=25.0, return_brf_q_v=False)

Generate a BOLD response function by integrating a physiological model and setting its driving input signal to a single impulse.

Parameters:
  • physiological_params (-) – <pvalue (float)>)): parameters of the physiological model. In jde.sandbox.physio see PHY_PARAMS_FRISTON00, PHY_PARAMS_FMRII…
  • response_dt (-) – temporal resolution of the response, in second
  • response_duration (-) – duration of the response, in second
Returns:

  • np.array(nb_time_coeffs, float) -> the BRF (normalized)
  • also return brf_not_normalized, q, v when return_prf_q_v=True (for error checking of v and q generation in calc_hrfs)

pyhrf.sandbox.physio_params.create_physio_prf(physiological_params, response_dt=0.5, response_duration=25.0, return_prf_q_v=False)

Generate a perfusion response function by setting the input driving signal of the given physiological model with a single impulse.

Parameters:
  • physiological_params (-) – <pvalue (float)>)): parameters of the physiological model. In jde.sandbox.physio see PHY_PARAMS_FRISTON00, PHY_PARAMS_FMRII…
  • response_dt (-) – temporal resolution of the response, in second
  • response_duration (-) – duration of the response, in second
Returns:

  • np.array(nb_time_coeffs, float) -> the PRF
  • also return brf_not_normalized, q, v when return_prf_q_v=True (for error checking of v and q generation in calc_hrfs)

pyhrf.sandbox.physio_params.create_tbg_neural_efficacies(physiological_params, condition_defs, labels)

Create neural efficacy from a truncated bi-Gaussian mixture.

Parameters:
  • physiological_params (dict (<param_name> : <param_value>)) – parameters of the physiological model
  • condition_defs (list of pyhrf.Condition) –

    list of condition definitions. Each item should have the following fields (moments of the mixture):

    • m_act (0<=float<eff_max): mean of activating component
    • v_act (0<float): variance of activating component
    • v_inact (0<float): variance of non-activating component
  • labels (np.array((nb_cond, nb_vox), int)) – binary activation states
Returns:

  • np.array(np.array((nb_cond, nb_vox), float)) – the generated neural efficacies
  • TODO (settle how to relate brls and prls to neural efficacy)

pyhrf.sandbox.physio_params.linear_rf_operator(rf_size, phy_params, dt, calculating_brf=False)
Calculates the linear operator A needed to convert brf to prf & vis-versa
prf = (A^{-1})brf brf = (A)prf
Inputs:
  • size of the prf and/or brf (assumed to be same)
  • physiological parameters
  • time resolution of data:
  • if you wish to calculate brf (return A), or prf (return inverse of A)
Outputs:
  • np.array of size (hrf_size,1) linear operator to convert hrfs
pyhrf.sandbox.physio_params.phy_integrate_euler(phy_params, tstep, stim, epsilon, Y0=None)

Integrate the ODFs of the physiological model with the Euler method.

Parameters:
  • phy_params (dict (<param_name> : <param_value>)) – parameters of the physiological model
  • tstep (float) – time step of the integration, in seconds.
  • stim (np.array(nb_steps, float)) – stimulation sequence with temporal resolution equal to the time step of the integration
  • epsilon (float) – neural efficacy
  • Y0 (np.array(4, float) | None) – initial values for the physiological signals. If None: [0, 1, 1, 1.] s f_in q v
Returns:

  • np.array((4, nb_steps), float) – the integrated physiological signals, where indexes of the first axis correspond to:
    • 0 : flow inducing
    • 1 : inflow
    • 2 : HbR
    • 3 : blood volume
  • TODO (should the output signals be rescaled wrt their value at rest?)