Test extended-basis SSS.
(regularize, bads)
| 1086 | @pytest.mark.parametrize("regularize", ("in", None)) |
| 1087 | @pytest.mark.parametrize("bads", ([], ["MEG0111"])) |
| 1088 | def test_esss(regularize, bads): |
| 1089 | """Test extended-basis SSS.""" |
| 1090 | # Make some fake "projectors" that actually contain external SSS bases |
| 1091 | raw_erm = read_crop(erm_fname).load_data().pick("meg") |
| 1092 | raw_erm.info["bads"] = bads |
| 1093 | proj_sss = mne.compute_proj_raw( |
| 1094 | raw_erm, meg="combined", verbose="error", n_mag=15, n_grad=15 |
| 1095 | ) |
| 1096 | good_info = pick_info(raw_erm.info, pick_types(raw_erm.info, meg=True)) |
| 1097 | S_tot = _trans_sss_basis( |
| 1098 | dict(int_order=0, ext_order=3, origin=(0.0, 0.0, 0.0)), |
| 1099 | all_coils=_prep_mf_coils(good_info), |
| 1100 | coil_scale=1.0, |
| 1101 | trans=None, |
| 1102 | ) |
| 1103 | assert S_tot.shape[-1] == len(proj_sss) |
| 1104 | for a, b in zip(proj_sss, S_tot.T): |
| 1105 | a["data"]["data"][:] = b |
| 1106 | with catch_logging() as log: |
| 1107 | raw_sss = maxwell_filter( |
| 1108 | raw_erm, coord_frame="meg", regularize=regularize, verbose=True |
| 1109 | ) |
| 1110 | log = log.getvalue() |
| 1111 | assert "xtend" not in log |
| 1112 | with catch_logging() as log: |
| 1113 | raw_sss_2 = maxwell_filter( |
| 1114 | raw_erm, |
| 1115 | coord_frame="meg", |
| 1116 | regularize=regularize, |
| 1117 | ext_order=0, |
| 1118 | extended_proj=proj_sss, |
| 1119 | verbose=True, |
| 1120 | ) |
| 1121 | log = log.getvalue() |
| 1122 | assert "Extending external SSS basis using 15 projection" in log |
| 1123 | assert_allclose(raw_sss_2._data, raw_sss._data, atol=1e-20) |
| 1124 | |
| 1125 | # This should work, as the projectors should be a superset |
| 1126 | raw_erm.info["bads"] = raw_erm.info["bads"] + ["MEG0112"] |
| 1127 | maxwell_filter(raw_erm, coord_frame="meg", extended_proj=proj_sss) |
| 1128 | |
| 1129 | # Degenerate condititons |
| 1130 | proj_sss = proj_sss[:2] |
| 1131 | proj_sss[0]["data"]["col_names"] = proj_sss[0]["data"]["col_names"][:-1] |
| 1132 | with pytest.raises(ValueError, match="were missing"): |
| 1133 | maxwell_filter(raw_erm, coord_frame="meg", extended_proj=proj_sss) |
| 1134 | proj_sss[0] = 1.0 |
| 1135 | with pytest.raises(TypeError, match=r"extended_proj\[0\] must be an inst"): |
| 1136 | maxwell_filter(raw_erm, coord_frame="meg", extended_proj=proj_sss) |
| 1137 | with pytest.raises(TypeError, match="extended_proj must be an inst"): |
| 1138 | maxwell_filter(raw_erm, coord_frame="meg", extended_proj=1.0) |
| 1139 | |
| 1140 | |
| 1141 | @contextmanager |
nothing calls this directly
no test coverage detected