Turning Evoked into RawArray

Hi Everyone, I need to cheat a little to accomplish something. I am trying to look at microstates both on epoched data and evoked data. Unfortunately, with microstates on evoked data, polarity does matter and the only programs that can currently handle that is Cartool or Ragu (at least that I am aware of). So I need to transform my evoked data into a file type readable by one of those programs. This has been no easy feat as I cannot find a way to turn .fif files directly into .eph, .avg, or .eeg file types. If someone knows a way please let me know! For now though, it was suggested I turn the evoked data into raw, and then I can convert the raw to a .sef file type which Cartool can read. The issue is that I loose the timing since it defaults it to start at 0sec. I have tried putting my evoked tmin into the RawArray first_samp argument, but this does not change anything actually. Additionally, MNE will not let me just do something like this:
So, I am at a loss. I would like to keep the timing if possible, just to make sure the stimulus presentation is properly aligned across participants, but this might be a moot point too. I have also tried bringing my epoched data over to Cartool by first feeding it through eeglab and brainstorm to change the file type to something cartool can read but these methods have failed too.
Let me know if there is a way to pass the time commands, OR if there is simply a smarter way to accomplish this, even if it is on the epoched data that I then turn back into evoked data in cartool or ragu.

Thank you,


A continuous recording does not have a “tmin” / “tmax” equivalent to an evoked. It does not make sense for that structure.
MNE prevents you from doing raw0.tmin = ... or raw.first_samp = ... because then it would not know what to do which this information and it will not be able to write it to disk (raw.save is not a pickle dump where you dump an entire object and reload it as is; it saves specific information in specific places (tags) in the file – same for export).

Now, could you explain what is the issue you face with the code snippet given by @vferat on ERPs · Issue #116 · vferat/pycrostates · GitHub?

The “timing” information is simply knowledge of which sample corresponds to t=0, which you can get with np.where(evoked.times == 0)[0].


I’ll add that maybe you can use the AAHC cluster object from pycrostates: pycrostates.cluster.AAHCluster — pycrostates 0.5.0.dev0 documentation with a small hack:

cluster = AAHCCluster(...)
cluster._ignore_polarity = False  # hack

IIRC, this object does support ignore_polarity for fitting BUT the BaseCluster object which implements predict and the segmentation does not. Thus, you’ll need to be careful with this hack and stop after the fit operation which will give you your microstates maps. See the discussion in this PR for more information [ENH] Add support for AAHC clustering by rkobler · Pull Request #92 · vferat/pycrostates · GitHub


Thanks @mscheltienne for the help. The code @vferat gave me looks like it’s working great. My only concern was the aligning of the stimulus onset point. However, you are likely right in that if I know what time corresponds to zero then it should be the same for everyone since everyone does have the exact same number of time points now. I was simply checking to see if this would be a potential issue and if there happened to be a simple fix. I am pretty satisfied going forward with what I have as is.

I will also try out the AAHC hack you provided to see what I can do with polarity,. Thanks for letting me know about it. I am, however, particularly sticking with ModKMeans for this analysis. Are you aware if that second line of code you provided is usable for the ModK clusters as well or if that will cause some unforeseen issues?

Thank you again,

No, the ModKMeans does not support ERP analysis yet, the hack will not work with that object.