Combining multiple files

Hi Colleagues,

I have 20 *.fif files. However, I have a difficulty how to combine all the data ? so that I can analyze them together instead of getting the result for each of 20 files. I know this function mne.concatenate_raws but it does not fit into my objective.

Thanks for your help

Best,
Ihshan

  • MNE-Python version: 0.23
  • operating system: Ubuntu 20

Please tell us more about your objective, otherwise we can only blindly guess at what might help.

Sorry for not being clear.

I would like to run time frequency (TF) analysis and synchronization. However, at the moment, I can only create TF from one participant since I can only read_raw_fif for one fif file. Since I would like to create TF out of 20 .fif files, I think I need to combine all 20 files together first then I can run TF or synchronization analysis easily. That would be great if you could let me know how to combine these 20 files together.

Thanks for your help.

Ok, but it’s not clear why will mne.concatenate_raws() not work for that use case.

It seems that mne.concatenate_raws() increase the time points “horizontally”.
Say, file A has 200 points (eg. 1 x 200) and file B has 200 points (eg. 1 x 200), If I combine them using mne.concatenate_raws(), it would be 400 points (1 x 400) instead of creating matrix which is (2 x 200), I hope that is clear enough. Let me explore once again then if you think that mne.concatenate_raws() fit

I found the same issue here Combine epoched ave fif files?
However, it seems that such function does not exist anymore in the current version. The function is mne_process_raw . Is that function still available in the current MNE version ?

Thanks

mne_process_raw is part of the MNE-C command-line tools, not MNE-Python.

You still haven’t told us yet what your .fif files contain. If you are combining continuous data (raw) files then mne.concatenate_raws() is probably the only choice. If your .fif files contain epoched data, then there is mne.concatenate_epochs(). Neither of those will combine data along the axis you mentioned, however, because what you describe (two 1x200 files combining into one 2x200 file) is analogous to adding new channels to the (raw or evoked) object.

1 Like

Thank you so much for your help and clarification.
I have some data which already has epochs and some don’t. I may want to use those two functions then.

I found that combining data along the axis that I mentioned above can be done by using raw.append , the example for using raw.append can be found here

Cheers

ok, good luck! I think mne.concatenate_raws([raw0, raw1, raw2, ...]) is the same as raw0.append([raw1, raw2, ...]) but raw.append has the advantage that you can load and append the raws one at a time in a for-loop.

Hi @ihgumilar,
if each of these files is a separate participant you should:

  • read each of these files in a loop and get separate TFR for each file (in the loop)
  • aggregate these TFRs (via .append() into a list for example; in the loop)
  • then outside of the loop use mne.grand_average to obtain average TFR
1 Like

Hi @mmagnuski

Thanks for your advice. I have just thought that I combine all the data of participants together then run the TFR once. Would it give a different result in compared to your suggestion ?

Thanks

Yes - if your data files do not contain the same number of epochs, you will get an equivalent of a weighted average of subject-level TFRs. BTW - if your data are raw (channels x time) then when you combine subjects along the time dimension and then compute the TFR, you will get subsequent subjects in time in the TFR, which is likely not what you want.

Hi @mmagnuski

I am wondering how can I plot the grande average of TFR result ?

Thanks

Let’s say you loop through your subjects and aggregate the TFRs of single subjects in a list all_tfrs. Then to get the average TFR you would need to do: avg_tfr = mne.grand_average(all_tfrs). Then you can use the plotting functionality of the avg_tfr which will be a TFR object (with .plot() method for example).

Make sure to baseline-correct the single-subject TFRs before you average them (important for example when you perform 'percent' baseline correction mode).

1 Like