Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions examples/convert_ieeg_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
4. Cite MNE-BIDS.
5. Repeat the process for the ``fsaverage`` template coordinate frame.
5. Repeat the process for the ``fsaverage`` template coordinate space.
The iEEG data will be written by :func:`write_raw_bids` with
the addition of extra metadata elements in the following files:
Expand Down Expand Up @@ -115,13 +115,12 @@
# - `background on FreeSurfer`_
# - `MNE-Python coordinate frames`_
#
# Currently, MNE-Python supports the ``mni_tal`` and ``mri`` coordinate frames,
# MNE-Python supports uses ``mni_tal`` and ``mri`` coordinate frames,
# corresponding to the ``fsaverage`` and ``ACPC`` (for an ACPC-aligned T1) BIDS
# coordinate systems respectively. All other coordinate coordinate frames in
# MNE-Python if written with :func:`mne_bids.write_raw_bids` are written with
# coordinate system ``'Other'``. Note, then we suggest using
# :func:`mne_bids.update_sidecar_json` to update the sidecar
# ``*_coordsystem.json`` file to add additional information.
# MNE-Python, if written with :func:`mne_bids.write_raw_bids`, must have
# an :attr:`mne_bids.BIDSPath.space` specified, and will be read in with
# the montage channel locations set to the coordinate frame 'unknown'.
Comment on lines +121 to +123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true? Or perhaps it can just be made a little bit more clear.

Maybe it would also help to provide a direct link to the specification for that matter?

https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/04-intracranial-electroencephalography.html#electrode-description-_electrodestsv

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not in MNE_TO_BIDS_FRAMES and there is no BIDSPath.space then it won't be written. It could default to 'Other' that's a -1 from me, I don't think Other should be in BIDS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You get

warn("Coordinate frame could not be inferred from the raw object "
                 "and the BIDSPath.space was none, skipping the writing of "
                 "channel positions")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's linked at the top, we could add it there, but the whole narrative is trying to get them not to save data in a template coordinate frame if possible so handing a list of template coordinate frames that close to the beginning of the example seems counterproductive

#
# Step 2: Formatting as BIDS
# --------------------------
Expand Down Expand Up @@ -207,7 +206,7 @@

# %%
# MNE-BIDS has created a suitable directory structure for us, and among other
# meta data files, it started an ``events.tsv``` and ``channels.tsv`` file,
# meta data files, it started an ``events.tsv`` and ``channels.tsv`` file,
# and created an initial ``dataset_description.json`` file on top!
#
# Now it's time to manually check the BIDS directory and the meta files to add
Expand All @@ -217,6 +216,7 @@

search_folder_for_text('n/a', bids_root)

# %%
# Remember that there is a convenient JavaScript tool to validate all your BIDS
# directories called the "BIDS-validator", available as a web version and a
# command line tool:
Expand Down Expand Up @@ -343,8 +343,8 @@
raw2.set_montage(montage2)

# check that we can recover the coordinates
print('Recovered coordinate: {recovered}\n'
'Saved coordinate: {saved}'.format(
print('Recovered coordinate head: {recovered}\n'
'Saved coordinate head: {saved}'.format(
recovered=raw2.info['chs'][0]['loc'][:3],
saved=raw.info['chs'][0]['loc'][:3]))

Expand All @@ -368,7 +368,7 @@

# %%
# As you can see the coordinates stored in the ``raw`` object are slightly off.
# This is because the head coordinate frame is defined by the fiducials
# This is because the ``head`` coordinate frame is defined by the fiducials
# (nasion, left and right pre-auricular points), and, in the first case,
# the fiducials were found on the individual anatomy and then transformed
# to MNI space, whereas, in the second case, they were found directly on
Expand All @@ -378,8 +378,8 @@
# the positions are the same in MNI coordinates which is what is important.
#
# As a final step, let's go over how to assign the fiducials for a template
# brain where they are not found for you. Many template coordinate frames
# are allowed by BIDS but not used in MNE-Python.
# brain where they are not found for you. Many template coordinate systems
# are allowed by BIDS but are not used in MNE-Python.
#
# .. note::
# As of this writing, BIDS accepts channel coordinates in reference to the
Expand Down Expand Up @@ -563,7 +563,7 @@
f'scanner RAS:\nnasion: {nas}\nlpa: {lpa}\nrpa: {rpa}')

# read raw in again to start over
raw_ = read_raw_bids(bids_path=bids_path)
raw2 = read_raw_bids(bids_path=bids_path)

# %%
# Now, it's the same as if we just got the montage from the raw in scanner RAS
Expand Down Expand Up @@ -603,3 +603,14 @@
'Saved coordinate: {saved}'.format(
recovered=montage2.get_positions()['ch_pos']['LENT 1'],
saved=montage.get_positions()['ch_pos']['LENT 1']))

# %%
# In summary, as we saw, these standard template spaces that are allowable by
# BIDS are quite complicated. We therefore only cover these cases because
# datasets are allowed to be in these coordinate systems, and we want to be
# able to analyze them with MNE-Python. Because the coordinate space doesn't
# specify a coordinate frame within that space for the standard templates
# and because saving the raw data in the individual's ACPC space allows the
# person analyzing the data to transform the positions to whatever template
# they want, we recommend if at all possible, saving BIDS iEEG data in ACPC
# space.