Test surface and vector source estimate morph.
(tmp_path)
| 296 | |
| 297 | @testing.requires_testing_data |
| 298 | def test_surface_vector_source_morph(tmp_path): |
| 299 | """Test surface and vector source estimate morph.""" |
| 300 | pytest.importorskip("h5io") |
| 301 | inverse_operator_surf = read_inverse_operator(fname_inv_surf) |
| 302 | |
| 303 | stc_surf = read_source_estimate(fname_smorph, subject="sample") |
| 304 | stc_surf.crop(0.09, 0.1) # for faster computation |
| 305 | |
| 306 | stc_vec = _real_vec_stc() |
| 307 | |
| 308 | source_morph_surf = compute_source_morph( |
| 309 | inverse_operator_surf["src"], subjects_dir=subjects_dir, smooth=1, warn=False |
| 310 | ) # smooth 1 for speed |
| 311 | src_to_fs = mne.read_source_spaces( |
| 312 | subjects_dir / "fsaverage" / "bem" / "fsaverage-ico-5-src.fif" |
| 313 | ) |
| 314 | morph_with_src_to = compute_source_morph( |
| 315 | inverse_operator_surf["src"], |
| 316 | subjects_dir=subjects_dir, |
| 317 | src_to=src_to_fs, |
| 318 | smooth=1, |
| 319 | warn=False, |
| 320 | ) |
| 321 | assert morph_with_src_to.spacing is None |
| 322 | assert source_morph_surf.subject_from == "sample" |
| 323 | assert source_morph_surf.subject_to == "fsaverage" |
| 324 | assert source_morph_surf.kind == "surface" |
| 325 | assert isinstance(source_morph_surf.src_data, dict) |
| 326 | assert isinstance(source_morph_surf.src_data["vertices_from"], list) |
| 327 | assert isinstance(source_morph_surf, SourceMorph) |
| 328 | stc_surf_morphed = source_morph_surf.apply(stc_surf) |
| 329 | assert isinstance(stc_surf_morphed, SourceEstimate) |
| 330 | stc_vec_morphed = source_morph_surf.apply(stc_vec) |
| 331 | with pytest.raises(ValueError, match="Invalid value for the 'output'"): |
| 332 | source_morph_surf.apply(stc_surf, output="nifti1") |
| 333 | |
| 334 | # check if correct class after morphing |
| 335 | assert isinstance(stc_surf_morphed, SourceEstimate) |
| 336 | assert isinstance(stc_vec_morphed, VectorSourceEstimate) |
| 337 | |
| 338 | # check __repr__ |
| 339 | assert "surface" in repr(source_morph_surf) |
| 340 | |
| 341 | # check loading and saving for surf |
| 342 | source_morph_surf.save(tmp_path / "42.h5") |
| 343 | |
| 344 | source_morph_surf_r = read_source_morph(tmp_path / "42.h5") |
| 345 | |
| 346 | assert all( |
| 347 | [ |
| 348 | read == saved |
| 349 | for read, saved in zip( |
| 350 | sorted(source_morph_surf_r.__dict__), sorted(source_morph_surf.__dict__) |
| 351 | ) |
| 352 | ] |
| 353 | ) |
| 354 | |
| 355 | # check wrong subject correction |
nothing calls this directly
no test coverage detected