MCPcopy
hub / github.com/mne-tools/mne-python / test_io_forward

Function test_io_forward

mne/forward/tests/test_forward.py:110–209  ·  view source on GitHub ↗

Test IO for forward solutions.

(tmp_path)

Source from the content-addressed store, hash-verified

108@pytest.mark.slowtest
109@testing.requires_testing_data
110def test_io_forward(tmp_path):
111 """Test IO for forward solutions."""
112 # do extensive tests with MEEG + grad
113 n_channels, n_src = 366, 108
114 fwd = read_forward_solution(fname_meeg_grad)
115 assert isinstance(fwd, Forward)
116 fwd = read_forward_solution(fname_meeg_grad)
117 fwd = convert_forward_solution(fwd, surf_ori=True)
118 leadfield = fwd["sol"]["data"]
119 assert_equal(leadfield.shape, (n_channels, n_src))
120 assert_equal(len(fwd["sol"]["row_names"]), n_channels)
121 fname_temp = tmp_path / "test-fwd.fif"
122 with pytest.warns(RuntimeWarning, match="stored on disk"):
123 write_forward_solution(fname_temp, fwd, overwrite=True)
124
125 fwd = read_forward_solution(fname_meeg_grad)
126 fwd = convert_forward_solution(fwd, surf_ori=True)
127 fwd_read = read_forward_solution(fname_temp)
128 fwd_read = convert_forward_solution(fwd_read, surf_ori=True)
129 leadfield = fwd_read["sol"]["data"]
130 assert_equal(leadfield.shape, (n_channels, n_src))
131 assert_equal(len(fwd_read["sol"]["row_names"]), n_channels)
132 assert_equal(len(fwd_read["info"]["chs"]), n_channels)
133 assert "dev_head_t" in fwd_read["info"]
134 assert "mri_head_t" in fwd_read
135 assert_array_almost_equal(fwd["sol"]["data"], fwd_read["sol"]["data"])
136
137 fwd = read_forward_solution(fname_meeg)
138 fwd = convert_forward_solution(fwd, surf_ori=True, force_fixed=True, use_cps=False)
139 with pytest.warns(RuntimeWarning, match="stored on disk"):
140 write_forward_solution(fname_temp, fwd, overwrite=True)
141 fwd_read = read_forward_solution(fname_temp)
142 fwd_read = convert_forward_solution(
143 fwd_read, surf_ori=True, force_fixed=True, use_cps=False
144 )
145 assert repr(fwd_read)
146 assert isinstance(fwd_read, Forward)
147 assert is_fixed_orient(fwd_read)
148 assert_forward_allclose(fwd, fwd_read)
149
150 fwd = convert_forward_solution(fwd, surf_ori=True, force_fixed=True, use_cps=True)
151 leadfield = fwd["sol"]["data"]
152 assert_equal(leadfield.shape, (n_channels, 1494 / 3))
153 assert_equal(len(fwd["sol"]["row_names"]), n_channels)
154 assert_equal(len(fwd["info"]["chs"]), n_channels)
155 assert "dev_head_t" in fwd["info"]
156 assert "mri_head_t" in fwd
157 assert fwd["surf_ori"]
158 with pytest.warns(RuntimeWarning, match="stored on disk"):
159 write_forward_solution(fname_temp, fwd, overwrite=True)
160 fwd_read = read_forward_solution(fname_temp)
161 fwd_read = convert_forward_solution(
162 fwd_read, surf_ori=True, force_fixed=True, use_cps=True
163 )
164 assert repr(fwd_read)
165 assert isinstance(fwd_read, Forward)
166 assert is_fixed_orient(fwd_read)
167 assert_forward_allclose(fwd, fwd_read)

Callers

nothing calls this directly

Calls 6

read_forward_solutionFunction · 0.90
convert_forward_solutionFunction · 0.90
write_forward_solutionFunction · 0.90
is_fixed_orientFunction · 0.90
assert_forward_allcloseFunction · 0.85
saveMethod · 0.45

Tested by

no test coverage detected