How to "average" multiple "source files"?

Dear Francois:

Thank you for your tips last time. I have successfully got the source estimation from the EEG recording and I can view it on the standard MNI template for each participant.

Now I have a question about how to “average” these source estimations. That is, how can I put all these source estimation together into one file as a group?

I seemed to be able to export each resulted “source file” into either .mat or .nii formats, though the .mat file seemed to be pretty large.

Thank you very much.

                                                                                        Ying

Hi Ying,

If you estimated the sources of all your subjects on the MNI brain, you can directly average the source matrices.
You can do the same as what you do for averaging recordings:

  1. drag and drop all the source files to the process list (at the bottom of the brainstorm window)
  2. select the “Process sources” button (second button from the top, on the left of the list of files to process)
  3. Click on run. Then select the process Average > Average files > Everything

Then you don’t need to “export” the source files, as they are already in Matlab format. Right-click > File > Show in file explorer, or Export to Matlab.
Don’t use the export to a 4D matrix (nii), this re-interpolates the sources from the surface to the MRI volume, this is probably not what you are trying to do.

Francois

Hi Francois:

Thank you for the tips. I tried to do as you said, there is always this error message popping out, saying “[process_average] Average> Average files, Line 102: Out of memory. Please unload some datasets (or restart Matlab) and try again”

I restarted my computer and the Java runtime, and it doesn’t really work.

I also deleted all the other protocols, and cleaned out enough space from the C drive, it doesn’t work either, even when the files to be averaged were reduced to two.

Do you have any suggestions? Should I export some files from under the same protocol and redo it?

Thank you very much.

                                                                                                                                       Ying

Hi Ying,

When you average source files, it has to convert them back from the compact mode (saving separately the inversion kernel and the recordings) to the full representation (a big matrix [nSources x nTime]). The difference between those two representations is explained in the tutorials:
neuroimage.usc.edu/brainstorm/Tutorials/TutSourceEstimation

This re-conversion may require too much memory. To estimate in Mb the amount of memory you need to save and process a full source file:
nSources * nTime * 8 * 4 / 1024 /1024
In the case of the introduction tutorials, it is:
15016 * 375 * 8 * 4 / 1024 / 1024 = 172 Mb

But if you have more time samples, you can quickly reach sizes that your computer cannot handle.
You have to work either on a computer with more memory, or work on smaller time windows (split the recordings into blocks of 1000 time points).

Cheers,
Francois

Hi Francois:

I tried to convert. Maybe it’s wrong, but I believe it’s under the “Compute sources”–"Full results (Kernel*recordings). It also pops out the same problem.

My C drive still has at least 6GB space. I can think of two solutions. One is that I switch to a computer that has a real matlab instead of a Java compiler, maybe that will help.

Another solution is that I export some files under the same protocol out and try again.

In both cases, I need to export portion of the database without destroying the data structure. Do you have any recommendations?

Thank you very much.

                                                                                                                                                                        Ying

Yes, when you compute the sources, if you select the option “Full results”, it stores the files in this expanded mode, with the full sources matrices in the field “ImageGridAmp”.

If you cannot compute those “full sources” on your computer, the only thing you should do is to reduce the size of your recordings, ie. working with shorter epochs. When you display recordings, you can see the number of time samples that are saved in the file in the top-right corner of the brainstorm window. You need to re-import your data, splitting it in shorter time segments.

Switching from a stand-alone version to a Matlab-based version of Brainstorm is not going to change anything, they work exactly the same way.

Francois

Hi Francois:

I reloaded the EEG recordings and split it. When I cut it into 400ms block and average two source files, the error message was still" out of the memory".

Then I tried to cut it into 200ms block and average two source files. It’s still very very slow and also crashing the computer.

I have to abort it and the final error message was something like “attempt to reference field of non-structure array”. I believe that means it was actually running, just very slow, right?

Should I unload files from the database and try again or use other strategies?

Thank you.

                                                                                                         Ying

Hi Ying,

It is crashing during what operation?
How old is your computer? What is your processor? How many cores? How much RAM?
Have you tried on another computer?

Can you export one subject from your protocol and send it to me, so I can check that you did everything properly?

  • Right-click on your subject > File > Export subject
  • Send the me the zip file via FTP or Dropbox, and send me the link in a private email
  • If it is way to big: start again but import just a few seconds of recordings…
  • Describe exactly the operations you are performing in order to reproduce the crash

Thanks
Francois

Hi Francois:

I don’t know how old the computer is, it’s a department computer.

The processor is Intel® Core ™2 Duo CPU E7500 @ 2.93GHz
RAM:4.00GB

No, I haven’t tried it on another computer. I will and if it doesn’t work I will send you the files.

Could this forum support attachments? If not, could you please give me an email address?

Thank you so so much.
Ying

Well, it should definitely work on that computer.
There is probably something wrong with the way you imported your recordings.
Please, export a subject and send it to me.
To send me the link where you upload it: On this page, click on “Francois”, on top of any of my posts > send email.

Cheers,
Francois

Hi Francois:

I sent a dropbox link in your email. Please let me know if you have trouble accessing it.

Thank you very much.

                                                                                Ying

Hi Ying,

I’ve just checked the data you sent me.
First thing: Any particular reason for which you chose to work in the volume rather than on the surface? We strongly encourage the Brainstorm users to switch to surface analysis (headmodel source space = cortex), because results are much easier to review graphically, we don’t lose a lot of information, it gives smaller files, and all the advanced tools in Brainstorm only work for surface-based reconstructions (including the ROI-based analysis). It is usually less intuitive for people who already have experience with other neuroimaging modalities (typically fMRI or PET), but it is usually worth it.

Second remark: Working with EEG, you should definitely use the OpenMEEG head model instead of the 3-shell sphere.
http://neuroimage.usc.edu/brainstorm/Tutorials/TutBem

Now, about your out of memory errors:
Indeed, your files are unnecessarily huge. Not the ones that you compute directly, because they are saved in this compact mode (ImagingKernel * Recordings) => ~50Mb. Reviewing directly those files is easy and fast.
But when there are re-processed (averaging, filtering, copy…), they are converted to a full source matrix, with unconstrained orientations (3 values for each point) => 3 x 15182 points x 4000 samples ~ 1.40Gb
Averaging files like this requires 3x the amount in space in memory => 4.2Gb
So it is totally normal that you get those errors.

There are some conceptual problems in your recordings that you need to think about before going any further.
=> Do you really need to keep your recordings sampled at 20000Hz?
If the example you sent me, the recordings are low-pass filtered at <100Hz, therefore you lose all the information that such a high sampling rate provides.

What you should do:

  • resample at 500Hz (process Pre-processing > Resample), you will have the full dynamics of your signal, but it will divide by 40 the size of everything
  • use cortically constrained models

Best,
Francois

Hi Francois:

Thank you so much for this detailed explanation. The later part totally made sense to me and I will try as you said.

My only question is what is “surface analysis”? Is it the same thing as using “OpenMEEG head model” instead of “three-layer model”

Thank you.

  • “Surface analysis”: Option “source-space cortex” in the headmodel option window, instead of “MRI Volume [experimental]” <=> List of points on which you want to estimate the sources
  • “OpenMEEG BEM” or “3-layer sphere” are two different methods to calculate a forward model for those points

See: http://neuroimage.usc.edu/brainstorm/Tutorials/TutHeadModel