# Data-generating model shared by make_data.py and simulation.py. Python 3.13, NumPy.
# Transwell migration: cells that crossed the membrane counted in 5 fields per insert, 2 inserts per condition, in
# several independent experiments. Counts differ a lot between experiments (seeding, cell state, staining), the
# knockdown effect varies a little between experiments, inserts differ, and fields scatter around the insert mean.
import numpy as np
INSERTS, FIELDS = 2, 5

def experiment(rng, kd_ratio=1.0, mean=60, sd_day=0.35, sd_cond=0.12, sd_insert=0.15, shape_field=8):
    rows = []; day = rng.normal(0, sd_day)
    for cond, ratio in (("control", 1.0), ("knockdown", kd_ratio)):
        mc = mean * ratio * np.exp(day + rng.normal(0, sd_cond))
        for i in range(INSERTS):
            mi = mc * np.exp(rng.normal(0, sd_insert))
            for f in range(FIELDS):                                   # gamma-Poisson: uneven spread of cells over the membrane
                rows.append((cond, i + 1, f + 1, rng.poisson(rng.gamma(shape_field, mi / shape_field))))
    return rows
