# Data-generating model shared by make_data.py and simulation.py. Python 3.13, NumPy.
# Hippocampal LTP: 1-3 slices per mouse (6 mice per genotype); in each slice the fEPSP slope is recorded once a minute
# for 20 min of baseline and 60 min after high-frequency stimulation (HFS). Potentiation (the rise above baseline)
# varies between mice and between slices of a mouse; post-tetanic potentiation decays over the first minutes, and
# every reading has noise. Slopes are in mV/ms; each slice has its own baseline slope.
import numpy as np
MICE = 6
MINUTES = np.r_[np.arange(-19, 1), np.arange(1, 61)]

def study(rng, ko_ratio=1.0, pot=0.5, sd_mouse=0.35, sd_slice=0.30, noise=0.04, mice=MICE):
    rows = []
    for g, r in (("wild-type", 1.0), ("knockout", ko_ratio)):
        for m in range(mice):
            pm = pot * r * np.exp(rng.normal(0, sd_mouse))
            for s in range(rng.integers(1, 4)):                                   # 1, 2 or 3 slices
                ps = pm * np.exp(rng.normal(0, sd_slice)); base = rng.uniform(0.3, 1.0)
                for t in MINUTES:
                    rel = 1.0 if t <= 0 else 1 + ps * (1 + 1.2 * np.exp(-t / 4))
                    rows.append((g, f"{g[0].upper()}{m + 1}", s + 1, int(t), round(base * rel * (1 + rng.normal(0, noise)), 4)))
    return rows
