Skip to content

Commit

Permalink
[MRG] Patch writing iEEGCoordinateSystemDescription (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
sappelhoff authored Feb 13, 2021
1 parent 77b9017 commit 74ac41a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
3 changes: 2 additions & 1 deletion doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ Bug fixes
- Fix writing MEGIN Triux files, by `Alexandre Gramfort`_ (:gh:`674`)
- Anonymization of EDF files in :func:`write_raw_bids` will now convert recording date to ``01-01-1985 00:00:00`` if anonymization takes place, while setting the recording date in the ``scans.tsv`` file to the anonymized date, thus making the file EDF/EDFBrowser compliant, by `Adam Li`_ (:gh:`669`)
- :func:`mne_bids.write_raw_bids` will not overwrite an existing ``coordsystem.json`` anymore, unless explicitly requested, by `Adam Li`_ (:gh:`675`)
- :func:`mne_bids.read_raw_bids` now properly handles datasets without event descriptions, by `Richard Höchenberger`_ (:gh:`680`)
- :func:`mne_bids.read_raw_bids` now properly handles datasets without event descriptions, by `Richard Höchenberger`_ (:gh:`680`)
- :func:`mne_bids.stats.count_events` now handles files without a ``trial_type`` or ``stim_type`` column gracefully, by `Richard Höchenberger`_ (:gh:`682`)
- :func:`mne_bids.read_raw_bids` now correctly treats ``coordsystem.json`` as optional for EEG and MEG data, by `Diego Lozano-Soldevilla`_ (:gh:`691`)
- :func:`mne_bids.read_raw_bids` now ignores ``exclude`` parameters passed via ``extra_params``, by `Richard Höchenberger`_ (:gh:`703`)
- :func:`mne_bids.write_raw_bids` now retains original event IDs in the ``value`` column of ``*_events.tsv``, by `Richard Höchenberger`_ (:gh:`708`)
- Fix writing correct ``iEEGCoordinateSystemDescription``, by `Stefan Appelhoff`_ (:gh:`706`)

:doc:`Find out what was new in previous releases <whats_new_previous_releases>`

Expand Down
23 changes: 18 additions & 5 deletions mne_bids/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ def _coordsystem_json(*, raw, unit, hpi_coord_system, sensor_coord_system,
as in BIDS_COORDINATE_UNITS.
hpi_coord_system : str
Name of the coordinate system for the head coils.
sensor_coord_system : str
sensor_coord_system : str | tuple of str
Name of the coordinate system for the sensor positions.
If a tuple of strings, should be in the form:
``(BIDS coordinate frame, MNE coordinate frame)``.
fname : str
Filename to save the coordsystem.json to.
datatype : str
Expand Down Expand Up @@ -269,11 +271,21 @@ def _coordsystem_json(*, raw, unit, hpi_coord_system, sensor_coord_system,
.format(coord_frame))

# get the coordinate frame description
try:
sensor_coord_system, sensor_coord_system_mne = sensor_coord_system
except ValueError:
sensor_coord_system_mne = "n/a"
sensor_coord_system_descr = (COORD_FRAME_DESCRIPTIONS
.get(sensor_coord_system.lower(), "n/a"))
if sensor_coord_system == 'Other' and verbose:
print('Using the `Other` keyword for the CoordinateSystem field. '
'Please specify the CoordinateSystemDescription field manually.')
if sensor_coord_system == 'Other':
if verbose:
msg = ('Using the `Other` keyword for the CoordinateSystem field. '
'Please specify the CoordinateSystemDescription field '
'manually.')
logger.info(msg)
sensor_coord_system_descr = (COORD_FRAME_DESCRIPTIONS
.get(sensor_coord_system_mne.lower(),
"n/a"))

# create the coordinate json data structure based on 'datatype'
if datatype == 'meg':
Expand Down Expand Up @@ -393,7 +405,8 @@ def _write_dig_bids(bids_path, raw, overwrite=False, verbose=True):
_electrodes_tsv(raw, electrodes_path,
datatype, overwrite, verbose)
_coordsystem_json(raw=raw, unit=unit, hpi_coord_system='n/a',
sensor_coord_system=coord_frame,
sensor_coord_system=(coord_frame,
mne_coord_frame),
fname=coordsystem_path, datatype=datatype,
overwrite=overwrite, verbose=verbose)
else:
Expand Down
14 changes: 5 additions & 9 deletions mne_bids/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -2204,10 +2204,6 @@ def test_coordsystem_json_compliance(
"""Tests that coordsystem.json contents are written correctly.
Tests multiple manufacturer data formats and MEG, EEG, and iEEG.
TODO: Fix coordinatesystemdescription for iEEG.
Currently, iEEG coordinate system descriptions are not written
correctly.
"""
bids_root = _TempDir()
data_path = op.join(testing.data_path(), dir_name)
Expand Down Expand Up @@ -2304,16 +2300,16 @@ def test_coordsystem_json_compliance(
elif datatype == 'ieeg' and coord_frame == 'mni_tal':
assert 'space-mni' in coordsystem_fname
assert coordsystem_json['iEEGCoordinateSystem'] == 'Other'
# assert coordsystem_json['iEEGCoordinateSystemDescription'] == \
# COORD_FRAME_DESCRIPTIONS['mni_tal']
assert coordsystem_json['iEEGCoordinateSystemDescription'] == \
COORD_FRAME_DESCRIPTIONS['mni_tal']
elif datatype == 'ieeg' and coord_frame == 'fs_tal':
assert 'space-fs' in coordsystem_fname
assert coordsystem_json['iEEGCoordinateSystem'] == 'Other'
# assert coordsystem_json['iEEGCoordinateSystemDescription'] == \
# COORD_FRAME_DESCRIPTIONS['fs_tal']
assert coordsystem_json['iEEGCoordinateSystemDescription'] == \
COORD_FRAME_DESCRIPTIONS['fs_tal']
elif datatype == 'ieeg' and coord_frame == 'unknown':
assert coordsystem_json['iEEGCoordinateSystem'] == 'Other'
# assert coordsystem_json['iEEGCoordinateSystemDescription'] == 'n/a'
assert coordsystem_json['iEEGCoordinateSystemDescription'] == 'n/a'
elif datatype == 'meg' and dir_name == 'CTF':
assert coordsystem_json['MEGCoordinateSystem'] == 'CTF'
assert coordsystem_json['MEGCoordinateSystemDescription'] == \
Expand Down

0 comments on commit 74ac41a

Please sign in to comment.