Skip to content

Commit

Permalink
BUG: Fix bug with BTi loc (mne-tools#10662)
Browse files Browse the repository at this point in the history
* BUG: Fix bug with BTi loc

* FIX: Counting
  • Loading branch information
larsoner authored May 23, 2022
1 parent 5bddef8 commit f5df927
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Bugs

- Fix bug in :meth:`raw.crop(start, stop) <mne.io.Raw.crop>` that would cause annotations to be erroneously shifted when ``start != 0`` and no measurement date was set. (:gh:`10491` by `Eric Larson`_)

- Fix bug in :func:`mne.io.read_raw_bti` where unknown electrode locations were not handled properly (:gh:`10662` by `Eric Larson`_)

- Rendering issues with recent MESA releases can be avoided by setting the new environment variable``MNE_3D_OPTION_MULTI_SAMPLES=1`` or using :func:`mne.viz.set_3d_options` (:gh:`10513` by `Eric Larson`_)

- Fix behavior for the ``pyvista`` 3D renderer's ``quiver3D`` function so that default arguments plot a glyph in ``arrow`` mode (:gh:`10493` by `Alex Rockhill`_)
Expand Down
2 changes: 1 addition & 1 deletion mne/io/bti/bti.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def _read_bti_header(pdf_fname, config_fname, sort_by_ch_name=True):
if ch_cfg.get('dev', dict()).get('transform', None) is not None:
ch['loc'] = _coil_trans_to_loc(ch_cfg['dev']['transform'])
else:
ch['loc'] = None
ch['loc'] = np.full(12, np.nan)
if pdf_fname is not None:
if info['data_format'] <= 2: # see DTYPES, implies integer
ch['cal'] = ch['scale'] * ch['upb'] / float(ch['gain'])
Expand Down
23 changes: 21 additions & 2 deletions mne/io/bti/tests/test_bti.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
assert_allclose, assert_equal)
import pytest

import mne
from mne.datasets import testing
from mne.io import read_raw_fif, read_raw_bti
from mne.io._digitization import _make_bti_dig_points
from mne.io.bti.bti import (_read_config,
from mne.io.bti.bti import (_read_config, _read_head_shape,
_read_bti_header, _get_bti_dev_t,
_correct_trans, _get_bti_info,
_loc_to_coil_trans, _convert_coil_trans,
_check_nan_dev_head_t, _rename_channels)
from mne.io.bti.bti import _read_head_shape
from mne.io.tests.test_raw import _test_raw_reader
from mne.io.pick import pick_info
from mne.io.constants import FIFF
Expand Down Expand Up @@ -55,6 +55,25 @@ def test_read_2500():
_test_raw_reader(read_raw_bti, pdf_fname=fname_2500, head_shape_fname=None)


def test_no_loc_none(monkeypatch):
"""Test that we don't set loc to None when no trans is found."""
ch_name = 'MLzA'

def _read_config_bad(*args, **kwargs):
cfg = _read_config(*args, **kwargs)
idx = [ch['name'] for ch in cfg['chs']].index(ch_name)
del cfg['chs'][idx]['dev']['transform']
return cfg

monkeypatch.setattr(mne.io.bti.bti, '_read_config', _read_config_bad)
kwargs = dict(pdf_fname=pdf_fnames[0], config_fname=config_fnames[0],
head_shape_fname=hs_fnames[0], rename_channels=False,
sort_by_ch_name=False)
raw = read_raw_bti(**kwargs)
idx = raw.ch_names.index(ch_name)
assert_allclose(raw.info['chs'][idx]['loc'], np.full(12, np.nan))


def test_read_config():
"""Test read bti config file."""
# for config in config_fname, config_solaris_fname:
Expand Down

0 comments on commit f5df927

Please sign in to comment.