osl_ephys.glm.glm_base#

Classes#

GLMBaseResult

A class for GLM-Epochs fitted to MNE-Python Raw objects.

GroupGLMBaseResult

A class for group level GLM-Epochs fitted across mmultiple first-level

BaseSensorPerm

A base class for sensor x frequency and sensor x time permutation tests computed from a

SensorMaxStatPerm

A class holding the result for sensor x frequency or sensor x time max-stat permutation test computed

SensorClusterPerm

A class holding the result for sensor x frequency or sensor x time cluster stats computed

Functions#

plot_joint_clusters(xvect, erp, clusters, info[, ax, ...])

Plot a GLM-Epochs contrast from cluster objects, with spatial line colouring and topograpies.

plot_sensor_erp(xvect, erp, info[, ax, sensor_proj, ...])

Plot a GLM-Spectrum contrast with spatial line colouring.

plot_sensor_proj(info[, ax, cmap])

plot_sensor_data(xvect, data, info[, ax, lw, xticks, ...])

Plot sensor data with spatial line colouring.

get_mne_sensor_cols(info)

Get sensor colours from MNE info object.

decorate_spectrum(ax[, ylabel])

Decorate a spectrum plot.

get_source_colors(parcellation_file[, cmap])

plot_channel_layout(ax, info[, size, marker])

Plot sensor layout.

plot_with_cols(ax, data, xvect[, cols, lw])

Plot data with spatial line colouring.

plot_source_topo(data_map[, parcellation_file, ...])

Plot a data map on a cortical surface. Wrapper for nilearn.plotting.plot_glass_brain.

Module Contents#

class osl_ephys.glm.glm_base.GLMBaseResult(model, design, info, data=None)[source]#

A class for GLM-Epochs fitted to MNE-Python Raw objects.

model[source]#
design[source]#
data = None[source]#
info[source]#
compute_cohens_f2(reg_ind)[source]#

Compute a Cohens F-squared effect size associated with a specific regressor.

Parameters:

reg_ind (int) – regressor of interest

Returns:

Cohen’s F-squared values

Return type:

array

save_pkl(outname, overwrite=True, save_data=False)[source]#

Save GLM-Epochs result to a pickle file.

Parameters:
  • outname (str) – Filename or full file path to write pickle to

  • overwrite (bool) – Overwrite previous file if one exists? (Default value = True)

  • save_data (bool) – Save epoch data in pickle? This is omitted by default to save disk space (Default value = False)

class osl_ephys.glm.glm_base.GroupGLMBaseResult(model, design, info, config, fl_contrast_names=None, data=None)[source]#

A class for group level GLM-Epochs fitted across mmultiple first-level GLM-Epochs computed from MNE-Python Raw objects

model[source]#
design[source]#
data = None[source]#
config[source]#
info[source]#
contrast_names[source]#
get_channel_adjacency(dist=40)[source]#

Return adjacency matrix of channels.

Parameters:

dist (float) – Distance in mm between parcel centroids to consider neighbours. Only used if data is parcellated.

Returns:

  • adjacency (scipy.sparse.csr_matrix) – The adjacency matrix.

  • ch_names (list of str) – The channel names.

class osl_ephys.glm.glm_base.BaseSensorPerm[source]#

A base class for sensor x frequency and sensor x time permutation tests computed from a group level GLM-Spectrum.

save_pkl(outname, overwrite=True, save_data=False)[source]#

Save GLM-Epochs result to a pickle file.

Parameters:
  • outname (str) – Filename or full file path to write pickle to

  • overwrite (bool) – Overwrite previous file if one exists? (Default value = True)

  • save_data (bool) – Save epoch data in pickle? This is omitted by default to save disk space (Default value = False)

class osl_ephys.glm.glm_base.SensorMaxStatPerm(glmsp, gl_con, fl_con=0, nperms=1000, tstat_args=None, metric='tstats', nprocesses=1, pooled_dims=(1, 2), tmin=None, tmax=None, fmin=None, fmax=None, picks=None)[source]#

Bases: BaseSensorPerm

A class holding the result for sensor x frequency or sensor x time max-stat permutation test computed from a group level GLM-Spectrum or GLM-Epochs

adjacency[source]#
perm_data[source]#
gl_con[source]#
fl_con = 0[source]#
gl_contrast_name[source]#
fl_contrast_name[source]#
info[source]#
perms[source]#
get_sig_clusters(thresh)[source]#

Return the significant clusters at a given threshold.

Parameters:

thresh (float) – The threshold to consider a cluster significant eg 95 or 99

Returns:

  • clusters – A list containing the significant clusters. Each list item contains a tuple of three items - the cluster statistic, the cluster percentile relative to the null and the spatial/spectral indices of the cluster.

  • obs_stat – The observed statistic.

plot_sig_clusters(thresh, ax=None, min_extent=1)[source]#

Plot the significant clusters at a given threshold.

Parameters:
  • thresh (float) – The threshold to consider a cluster significant eg 95 or 99

  • ax (matplotlib.axes) – Matplotlib axes to plot on. (Default value = None)

class osl_ephys.glm.glm_base.SensorClusterPerm(glmsp, gl_con, fl_con=0, nperms=1000, cluster_forming_threshold=3, tstat_args=None, metric='tstats', tmin=None, tmax=None, fmin=None, fmax=None, picks=None, nprocesses=1)[source]#

Bases: BaseSensorPerm

A class holding the result for sensor x frequency or sensor x time cluster stats computed from a group level GLM-Spectrum or GLM-Epochs

perm_data[source]#
gl_contrast_name[source]#
fl_contrast_name[source]#
info[source]#
perms[source]#
get_sig_clusters(thresh)[source]#

Return the significant clusters at a given threshold.

Parameters:

thresh (float) – The threshold to consider a cluster significant eg 95 or 99

Returns:

  • clusters – A list containing the significant clusters. Each list item contains a tuple of three items - the cluster statistic, the cluster percentile relative to the null and the spatial/spectral indices of the cluster.

  • obs_stat – The observed statistic.

plot_sig_clusters(thresh, ax=None, min_extent=1)[source]#

Plot the significant clusters at a given threshold.

Parameters:
  • thresh (float) – The threshold to consider a cluster significant eg 95 or 99

  • ax (matplotlib.axes) – Matplotlib axes to plot on. (Default value = None)

osl_ephys.glm.glm_base.plot_joint_clusters(xvect, erp, clusters, info, ax=None, times='auto', topo_scale='joint', lw=0.5, ylabel='Power', title='', ylim=None, xtick_skip=1, topo_prop=1 / 5, topo_cmap=None, topomap_args=None)[source]#

Plot a GLM-Epochs contrast from cluster objects, with spatial line colouring and topograpies.

Parameters:
  • xvect (array_like) – Time vector

  • erp (array_like) – epochs values

  • clusters (list) – List of cluster objects

  • info (dict) – MNE-Python info object

  • ax ({None or axis handle}) – Axis to plot into (Default value = None)

  • times ({list, tuple or 'auto'}) – Which times to plot topos for (Default value = ‘auto’)

  • topo_scale ({'joint' or None}) – Whether to fix topomap colour scales across all topos (‘joint’) or leave them individual (Default value = ‘joint’)

  • lw (float) – Line width(Default value = 0.5)

  • ylabel (str) – Y-axis label(Default value = ‘Power’)

  • title (str) – Plot title(Default value = None)

  • ylim ({tuple or list}) – min and max values for y-axis (Default value = None)

  • xtick_skip (int) – Number of xaxis ticks to skip, useful for tight plots (Default value = 1)

  • topo_prop (float) – Proportion of plot dedicted to topomaps(Default value = 1/3)

  • topo_cmap ({None or matplotlib colormap}) – Colormap to use for plotting (Default is ‘RdBu_r’ if pooled topo data range is positive and negative, otherwise ‘Reds’ or ‘Blues’ depending on sign of pooled data range)

osl_ephys.glm.glm_base.plot_sensor_erp(xvect, erp, info, ax=None, sensor_proj=False, xticks=None, xticklabels=None, lw=0.5, title=None, sensor_cols=True, ylabel=None, xtick_skip=1)[source]#

Plot a GLM-Spectrum contrast with spatial line colouring.

Parameters:
  • xvect (array_like) – Vector of time values for x-axis

  • psd (array_like) – Array of spectrum values to plot

  • info (MNE Raw info) – Sensor info for spatial map

  • ax ({None or axis handle}) – Axis to plot into (Default value = None)

  • sensor_proj (bool) – Whether to plot a topomap inset (Default value = False)

  • xticks (array_like) – xtick positions (Default value = None)

  • xticklabels (array_like of str) – xtick labels (Default value = None)

  • lw (flot) – Line width(Default value = 0.5)

  • title (str) – Plot title(Default value = None)

  • sensor_cols (bool) – Whether to colour lines by sensor (Default value = True)

  • ylabel (str) – Y-axis label(Default value = None)

  • xtick_skip (int) – Number of xaxis ticks to skip, useful for tight plots (Default value = 1)

osl_ephys.glm.glm_base.plot_sensor_proj(info, ax=None, cmap=None)[source]#
osl_ephys.glm.glm_base.plot_sensor_data(xvect, data, info, ax=None, lw=0.5, xticks=None, xticklabels=None, sensor_cols=True, xtick_skip=1)[source]#

Plot sensor data with spatial line colouring.

osl_ephys.glm.glm_base.get_mne_sensor_cols(info)[source]#

Get sensor colours from MNE info object.

Parameters:

info (mne.Info) – MNE-Python info object

Returns:

  • colors (array_like) – Array of RGB values for each sensor

  • pos (array_like) – Sensor positions

  • outlines (array_like) – Sensor outlines

osl_ephys.glm.glm_base.decorate_spectrum(ax, ylabel='Amplitude')[source]#

Decorate a spectrum plot.

Parameters:
  • ax (matplotlib.axes) – Axis to plot into

  • ylabel (str) – Y-axis label(Default value = ‘Power’)

osl_ephys.glm.glm_base.get_source_colors(parcellation_file, cmap='viridis')[source]#
osl_ephys.glm.glm_base.plot_channel_layout(ax, info, size=30, marker='o')[source]#

Plot sensor layout.

Parameters:
  • ax (matplotlib.axes) – Axis to plot into

  • info (mne.Info) – MNE-Python info object

  • size (int) – Size of sensor § (Default value = 30)

  • marker (str) – Marker type (Default value = ‘o’)

osl_ephys.glm.glm_base.plot_with_cols(ax, data, xvect, cols=None, lw=0.5)[source]#

Plot data with spatial line colouring.

Parameters:
  • ax (matplotlib.axes) – Axis to plot into

  • data (array_like) – Data to plot

  • xvect (array_like) – Vector of time values for x-axis

  • cols (array_like) – Array of RGB values for each sensor (Default value = None)

  • lw (flot) – Line width(Default value = 0.5)

osl_ephys.glm.glm_base.plot_source_topo(data_map, parcellation_file=None, mask_file='MNI152_T1_8mm_brain.nii.gz', axis=None, cmap=None, vmin=None, vmax=None, alpha=0.7)[source]#

Plot a data map on a cortical surface. Wrapper for nilearn.plotting.plot_glass_brain.

Parameters:
  • data_map (array_like) – Vector of data values to plot (nparc,)

  • parcellation_file (str) – Filepath of parcellation file to plot data on

  • mask_file (str) – Filepath of mask file to plot data on (Default value = ‘MNI152_T1_8mm_brain.nii.gz’)

  • axis ({None or axis handle}) – Axis to plot into (Default value = None)

  • cmap ({None or matplotlib colormap}) – Colormap to use for plotting (Default value = None)

  • vmin ({None or float}) – Minimum value for colormap (Default value = None)

  • vmax ({None or float}) – Maximum value for colormap (Default value = None)

  • alpha ({None or float}) – Alpha value for colormap (Default value = None)

Returns:

image – AxesImage object

Return type:

matplotlib.image.AxesImage