contracts: shared data classes, protocols and contract test suites
Step 1 of the tea_modulo plan: Recording (MNE Raw from EDF), ValidationSummary, Preprocessed, Labels, Study, the Validator/Preprocessor/Process/Biomarker protocols with check_module(), reusable contract suites in contracts.testing, and an AST test that enforces the module boundary rule.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
|
||||
def make_prep(seconds=60.0, fs=250.0, channels=("Fp1", "Fp2", "O1", "O2"), seed=0,
|
||||
window_s=4.0, step_s=2.0):
|
||||
"""A small Preprocessed made in memory (white noise, one variant)."""
|
||||
import mne
|
||||
from tea_modulo.contracts import Preprocessed
|
||||
|
||||
rng = np.random.default_rng(seed)
|
||||
n = int(seconds * fs)
|
||||
info = mne.create_info(list(channels), fs, ch_types="eeg")
|
||||
raw = mne.io.RawArray(rng.normal(0, 20e-6, (len(channels), n)), info, verbose="error")
|
||||
starts = np.arange(0, seconds - window_s + 1e-9, step_s)
|
||||
windows = pd.DataFrame({"start_s": starts, "end_s": starts + window_s,
|
||||
"clean": np.ones(len(starts), bool),
|
||||
"gap": np.zeros(len(starts), bool)})
|
||||
plan = {"schema": 1, "name": "test"}
|
||||
return Preprocessed(variants={"hp05_prom": raw}, windows=windows, age_months=24.0,
|
||||
plan=plan, plan_hash="test")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def prep():
|
||||
return make_prep()
|
||||
Reference in New Issue
Block a user