Skip to content

Commit f9e1c2a

Browse files
author
Joan Massich
committed
Check standard montages
1 parent c289b56 commit f9e1c2a

2 files changed

Lines changed: 48 additions & 6 deletions

File tree

mne/channels/_dig_montage_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def _transform_to_head_call(data):
9494
}
9595

9696

97+
# XXX: to split as _parse like bvct
9798
def _read_dig_montage_egi(
9899
fname,
99100
_scaling,
@@ -149,6 +150,7 @@ def _read_dig_montage_egi(
149150
)
150151

151152

153+
# XXX: this should go in _digitization/utils
152154
def _foo_get_data_from_dig(dig):
153155
# XXXX:
154156
# This does something really similar to _read_dig_montage_fif but:
@@ -187,8 +189,9 @@ def _foo_get_data_from_dig(dig):
187189
)
188190

189191

192+
# XXX: this should go in _digitization/utils
190193
def _get_fid_coords(dig):
191-
fid_coords = dict()
194+
fid_coords = Bunch()
192195
fid_coord_frames = []
193196

194197
for d in dig:
@@ -213,6 +216,7 @@ def _get_fid_coords(dig):
213216
return fid_coords, coord_frame
214217

215218

219+
# XXX: to remove in 0.20
216220
def _read_dig_montage_bvct(
217221
fname,
218222
unit,

mne/channels/tests/test_standard_montage.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# from copy import deepcopy
1414
# from functools import partial
1515

16-
# from numpy.testing import (assert_array_equal, assert_almost_equal,
17-
# assert_allclose, assert_array_almost_equal,
18-
# assert_array_less, assert_equal)
16+
from numpy.testing import assert_array_equal
1917

2018
# from mne import create_info, EvokedArray, read_evokeds, __file__ as _mne_file
2119
# from mne.channels import (Montage, read_montage, read_dig_montage,
@@ -28,6 +26,7 @@
2826
# from mne.channels._dig_montage_utils import _transform_to_head_call
2927
# from mne.channels._dig_montage_utils import _fix_data_fiducials
3028
from mne.channels._standard_montage_utils import read_standard_montage
29+
from mne.utils import Bunch
3130
# from mne.utils import (_TempDir, run_tests_if_main, assert_dig_allclose,
3231
# object_diff, Bunch)
3332
# from mne.bem import _fit_sphere
@@ -48,21 +47,60 @@
4847
# from mock import patch
4948

5049
from unittest.mock import patch
50+
from mne.io.constants import FIFF
51+
# from mne.channels._dig_montage_utils import _get_fid_coords
52+
from mne.channels._dig_montage_utils import _cardinal_ident_mapping
53+
54+
55+
# XXX: this should go in _digitization/utils
56+
def _get_ch_pos_location(dig):
57+
return [d['r'] for d in dig if d['kind'] == FIFF.FIFFV_POINT_EEG]
58+
59+
60+
# XXX: this should go in _digitization/utils
61+
# XXX: this is really similar to _get_fid_coords from pr-6706 but I needed
62+
# something different so, I'll merge later
63+
def _get_fid_coords(dig):
64+
fid_coords = Bunch(nasion=None, lpa=None, rpa=None)
65+
fid_coord_frames = Bunch(nasion=None, lpa=None, rpa=None)
66+
67+
for d in dig:
68+
if d['kind'] == FIFF.FIFFV_POINT_CARDINAL:
69+
key = _cardinal_ident_mapping[d['ident']]
70+
fid_coords[key] = d['r']
71+
fid_coord_frames[key] = d['coord_frame']
72+
73+
return fid_coords, fid_coord_frames
5174

5275

5376
def _compare_dig_montage_and_standard_montage(self, other):
54-
"""Allows ACTUAL_DigMontage == EXPECTED_Montage"""
77+
"""Allow ACTUAL_DigMontage == EXPECTED_Montage."""
5578
assert isinstance(self, DigMontage), 'DigMontage should be left element'
5679
assert isinstance(other, Montage), 'Montage should be right element'
57-
return True
5880

81+
assert len(self.ch_names) == len(other.ch_names)
82+
83+
dig_montage_fid, _ = _get_fid_coords(self.dig)
84+
assert dig_montage_fid.nasion == other.nasion
85+
assert dig_montage_fid.lpa == other.lpa
86+
assert dig_montage_fid.rpa == other.rpa
87+
88+
dig_montage_ch_pos = dict(zip(
89+
self.ch_names, _get_ch_pos_location(self.dig)))
90+
montage_ch_pos = dict(zip(other.ch_names, other.pos))
91+
for kk, expected_pos in montage_ch_pos.items():
92+
assert_array_equal(dig_montage_ch_pos[kk], expected_pos)
93+
94+
return True # If all assert pass, then they are equal
5995

6096

6197
@pytest.mark.parametrize('kind', _BUILT_IN_MONTAGES)
98+
# @pytest.mark.parametrize('kind', [_BUILT_IN_MONTAGES[0]])
6299
@patch("mne.channels.DigMontage.__eq__",
63100
_compare_dig_montage_and_standard_montage)
64101
def test_read_montage(kind):
65102
"""Test difference between old and new standard montages."""
66103
old_montage = read_montage(kind)
67104
new_montage = read_standard_montage(kind)
105+
# import pdb; pdb.set_trace()
68106
assert new_montage == old_montage

0 commit comments

Comments
 (0)