# Data-generating model shared by make_data.py and simulation.py. Python 3.13, NumPy.
# Sholl analysis: intersections counted at radii 10-200 um (10 um steps) for 8 traced neurons per mouse, 6 mice per
# genotype. Each neuron's profile rises to a peak (Nm intersections at radius rc) and then falls; mice differ in
# overall branching, neurons differ within a mouse, and each count is Poisson around the neuron's profile.
import numpy as np
RADII = np.arange(10, 201, 10); NEURONS, MICE = 8, 6

def profile(nm, rc, k=2.0):
    x = RADII / rc; return nm * x ** k * np.exp(k * (1 - x))

def study(rng, ko_ratio=1.0, nm=8.0, rc=60.0, sd_mouse=0.15, sd_neuron=0.25, sd_rc=0.10):
    rows = []
    for g, ratio in (("wild-type", 1.0), ("knockout", ko_ratio)):
        for m in range(MICE):
            nm_m = nm * ratio * np.exp(rng.normal(0, sd_mouse))
            for n in range(NEURONS):
                lam = profile(nm_m * np.exp(rng.normal(0, sd_neuron)), rc * np.exp(rng.normal(0, sd_rc)))
                rows += [(g, f"{g[0].upper()}{m + 1}", n + 1, r, c) for r, c in zip(RADII, rng.poisson(lam))]
    return rows
