cedalion.models.glm package
Submodules
cedalion.models.glm.basis_functions module
- class cedalion.models.glm.basis_functions.Gamma(tau, sigma, T)
Bases:
TemporalBasisFunction
Modified gamma function, optionally convolved with a square-wave.
- Parameters:
tau (
Union
[Quantity
,dict
[str
,Quantity
]]) – onset timesigma (
Union
[Quantity
,dict
[str
,Quantity
]]) – width of the HRFT (
Union
[Quantity
,dict
[str
,Quantity
]]) – convolution width
- class cedalion.models.glm.basis_functions.GaussianKernels(t_pre, t_post, t_delta, t_std)
Bases:
TemporalBasisFunction
A consecutive sequence of gaussian functions.
- Parameters:
t_pre (
Quantity
, [time]) – time before trial onsett_post (
Quantity
, [time]) – time after trial onsett_delta (
Quantity
, [time]) – the temporal spacing between consecutive gaussianst_std (
Quantiantity
, [time]) – time width of the gaussians
- class cedalion.models.glm.basis_functions.TemporalBasisFunction(convolve_over_duration)
Bases:
ABC
- cedalion.models.glm.basis_functions.generate_component_names(n_components)
- Return type:
list
[str
]
- cedalion.models.glm.basis_functions.get_other_dim(ts)
Returns the name of 3rd dimension (chromo, wavelength) and it coords.
- cedalion.models.glm.basis_functions.to_dict(param, keys)
Extends a parameter to a dict.
- cedalion.models.glm.basis_functions.to_unit(obj, unit)
Sets the unit of this quantity or the quantity values in the dict.
cedalion.models.glm.design_matrix module
- cedalion.models.glm.design_matrix.build_stim_array(time, onsets, duration)
Build an array indicating active stimulus periods.
The array values are 1 between onset and onset+duration and zero everywhere else.
- Parameters:
time (
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – the time axisonsets (
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – times of stimulus onsetsduration (
Union
[None
,_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – either durations of each stimulus or None, in which case the stimulus duration is set to one sample.
- Return type:
ndarray
- Returns:
The array denoting
- cedalion.models.glm.design_matrix.closest_short_channel(ts_long, ts_short, geo3d)
Create channel-wise regressors use closest nearby short channel.
- Parameters:
ts_long (
DataArray
) – time series of long channelsts_short (
DataArray
) – time series of short channelsgeo3d (
DataArray
) – probe geometry
- Returns:
channel-wise regressor
- cedalion.models.glm.design_matrix.construct_afni_gamma_basis(t_hrf, params_basis)
- cedalion.models.glm.design_matrix.construct_basis_functions(t_hrf, idx_basis, params_basis)
- cedalion.models.glm.design_matrix.construct_gaussian_basis(t_hrf, params_basis)
- cedalion.models.glm.design_matrix.construct_individual_basis(t_hrf, params_basis)
- cedalion.models.glm.design_matrix.construct_modified_gamma_basis(t_hrf, params_basis)
- cedalion.models.glm.design_matrix.construct_modified_gamma_deriv_basis(t_hrf, params_basis)
- cedalion.models.glm.design_matrix.get_ss_regressors(y, geo3d, ss_method='closest', ss_tresh=1.5, as_xarray=False)
Get short separation channels for each long channel.
- Parameters:
y (
DataArray
) – xarray.DataArray of the data (time x chromo x channels)geo3d (
DataArray
) – xarray.DataArray of the 3D geometry (no. of sources/detectors x dim pos)ss_method – method for determining short separation channels (“nearest”, “corr”)
ss_tresh (
float
) – threshold for short separation channels (in cm)get_data – whether to return the short channel data (True) or the short channel names (False)
as_xarray (
bool
) – TBD
- Returns:
xarray.DataArray of short separation channels (channels x chromo)
- Return type:
ss
- cedalion.models.glm.design_matrix.get_third_dimension(ts)
- cedalion.models.glm.design_matrix.make_design_matrix(ts_long, ts_short, stim, geo3d, basis_function, drift_order, short_channel_method)
Generate the design matrix for the GLM.
- Parameters:
ts_long (
DataArray
) – time series of long distance channelsts_short (
Optional
[DataArray
]) – time series of short distance channelsstim (
DataFrame
) – stimulus DataFramegeo3d (
DataArray
) – probe geometrybasis_function (
TemporalBasisFunction
) – the temporal basis function(s) to model the HRFdrift_order (
int
|None
) – if not None specify the highest polynomial order of the drift termsshort_channel_method (
str
|None
) – can be ‘closest’ or ‘max_corr’ and specifies the method to add short channel information ot the design matrix
- Returns:
A tuple containing the global design_matrix and a list of channel-wise regressors.
- cedalion.models.glm.design_matrix.make_drift_regressors(ts, drift_order)
- Return type:
DataArray
- cedalion.models.glm.design_matrix.make_hrf_regressors(ts, stim, basis_function)
Create regressors modelling the hemodynamic response to stimuli.
- cedalion.models.glm.design_matrix.max_corr_short_channel(ts_long, ts_short)
Create channel-wise regressors using the most correlated short channels.
For each long channel the short channel is selected that has the highest correleation coefficient in any wavelength or chromophore.
- Parameters:
ts_long (
DataArray
) – time series of long channelsts_short (
DataArray
) – time series of short channels
- Returns:
channel-wise regressors
- cedalion.models.glm.design_matrix.pad_time_axis(time, onsets)
cedalion.models.glm.solve module
- cedalion.models.glm.solve.fit(ts, design_matrix, channel_wise_regressors=None, noise_model='ols')
Fit design matrix to data.
- Parameters:
ts (
DataArray
) – the time series to be modeleddesign_matrix (
DataArray
) – DataArray with dims time, regressor, chromochannel_wise_regressors (
list
[DataArray
] |None
) – optional list of design matrices, with additional channel dimensionnoise_model – must be ‘ols’ for the moment
- Returns:
thetas as a DataArray
- cedalion.models.glm.solve.hash_channel_wise_regressor(regressor)
Hashes each channel slice of the regressor array.
- Parameters:
regressor (
DataArray
) – array of channel-wise regressors. Dims (channel, regressor, time, chromo|wavelength)- Return type:
list
[int
]- Returns:
A list of hash values, one hash for each channel.
- cedalion.models.glm.solve.iter_design_matrix(ts, design_matrix, channel_wise_regressors=None, channel_groups=None)
- cedalion.models.glm.solve.predict(ts, thetas, design_matrix, channel_wise_regressors=None)
- Return type:
DataArray
Module contents
Tools for describing fNIRS data with general linear models.