Pipeline Functions

Classes and Functions for running the Lossless Pipeline.

pylossless.pipeline.chan_neighbour_r(epochs, nneigbr, method)

Compute nearest Neighbor R.

Parameters:
epochsmne.Epochs
nneigbrint

Number of neighbours to compare in open interval

methodstr

One of ‘max’, ‘mean’, or ‘trimmean’. This is the function which aggregates the neighbours into one value.

Returns:
XarrayXarray.DataArray

An instance of Xarray.DataArray

pylossless.pipeline.coregister(raw_edf, fiducials='estimated', show_coreg=False, verbose=False)

Coregister Raw object to ‘fsaverage’.

Parameters:
raw_edfmne.io.Raw

an instance of mne.io.Raw to coregister.

fiducialsstr (default ‘estimated’)

fiducials to use for coregistration. if ‘estimated’, gets fiducials from fsaverage.

show_coregbool (default False)

If True, shows the coregistration result in a plot.

verbosebool | str (default False)

sets the logging level for mne.Coregistration.

Returns:
coregistration | numpy.array

a 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:
epochsmne.Epochs

an instance of mne.Epochs

kindstr

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'.

icamne.preprocessing.ICA

If not None, should be an instance of mne.preprocessing.ICA from which to pull the names of the ICA components.

Returns:
xarray.DataArray

an 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:
epochsmne.Epochs

an instance of mne.Epochs with a single channel type.

thresholdfloat

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.

Returns:
list

a 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:
arrayxarray.DataArray

An instance of Xarray.DataArray that was constructed from an mne.Epochs object, using pylossless.pipeline.epochs_to_xr. The array must be 2D.

flag_dimstr

Name of the dimension to remove in xarray.DataArray.dims. Must be one of 'epoch', 'ch', or 'ic'.

Returns:
listlist

a list of the dimensions of the xarray.DataArray, excluding the dimension that the pipeline will conduct flagging operations on.

pylossless.pipeline.warp_locs(self, raw)

Warp locs.

Parameters:
rawmne.io.Raw

an instance of mne.io.Raw

Returns:
None (operates in place)