Check the SNR of a set of channels.
(actual, desired, picks, min_tol, med_tol, msg, kind="MEG")
| 219 | |
| 220 | |
| 221 | def _check_snr(actual, desired, picks, min_tol, med_tol, msg, kind="MEG"): |
| 222 | """Check the SNR of a set of channels.""" |
| 223 | __tracebackhide__ = True |
| 224 | |
| 225 | actual_data = _get_data(actual, picks) |
| 226 | desired_data = _get_data(desired, picks) |
| 227 | bench_rms = np.sqrt(np.mean(desired_data * desired_data, axis=1)) |
| 228 | error = actual_data - desired_data |
| 229 | error_rms = np.sqrt(np.mean(error * error, axis=1)) |
| 230 | np.clip(error_rms, 1e-60, np.inf, out=error_rms) # avoid division by zero |
| 231 | snrs = bench_rms / error_rms |
| 232 | # min tol |
| 233 | snr = snrs.min() |
| 234 | bad_count = (snrs < min_tol).sum() |
| 235 | msg = f" ({msg})" if msg != "" else msg |
| 236 | assert bad_count == 0, ( |
| 237 | f"SNR (worst {snr:0.2f}) < {min_tol:0.2f} " |
| 238 | f"for {bad_count}/{len(picks)} channels{msg}" |
| 239 | ) |
| 240 | # median tol |
| 241 | snr = np.median(snrs) |
| 242 | assert snr >= med_tol, f"{kind} SNR median {snr:0.2f} < {med_tol:0.2f}{msg}" |
| 243 | |
| 244 | |
| 245 | def assert_meg_snr( |
no test coverage detected