Prepare forward solution for inverse solvers.
(forward, info, noise_cov=None, copy=True)
| 1123 | |
| 1124 | |
| 1125 | def _select_orient_forward(forward, info, noise_cov=None, copy=True): |
| 1126 | """Prepare forward solution for inverse solvers.""" |
| 1127 | # fwd['sol']['row_names'] may be different order from fwd['info']['chs'] |
| 1128 | fwd_sol_ch_names = forward["sol"]["row_names"] |
| 1129 | all_ch_names = set(fwd_sol_ch_names) |
| 1130 | all_bads = set(info["bads"]) |
| 1131 | if noise_cov is not None: |
| 1132 | all_ch_names &= set(noise_cov["names"]) |
| 1133 | all_bads |= set(noise_cov["bads"]) |
| 1134 | else: |
| 1135 | noise_cov = dict(bads=info["bads"]) |
| 1136 | ch_names = [ |
| 1137 | c["ch_name"] |
| 1138 | for c in info["chs"] |
| 1139 | if c["ch_name"] not in all_bads and c["ch_name"] in all_ch_names |
| 1140 | ] |
| 1141 | |
| 1142 | if not len(info["bads"]) == len(noise_cov["bads"]) or not all( |
| 1143 | b in noise_cov["bads"] for b in info["bads"] |
| 1144 | ): |
| 1145 | logger.info( |
| 1146 | 'info["bads"] and noise_cov["bads"] do not match, ' |
| 1147 | "excluding bad channels from both" |
| 1148 | ) |
| 1149 | |
| 1150 | # check the compensation grade |
| 1151 | _check_compensation_grade(forward["info"], info, "forward") |
| 1152 | |
| 1153 | n_chan = len(ch_names) |
| 1154 | logger.info("Computing inverse operator with %d channels.", n_chan) |
| 1155 | forward = pick_channels_forward(forward, ch_names, ordered=True, copy=copy) |
| 1156 | info_idx = [info["ch_names"].index(name) for name in ch_names] |
| 1157 | info_picked = pick_info(info, info_idx) |
| 1158 | forward["info"]._check_consistency() |
| 1159 | info_picked._check_consistency() |
| 1160 | return forward, info_picked |
| 1161 | |
| 1162 | |
| 1163 | def _triage_loose(src, loose, fixed="auto"): |
no test coverage detected