# Data-generating model shared by make_data.py and simulation.py. Python 3.13, NumPy.
# Histopathology: a blinded observer scores inflammation 0-4 in 9 fields of one section per mouse. Each mouse has an
# underlying inflammation level; fields vary around it, and the score is that field's level cut into 5 ordered grades.
import numpy as np
MICE, FIELDS = 8, 9
CUTS = np.array([-0.5, 0.5, 1.5, 2.5])                                 # boundaries between grades 0|1|2|3|4

def study(rng, shift=0.0, base=1.2, sd_mouse=1.0, sd_field=0.8):
    rows = []
    for g, s in (("control", 0.0), ("treated", shift)):
        for m in range(MICE):
            level = base + s + rng.normal(0, sd_mouse)
            for f, z in enumerate(level + rng.normal(0, sd_field, FIELDS)):
                rows.append((g, f"{g[0].upper()}{m + 1}", f + 1, int(np.searchsorted(CUTS, z))))
    return rows
