#!/usr/bin/env python3
"""Code test only: copy the bundle's data with neuron subclass labels randomly permuted within each section
(destroys any real neuron-vessel association), so analyze.py can be exercised end-to-end before preregistration.
usage: make_synthetic.py BUNDLE_DIR OUT_DIR"""
import sys, pathlib, shutil, numpy as np
src = pathlib.Path(sys.argv[1]) / "data"; out = pathlib.Path(sys.argv[2]); (out / "data").mkdir(parents=True, exist_ok=True)
rng = np.random.default_rng(1)
for f in src.iterdir():
    if f.name.startswith("cells_"):
        z = dict(np.load(f)); m = np.where(z["kind"] == 1)[0]
        for s in np.unique(z["sec"][m]):
            ix = m[z["sec"][m] == s]; p = rng.permutation(len(ix))
            for k in ("subclass", "cls", "log10_counts"):
                if k in z: z[k][ix] = z[k][ix][p]
        np.savez_compressed(out / "data" / f.name, **z)
    else:
        shutil.copy(f, out / "data" / f.name)
