Pipeline Functions¶
Classes and Functions for running the Lossless Pipeline.
- pylossless.pipeline.chan_neighbour_r(epochs, nneigbr, method)¶
Compute nearest Neighbor R.
- Parameters:
- epochs
mne.Epochs - nneigbr
int Number of neighbours to compare in open interval
- method
str One of ‘max’, ‘mean’, or ‘trimmean’. This is the function which aggregates the neighbours into one value.
- epochs
- Returns:
- Xarray
Xarray.DataArray An instance of Xarray.DataArray
- Xarray
- pylossless.pipeline.coregister(raw_edf, fiducials='estimated', show_coreg=False, verbose=False)¶
Coregister Raw object to ‘fsaverage’.
- Parameters:
- raw_edf
mne.io.Raw an instance of mne.io.Raw to coregister.
- fiducials
str(default ‘estimated’) fiducials to use for coregistration. if ‘estimated’, gets fiducials from fsaverage.
- show_coreg
bool(defaultFalse) If True, shows the coregistration result in a plot.
- verbose
bool|str(defaultFalse) sets the logging level for mne.Coregistration.
- raw_edf
- Returns:
coregistration|numpy.arraya numpy array containing the coregistration trans values.
- pylossless.pipeline.epochs_to_xr(epochs, kind='ch', ica=None)¶
Create an Xarray DataArray from an instance of mne.Epochs.
- Parameters:
- epochs
mne.Epochs an instance of mne.Epochs
- kind
str The name to be passed into the coords argument of xr.DataArray corresponding to the channel dimension of the epochs object. Must be
'ch'or'ic'.- ica
mne.preprocessing.ICA If not
None, should be an instance of mne.preprocessing.ICA from which to pull the names of the ICA components.
- epochs
- Returns:
xarray.DataArrayan instance of xarray.DataArray, with dimensions
'epochs','time'(samples), and either'ch'(channels) or'ic'(independent components).
- pylossless.pipeline.find_bads_by_threshold(epochs, threshold=5e-05)¶
Return channels with a standard deviation consistently above a fixed threshold.
- Parameters:
- epochs
mne.Epochs an instance of mne.Epochs with a single channel type.
- threshold
float the threshold in volts. If the standard deviation of a channel’s voltage variance at a specific epoch is above the threshold, then that channel x epoch will be flagged as an “outlier”. If more than 20% of epochs are flagged as outliers for a specific channel, then that channel will be flagged as bad. Default threshold is 5e-5 (0.00005), i.e. 50 microvolts.
- epochs
- Returns:
lista list of channel names that are considered outliers.
Notes
If you are having trouble converting between exponential notation and decimal notation, you can use the following code to convert between the two:
>>> import numpy as np >>> threshold = 5e-5 >>> with np.printoptions(suppress=True): ... print(threshold) 0.00005
See also
flag_channels_fixed_threshold()to use this function within the lossless pipeline.Examples
>>> import mne >>> import pylossless as ll >>> fname = mne.datasets.sample.data_path() / "MEG/sample/sample_audvis_raw.fif" >>> raw = mne.io.read_raw(fname, preload=True).pick("eeg") >>> raw.apply_function(lambda x: x * 3, picks=["EEG 001"]) # Make a noisy channel >>> epochs = mne.make_fixed_length_epochs(raw, preload=True) >>> bad_chs = ll.pipeline.find_bads_by_threshold(epochs)
- pylossless.pipeline.get_operate_dim(array, flag_dim)¶
Get the xarray.DataArray dimension to flag for a pipeline method.
- Parameters:
- array
xarray.DataArray An instance of Xarray.DataArray that was constructed from an
mne.Epochsobject, usingpylossless.pipeline.epochs_to_xr. Thearraymust be 2D.- flag_dim
str Name of the dimension to remove in
xarray.DataArray.dims. Must be one of'epoch','ch', or'ic'.
- array
- Returns:
- list
list a list of the dimensions of the xarray.DataArray, excluding the dimension that the pipeline will conduct flagging operations on.
- list
- pylossless.pipeline.warp_locs(self, raw)¶
Warp locs.
- Parameters:
- raw
mne.io.Raw an instance of mne.io.Raw
- raw
- Returns:
None(operatesinplace)