# Data-generating model shared by make_data.py and simulation.py. Python 3.13, NumPy.
# Myelin g-ratio from electron micrographs: in 5 mice per genotype, about 100 myelinated axons are measured
# (axon diameter and fibre diameter, um). Myelin thickness grows with axon diameter with a positive intercept, so the
# g-ratio (axon / fibre diameter) rises with axon size. Mice differ in myelin thickness; axons vary around their mouse.
# The knockout can thin myelin (myelin_ratio) or simply have smaller axons (diam_ratio) with normal myelin.
import numpy as np
MICE = 5

def study(rng, myelin_ratio=1.0, diam_ratio=1.0, sd_mouse=0.06, sd_axon=0.12):
    rows = []
    for g, mr, dr in (("wild-type", 1.0, 1.0), ("knockout", myelin_ratio, diam_ratio)):
        for m in range(MICE):
            em = np.exp(rng.normal(0, sd_mouse))
            n = rng.integers(80, 121)
            d = 0.8 * dr * np.exp(rng.normal(0, 0.35, n))                      # axon diameter
            thick = (0.06 + 0.12 * d) * mr * em * np.exp(rng.normal(0, sd_axon, n))   # myelin thickness
            rows += [(g, f"{g[0].upper()}{m + 1}", i + 1, round(float(a), 3), round(float(a + 2 * t), 3)) for i, (a, t) in enumerate(zip(d, thick))]
    return rows
