MCPcopy
hub / github.com/mne-tools/mne-python / _check_snr

Function _check_snr

mne/utils/_testing.py:221–242  ·  view source on GitHub ↗

Check the SNR of a set of channels.

(actual, desired, picks, min_tol, med_tol, msg, kind="MEG")

Source from the content-addressed store, hash-verified

219
220
221def _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
245def assert_meg_snr(

Callers 1

assert_meg_snrFunction · 0.85

Calls 4

sqrtMethod · 0.80
_get_dataFunction · 0.70
meanMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected