|
13 | 13 | # from copy import deepcopy |
14 | 14 | # from functools import partial |
15 | 15 |
|
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 |
19 | 17 |
|
20 | 18 | # from mne import create_info, EvokedArray, read_evokeds, __file__ as _mne_file |
21 | 19 | # from mne.channels import (Montage, read_montage, read_dig_montage, |
|
28 | 26 | # from mne.channels._dig_montage_utils import _transform_to_head_call |
29 | 27 | # from mne.channels._dig_montage_utils import _fix_data_fiducials |
30 | 28 | from mne.channels._standard_montage_utils import read_standard_montage |
| 29 | +from mne.utils import Bunch |
31 | 30 | # from mne.utils import (_TempDir, run_tests_if_main, assert_dig_allclose, |
32 | 31 | # object_diff, Bunch) |
33 | 32 | # from mne.bem import _fit_sphere |
|
48 | 47 | # from mock import patch |
49 | 48 |
|
50 | 49 | 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 |
51 | 74 |
|
52 | 75 |
|
53 | 76 | def _compare_dig_montage_and_standard_montage(self, other): |
54 | | - """Allows ACTUAL_DigMontage == EXPECTED_Montage""" |
| 77 | + """Allow ACTUAL_DigMontage == EXPECTED_Montage.""" |
55 | 78 | assert isinstance(self, DigMontage), 'DigMontage should be left element' |
56 | 79 | assert isinstance(other, Montage), 'Montage should be right element' |
57 | | - return True |
58 | 80 |
|
| 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 |
59 | 95 |
|
60 | 96 |
|
61 | 97 | @pytest.mark.parametrize('kind', _BUILT_IN_MONTAGES) |
| 98 | +# @pytest.mark.parametrize('kind', [_BUILT_IN_MONTAGES[0]]) |
62 | 99 | @patch("mne.channels.DigMontage.__eq__", |
63 | 100 | _compare_dig_montage_and_standard_montage) |
64 | 101 | def test_read_montage(kind): |
65 | 102 | """Test difference between old and new standard montages.""" |
66 | 103 | old_montage = read_montage(kind) |
67 | 104 | new_montage = read_standard_montage(kind) |
| 105 | + # import pdb; pdb.set_trace() |
68 | 106 | assert new_montage == old_montage |
0 commit comments