How to merge files

  • MNE version: 0.24.0
  • operating system: Windows 10

In my studies, I record bipolar ECoG from 3 animals simultaneously. Can I combine several files belonging to the same experimental group under one file? For example, there are 12 animals in a group and I can record from 3 animals at once. Therefore, at the end of the experiment, there are 4 different files. I want to merge these files.

Hello, I don’t think there’s any file format that MNE supports that allows to do that.

For interoperability, you should consider storing the data in BIDS via MNE-BIDS.

I think EDFbrowser can combine multiple EDFs into one file: EDFbrowser manual

1 Like

Thank you very much. I will try

Yes but that’s really just some sort of concatenation / merging and loses information about individual participants … from the doc:

  • in case of multple files, the new file will get the subject, recording, date and time
    of the file that has the reference at the moment of printing.
    You can select the reference in the Time-menu
1 Like

True. I thought this was what the OP wanted, but you are right it’s just concatenating the files.

My understanding was they’d like to have some sort of a meta-structure (in the most simple case, basically a list of recordings), but maybe I was mistaken.

if they’re recording 3 animals at once, presumably that means something like channels 1-10 are animal A, channels 11-20 are animal B, etc. So I think the goal is to add channels? And although this is possible it is not very easy in MNE-Python because it would require that all 4 files have exactly the same duration. So you would probably need to do something like:

  1. load the data into separate Raw objects
  2. use .get_data() method to get the NumPy arrays
  3. figure out which recording is the longest
  4. zero-pad the other 3 NumPy arrays to match the longest one
  5. combine the arrays with np.concatenate (make sure you do it on the channels axis, not the time axis)
  6. convert back to Raw object using

An unstated part of step 6 is “getting the channel names right” — they need to be unique, and presumably you want the channel names to encode both physical location and which animal they were from.

1 Like

Hi @drammock. Unfortunately, the files are not the same duration.

OK… the steps I’ve outlined above describe how to work around that (by zero-padding). This still may or may not be good enough (e.g., if you are trying to align specific events, you might need to zero-pad some at both the beginning and the end). But in principle it’s possible.