Test Maxwell filter basic version.
()
| 565 | # This is also slow, but we probably want it running on all OSes |
| 566 | @testing.requires_testing_data |
| 567 | def test_basic(): |
| 568 | """Test Maxwell filter basic version.""" |
| 569 | # Load testing data (raw, SSS std origin, SSS non-standard origin) |
| 570 | raw = read_crop(raw_fname, (0.0, 1.0)) |
| 571 | raw_err = read_crop(raw_fname).apply_proj() |
| 572 | raw_erm = read_crop(erm_fname) |
| 573 | with pytest.raises(RuntimeError, match="cannot be applied"): |
| 574 | maxwell_filter(raw_err) |
| 575 | with pytest.raises(TypeError, match="instance of BaseRaw"): |
| 576 | maxwell_filter(1.0) |
| 577 | with pytest.raises(ValueError, match="Number of requested bases"): |
| 578 | maxwell_filter(raw, int_order=20) # too many |
| 579 | |
| 580 | n_int_bases = int_order**2 + 2 * int_order |
| 581 | n_ext_bases = ext_order**2 + 2 * ext_order |
| 582 | nbases = n_int_bases + n_ext_bases |
| 583 | |
| 584 | # Check number of bases computed correctly |
| 585 | assert _get_n_moments([int_order, ext_order]).sum() == nbases |
| 586 | |
| 587 | # Test SSS computation at the standard head origin |
| 588 | assert len(raw.info["projs"]) == 12 # 11 MEG projs + 1 AVG EEG |
| 589 | with use_coil_def(elekta_def_fname): |
| 590 | raw_sss = maxwell_filter( |
| 591 | raw, origin=mf_head_origin, regularize=None, bad_condition="ignore" |
| 592 | ) |
| 593 | assert len(raw_sss.info["projs"]) == 1 # avg EEG |
| 594 | assert raw_sss.info["projs"][0]["desc"] == "Average EEG reference" |
| 595 | assert_meg_snr(raw_sss, read_crop(sss_std_fname), 200.0, 1000.0) |
| 596 | py_cal = raw_sss.info["proc_history"][0]["max_info"]["sss_cal"] |
| 597 | assert len(py_cal) == 0 |
| 598 | py_ctc = raw_sss.info["proc_history"][0]["max_info"]["sss_ctc"] |
| 599 | assert len(py_ctc) == 0 |
| 600 | py_st = raw_sss.info["proc_history"][0]["max_info"]["max_st"] |
| 601 | assert len(py_st) == 0 |
| 602 | with pytest.raises(RuntimeError, match="cannot reapply"): |
| 603 | maxwell_filter(raw_sss) |
| 604 | |
| 605 | # Test SSS computation at non-standard head origin |
| 606 | with use_coil_def(elekta_def_fname): |
| 607 | raw_sss = maxwell_filter( |
| 608 | raw, origin=[0.0, 0.02, 0.02], regularize=None, bad_condition="ignore" |
| 609 | ) |
| 610 | assert_meg_snr(raw_sss, read_crop(sss_nonstd_fname), 250.0, 700.0) |
| 611 | |
| 612 | # Test SSS computation at device origin |
| 613 | sss_erm_std = read_crop(sss_erm_std_fname) |
| 614 | raw_sss = maxwell_filter( |
| 615 | raw_erm, |
| 616 | coord_frame="meg", |
| 617 | origin=mf_meg_origin, |
| 618 | regularize=None, |
| 619 | bad_condition="ignore", |
| 620 | ) |
| 621 | assert_meg_snr(raw_sss, sss_erm_std, 70.0, 260.0) |
| 622 | for key in ("job", "frame"): |
| 623 | vals = [ |
| 624 | x.info["proc_history"][0]["max_info"]["sss_info"][key] |
nothing calls this directly
no test coverage detected