diff --git a/doc/whats_new.rst b/doc/whats_new.rst index a4bf8231b..177dbdbb8 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -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 ` diff --git a/mne_bids/dig.py b/mne_bids/dig.py index 94645d5d5..36b5cf89c 100644 --- a/mne_bids/dig.py +++ b/mne_bids/dig.py @@ -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 @@ -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': @@ -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: diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py index 7b5eea8b3..a75a70f7f 100644 --- a/mne_bids/tests/test_write.py +++ b/mne_bids/tests/test_write.py @@ -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) @@ -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'] == \