Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Merging multiple OpenEphys binary (continuous.dat) files #95

Open
saman-abbaspoor opened this issue Nov 4, 2021 · 1 comment
Open

Comments

@saman-abbaspoor
Copy link

Hi all,

In my experiment, we record multiple binary files corresponding to different behavioral states during a session. I would like to merge them for data analysis/spike sorting. Can you suggest some of the most efficient ways to do this? I also read on one of the topics that .continuous files had 1024 samples as headers. Is this also the case for OpenEphys binary (.dat) files?

Thank you in advance,
SAM

@jsiegle
Copy link
Member

jsiegle commented Nov 5, 2021

Hi Sam –

You can do this fairly easily using numpy.ndarray.tofile

The .dat files don't have a header, so you can load them efficiently using memory mapping. You will need to know the number of channels in the file to do this (check the structure.oebin file for this number).

import numpy as np
data = np.memmap(filename, dtype='int16')
data = np.reshape(data, (data.size // numChannels, numChannels)

Once you have the data loaded, you can write it to a file using:

f = open(newfilename, 'wb')
data.tofile(f)
f.close()

Now, you can add additional recordings to the same file by opening the file in "append" mode:

f = open(newfilename, 'a')
data2.tofile(f)
f.close()

Let me know if that works! Just keep in mind that this may be pretty slow if your data files are large.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants