mne-tools / mne-bids

MNE-BIDS is a Python package that allows you to read and write BIDS-compatible datasets with the help of MNE-Python.
https://mne.tools/mne-bids/
BSD 3-Clause "New" or "Revised" License
132 stars 86 forks source link

[API] Reading montage for EEG/iEEG from electrodes.tsv and coordsystem.json #605

Open adam2392 opened 3 years ago

adam2392 commented 3 years ago

Describe the problem

I was reading in some dataset and wanted to read in the montage again later, but without reading in the whole raw file. However, that is not possible right now.

Describe your solution

Outside of read_raw_bids, it would be nice to be able to have a public API for read_montage_bids or something that gets the electrode coordinates and other data (e.g. impedance) and returns a DigMontage, or a dictionary of coordinate points(?)

Describe possible alternatives

I suppose, I could always just run read_raw_bids again and do raw.get_montage(), but that seems extra to me.

Additional context

Idk if this is possible for MEG, since I don't work w/ it (yet), but they have a coordsystem.json at least.

agramfort commented 3 years ago

as you read raw files without preload doing raw.get_montage() seem acceptable no?

adam2392 commented 3 years ago

I would like to revive this discussion if possible. In some clinical workflows for iEEG, one might not have an existing EEG-data file yet, when they would like to localize the electrode coordinates. E.g.

  1. epilepsy monitor patient and collect data in NK/EDF formats
  2. Meanwhile, CT and T1 scans are collected to perform anatomical parcellation (e.g. using FreeSurfer) and electrode localization (e.g. using FieldTrip)
  3. It would be ideal to get IO for the electrodes.tsv and coordsystem.json files that will end up working with MNE-python/mne-bids, but without the need to use read_raw_bids.
  4. Sometime later, iEEG data acquisition is complete, and the electrodes.tsv and coordsystem.json files are already ready to be used.

The following could use some iterating probably. For sake of an example:

def read_dig_bids(elecs_fname, coordsystem_fname):
# creates a DigMontage from the read in files that are supposedly BIDS-compliant and handles error/warning checks

and

def write_electrodes_tsv(name, x, y, z, size=None, impedance=None, **kwargs):
# writes the electrodes.tsv file

def write_coordsystem_json(
# writes the coordsystem.json file