ERPs
Opened this issue · 9 comments
Is there a way to perform the segmentation on ERPs?
@vferat Any reason why we excluded Evoked?
I guess you could bypass this by using a ChData
object: https://pycrostates.readthedocs.io/en/latest/api/generated/pycrostates.io.ChData.html#pycrostates.io.ChData
evoked = Evoked(...)
ch_data = ChData(evoked.get_data(), evoked.info)
Hey,
The way microstate analysis is performed on ERPs is quite different from spontaneous activity: one major difference is that polarity is not ignored for ERPs (more details here: A Tutorial on Data-Driven Methods for Statistically Assessing ERP Topographies).
This is not yet supported by Pycrostates. There is an ongoing PR (#93) that should deal with it; however, more work is needed, especially to adapt the smoothing algorithm (here). Any contribution is welcomed! 😊
As for now, I can only recommend using Cartool or Ragu for the topographic analysis of ERPs.
Thanks @vferat. That is good to know.
As for the smoothing parameters, I am actually working on a simulation that applies MS-like topographies and then injects 1/f noise. My hope is to see how different combinations of smoothing parameters affect the segmentation, compared to the known a priori segmentation used to create the simulation. The assumption is that each participant will be optimized by different smoothing parameter combinations, so this is just a tool to be used in tandem with actual participant data to help identify best smoothing parameters per subject. I do not have this code up on Git yet as I am still working out some of the bugs, but it is mostly done. I am happy to share it if you think it would be helpful.
Hi @vferat, just wondering if there has been any breakthroughs on getting the ERP side of pycrostates up an running? I have been having a really difficult time trying to figure out how to get my fif files converted into something Cartool or Ragu can read.
Hey Matt,
Unfortunately, I don't know when we'll have time to work on this.
However, if your aim is to use MNE data in Cartool, I can advise you to have a look at Pycartool which provides I/O function to read and export MNE objects to Cartool file formats.
I don't think there is a specific Cartool file format for Evoked
or Epoched
data.
A workaround would be to transform your evoked
data into raw
(see example with MNE sample dataset)
import mne
import pycartool
# Load the MNE-Python sample dataset
sample_data_path = mne.datasets.sample.data_path()
# Load the auditory evoked data (for example)
evoked = mne.read_evokeds(sample_data_path + '/MEG/sample/sample_audvis-ave.fif', condition=0)
data = evoked.data
info = evoked.info
raw = mne.io.RawArray(data, info)
pycartool.io.write_sef("test.sef", raw)
I'm not really sure how to handle epochs
in Cartool, you may need to export the raw
file ( your can also use mne.export.export_raw for that) along with the triggers. Or export each epoch to a sef
file individually:
# Load the Epochs data for the visual condition (for example)
raw = mne.io.read_raw_fif(sample_data_path + '/MEG/sample/sample_audvis_raw.fif', preload=True)
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, tmin=-0.2, tmax=0.5, picks='meg', event_id=1)
data = epochs.get_data()
for i,d in enumerate(data):
raw = mne.io.RawArray(d, epochs.info)
pycartool.io.write_sef(f"epoch_{i}.sef", raw)
Hope it can help. Let us know here if it worked for you, so other people can benefit from your experience
Hi @vferat, I gave this option a shot, and it does allow me to pull the data into Cartool, but it will not allow you to pull it into the segmentation due to some automatically calculated extra channels, such as GFP. However, this can be mitigated by opening up each file and manually deleting these channels and saving the modified .sef files separately. These separate files can then be pulled into the segmentation window.
That said, there are some issue I am still trying to figure out. The segmentation output seems to lack a lot of information the tutorials have, such as the colored segmented GFP data and there are no head models for the microstate classes (though this latter issue happens because the .fif to .sef file transition loses this info and there is no great way to extract this info from MNE). All this has kept me from moving onto the next fitting step. I will say, as a note of caution, a lot of these problems are my ignorance of Cartool most likely. I am finding it incredibly overcomplicated and there are not a lot of good tutorials or an active forum specifically for the microstates side of the program. If someone knows Cartool better I will happily take your help.
In the mean time I have found I could get a lot further with the toolboxes:< https://github.com/atpoulsen/Microstate-EEGlab-toolbox > and < https://github.com/plus-microstate/toolbox >. There does not seem to be a lot of support here either, but changing .fif files to .set files is readily done in MNE and then they have relatively straight forward pipelines.