prestonlab / ebids

Code to translate electrophysiological data to BIDS format.
GNU General Public License v3.0
1 stars 0 forks source link

Convert Neuralynx data to EDF or BrainVision #2

Open mortonne opened 5 years ago

mortonne commented 5 years ago

For each task run, use the synchronization data to pull relevant times from all channels and save to an EDF or BrainVision file. Also need a JSON sidecar for each; may need to rename the existing ieeg sync information files to avoid a conflict with that.

Also, may want to move Neuralynx files to a sourcedata subdirectory, and also move the sync-related files. Then the final directory structure will be a lot less cluttered, just having events.tsv, ieeg.edf, ieeg.json, micro.edf, and micro.json for each run.

mortonne commented 5 years ago

Start is a python function, placed in the ebids/nlx module, that takes in the path to an events_file and the path to a Neuralynx directory with recordings for that session. Use the "ieeg" field in events to look up the recording time of each event. Note that Neuralynx times are in microseconds.

Read in the Neuralynx directory using neo, then write out to EDF using neo (if it has support for writing EDF) or pyedf.

The BIDS spec says that the events files should have an onset field with the time in the corresponding recording. To match the existing onset field, we'll have to trim the recording written out to start at the same t0 that we used for the task. That also has the benefit of reducing the size of the recordings, as you're just getting the well-controlled task runs and not the uncontrolled times between them. We'll keep the Neuralynx versions, of course, in case we later want to do something like look at rest data. May need to also adjust any time information encoded in the EDF file, for example to put it in seconds instead of microseconds.

At the end you get two files for each run: a tab-delimited text file with task data, and a file with all channels that is stored in a widely used format that can be read by many different software packages. They're on the same timescale in seconds, and t0 in both the recordings and the task data is zero.