# Data-generating model shared by make_data.py and simulation.py. Python 3.13, NumPy.
# Dendritic spines: in each of 6 mice per genotype, 6 neurons are imaged blind to genotype and spines are counted on
# 2 secondary dendritic segments per neuron (10-30 um long). Spine density (about 1.2 per um) varies between mice,
# between neurons of a mouse and between segments of a neuron; each count is Poisson given its segment's density.
import numpy as np
MICE, NEURONS, SEGMENTS = 6, 6, 2

def study(rng, ko_ratio=1.0, density=1.2, sd_mouse=0.12, sd_neuron=0.15, sd_segment=0.10, mice=MICE, neurons=NEURONS):
    rows = []
    for g, r in (("wild-type", 1.0), ("knockout", ko_ratio)):
        for m in range(mice):
            dm = density * r * np.exp(rng.normal(0, sd_mouse))
            for n in range(neurons):
                dn = dm * np.exp(rng.normal(0, sd_neuron))
                for s in range(SEGMENTS):
                    length = round(float(rng.uniform(10, 30)), 1); ds = dn * np.exp(rng.normal(0, sd_segment))
                    rows.append((g, f"{g[0].upper()}{m + 1}", n + 1, s + 1, length, int(rng.poisson(ds * length))))
    return rows
