|
| 1 | +"""pyriemann API compatibility tests.""" |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from meegkit.utils.covariances import block_covariance |
| 7 | + |
| 8 | +ROOT = Path(__file__).resolve().parents[1] |
| 9 | + |
| 10 | + |
| 11 | +def _version_tuple(version): |
| 12 | + return tuple(int(part) for part in version.split(".")) |
| 13 | + |
| 14 | + |
| 15 | +def test_pyriemann_lower_bound_uses_geometry_api(): |
| 16 | + """Ensure the supported pyriemann range has the geometry namespace.""" |
| 17 | + requirement = next( |
| 18 | + line |
| 19 | + for line in (ROOT / "requirements.txt").read_text().splitlines() |
| 20 | + if line.startswith("pyriemann") |
| 21 | + ) |
| 22 | + |
| 23 | + _, lower_bound = requirement.split(">=") |
| 24 | + |
| 25 | + assert _version_tuple(lower_bound) >= (0, 12) |
| 26 | + |
| 27 | + |
| 28 | +def test_pyriemann_imports_use_modern_public_api(): |
| 29 | + """Keep deprecated pyriemann utils imports out of meegkit.""" |
| 30 | + source_files = [ |
| 31 | + ROOT / "meegkit" / "asr.py", |
| 32 | + ROOT / "meegkit" / "trca.py", |
| 33 | + ROOT / "meegkit" / "utils" / "covariances.py", |
| 34 | + ] |
| 35 | + source = "\n".join(path.read_text() for path in source_files) |
| 36 | + |
| 37 | + assert "pyriemann.utils.mean" not in source |
| 38 | + assert "pyriemann.utils.covariance" not in source |
| 39 | + assert "check_function" not in source |
| 40 | + assert "cov_est_functions" not in source |
| 41 | + |
| 42 | + |
| 43 | +def test_block_covariance_uses_pyriemann_covariances(): |
| 44 | + """Compare block covariance with pyriemann's vectorized covariance helper.""" |
| 45 | + from pyriemann.geometry.covariance import covariances |
| 46 | + |
| 47 | + data = 0.1 + 0.01 * (1 + np.arange(24, dtype=float).reshape(3, 8)) |
| 48 | + expected_blocks = np.array( |
| 49 | + [data[:, start:start + 4] for start in range(0, 4, 2)] |
| 50 | + ) |
| 51 | + |
| 52 | + actual = block_covariance(data, window=4, overlap=0.5, padding=False) |
| 53 | + |
| 54 | + np.testing.assert_allclose(actual, covariances(expected_blocks, estimator="cov")) |
0 commit comments