osl_dynamics.meeg.parcellation#
Parcellation.
Classes#
Class for reading parcellation files. |
Functions#
|
Plot a parcellation. |
|
Takes a vector of parcel values and return a 3D voxel grid. |
|
Parcellate data. |
|
Save parcellated data as a fif file. |
|
Plot PSD of each parcel time course. |
|
Save parcellation QC plots. |
|
Convert an array to an MNE Raw object, copying metadata from a reference. |
Module Contents#
- class osl_dynamics.meeg.parcellation.Parcellation(file)[source]#
Class for reading parcellation files.
- Parameters:
file (str) – Path to parcellation file.
- osl_dynamics.meeg.parcellation.plot_parcellation(parcellation, **kwargs)[source]#
Plot a parcellation.
- Parameters:
parcellation (str or Parcellation) – Parcellation to plot.
kwargs (keyword arguments, optional) – Keyword arguments to pass to nilearn.plotting.plot_markers.
- Return type:
object
- osl_dynamics.meeg.parcellation.parcel_vector_to_voxel_grid(mask_file, parcellation_file, vector, remove_subcortical_voxels=False)[source]#
Takes a vector of parcel values and return a 3D voxel grid.
- Parameters:
mask_file (str) – Mask file for the voxel grid. Must be a NIFTI file.
parcellation_file (str) – Parcellation file. Must be a NIFTI file.
vector (np.ndarray) – Value at each parcel. Shape must be (n_parcels,).
remove_subcortical_voxels (bool, optional) – Should we set the subcortical voxels to np.nan?
- Returns:
voxel_grid – Value at each voxel. Shape is (x, y, z), where
x,yandzcorrespond to 3D voxel locations.- Return type:
np.ndarray
- osl_dynamics.meeg.parcellation.parcellate(fns, voxel_data, voxel_coords, method, parcellation_file, orthogonalisation=None)[source]#
Parcellate data.
- Parameters:
fns (OSLFilenames) – Container for OSL filenames.
voxel_data (np.ndarray) – (nvoxels x n_time) or (nvoxels x n_time x n_trials) and is assumed to be on the same grid as parcellation.
voxel_coords (numpy.ndarray) – (nvoxels x 3) coordinates in mm in same space as parcellation.
method (str, optional) –
‘pca’ - take 1st PC of voxels. ‘spatial_basis’ - The parcel time-course for each spatial map is the
1st PC from all voxels, weighted by the spatial map. If the parcellation is unweighted and non-overlapping, ‘spatial_basis’ will give the same result as ‘pca’ except with a different normalisation.
- ’centroid’ - Use the time course of the voxel nearest to each
parcel centroid.
parcellation_file (str) – Path to parcellation file. In same space as voxel_coords.
orthogonalisation (str, optional) – Method for orthogonalising the data. Can be None or ‘symmetric’.
- Returns:
parcel_data – Parcellated data. Shape is (parcels, time) or (parcels, time, epochs).
- Return type:
np.ndarray
- osl_dynamics.meeg.parcellation.save_as_fif(parcel_data, raw, filename, extra_chans=None)[source]#
Save parcellated data as a fif file.
- Parameters:
parcel_data (np.ndarray) – (parcels, time) or (parcels, time, epochs) data.
raw (mne.Raw or mne.Epochs) – MNE Raw or Epochs objects to get info from.
filename (str) – Output file path.
extra_chans (str or list of str) – Extra channels, e.g. ‘stim’ or ‘emg’, to include in the parc_raw object. Defaults to ‘stim’. stim channels are always added to parc_raw if they are present in raw.
- Return type:
None
- osl_dynamics.meeg.parcellation.plot_psds(parc_fif, parcellation_file, fmin=0.5, fmax=45, filename=None)[source]#
Plot PSD of each parcel time course.
- Parameters:
parc_fif (mne.Raw or mne.Epochs) – MNE Raw or Epochs object containing the parcel data.
parcellation_file (str) – Path to parcellation file.
fmin (float, optional) – Minimum frequency.
fmax (float, optional) – Maximum frequency.
filename (str, optional) – Output filename.
- Return type:
None
- osl_dynamics.meeg.parcellation.save_qc_plots(parc_fif, parcellation_file, output_dir=None, power_maps=False, show=False, cmap='hot')[source]#
Save parcellation QC plots.
Saves the following files to output_dir: - psd_topo.png: PSD topography plot - power_maps.png: composite band power maps (only if power_maps=True)
- Parameters:
parc_fif (str) – Path to parcellated fif file.
parcellation_file (str) – Parcellation file name.
output_dir (str or Path, optional) – Directory to save plots to. Defaults to the directory containing parc_fif.
power_maps (bool, optional) – Whether to create band power map plots. Default is False.
show (bool, optional) – Whether to display the plots interactively. Default is False.
cmap (str, optional) – Colormap for power maps.
- Return type:
None
- osl_dynamics.meeg.parcellation.convert_to_mne_raw(data, raw, ch_names=None, extra_chans=None)[source]#
Convert an array to an MNE Raw object, copying metadata from a reference.
If
datahas fewer time points thanraw, bad segments are re-inserted as zeros so that the output has the same length asraw.- Parameters:
data (np.ndarray) – (n_channels, n_samples) data array.
raw (mne.io.Raw) – Reference Raw object. Timing, annotations, filter settings, description and extra channels are copied from this object.
ch_names (list of str, optional) – Channel names. Defaults to
channel_0, ..., channel_{n-1}.extra_chans (str or list of str, optional) – Extra channel types (e.g.
"stim","emg") to copy fromraw. Defaults toNone(no extra channels).
- Returns:
new_raw – New Raw object containing
datawith metadata fromraw.- Return type:
mne.io.Raw