diff --git a/benchmarks/uipsf/real/m2_pairs/coverslip_fit.py b/benchmarks/uipsf/real/m2_pairs/coverslip_fit.py new file mode 100644 index 00000000..2212d625 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/coverslip_fit.py @@ -0,0 +1,72 @@ +"""Control: fluorophores at known heights in the sample (AB's model propagated, n_med 1.345, focus 607 nm, no tilt) +localised with the AB coverslip calibration's spline, as a user would (Spline 3D, best of 5 starts). + + python coverslip_fit.py OUTDIR + +The spline describes a molecule on the glass against defocus; the fluorophores sit 0-1200 nm deep, imaged with +the focus 607 nm into the sample. Prints per height the median fitted z, its spread, the x and y error, and the +slope and the rms about a straight line over 0-1000 nm: what ignoring the depth costs in linearity. +""" +import os +import sys + +import numpy as np +import torch + +HEIGHTS = np.arange(0.0, 1201.0, 100.0) +REP, PHOTONS, BG = 40, 4570.0, 98.0 + + +def main(): + out = sys.argv[1] + from smappy.calibrate.pupil import _best_of, load_start + from smappy.io.calibration import load_spline_calibration + from smappy.psf import SplinePSF + + from uipsf.simulate import parameters, simulate, template + + t = load_start(os.path.join(out, "insitu_all_n1345_tilt_s315_ab_n1345_3dcal.h5")) + tm = t.model + shared = {k: torch.as_tensor(v).detach().clone() for k, v in t.shared.items()} + shared["geometry.tilt"] = torch.zeros_like(shared["geometry.tilt"]) + rng = np.random.default_rng(0) + E = len(HEIGHTS) * REP + z_gt = np.repeat(HEIGHTS, REP) + px, py = tm.pixel_size_nm + xy = rng.uniform(-0.5, 0.5, (E, 2)) * np.array([px, py]) + cal = load_spline_calibration(os.path.join(out, "ab_n1345_3dcal.h5")) + box = min(int(cal.coeff.shape[-1]) - 3, 15) | 1 + roi = (box, box) + b0 = template(E, torch.zeros(1, dtype=torch.float64), roi, dtype=torch.float32) + values = dict(shared) + values.update({"emitter.xyz": torch.tensor(np.c_[xy, z_gt], dtype=torch.float64), + "emitter.photons": torch.full((E,), PHOTONS), "emitter.background": torch.full((E,), BG)}) + batch = simulate(tm, parameters(tm, b0, values), b0, seed=1) + full = batch.data.cpu().numpy().reshape(E, *batch.data.shape[-2:]) + c0 = (full.shape[-1] - box) // 2 + rois = np.ascontiguousarray(full[:, c0:c0 + box, c0:c0 + box], np.float32) + best = _best_of(lambda z: SplinePSF(cal, z_start_nm=z).fit(rois, iterations=75), + cal.z_index_to_nm(np.linspace(1, cal.shape[0] - 2, 5))) + z = cal.z_index_to_nm(best.theta[:, 4]) + h = box // 2 + x_nm = (best.theta[:, 0] - h) * px + y_nm = (best.theta[:, 1] - h) * py + print(f"spline z range {cal.z_index_to_nm(0):.0f} .. {cal.z_index_to_nm(cal.shape[0] - 1):.0f} nm, box {box} px") + print(" z_gt z_fit median sd x err y err") + med = [] + for hh in HEIGHTS: + k = z_gt == hh + m = float(np.median(z[k])) + med.append(m) + mad = 1.4826 * np.median(np.abs(z[k] - m)) + ex, ey = np.median(x_nm[k] - xy[k, 0]), np.median(y_nm[k] - xy[k, 1]) + print(f" {hh:5.0f} {m:9.1f} {mad:5.1f} {ex:6.1f} {ey:6.1f}") + med = np.array(med) + inner = HEIGHTS <= 1000 + a, b = np.polyfit(HEIGHTS[inner], med[inner], 1) + r = med[inner] - np.polyval([a, b], HEIGHTS[inner]) + print(f"slope {a:.3f} (z_fit per nm of height), rms about the line {np.sqrt((r ** 2).mean()):.1f} nm") + + +if __name__ == "__main__": + main() diff --git a/benchmarks/uipsf/real/m2_pairs/cross_score.py b/benchmarks/uipsf/real/m2_pairs/cross_score.py new file mode 100644 index 00000000..11e85ae4 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/cross_score.py @@ -0,0 +1,179 @@ +"""In situ against molecule stacks on M2 (12 November 2026): each model scores the other's held-out molecules. + + python cross_score.py OUTDIR STACK_MODEL INSITU_FOR_STACK MODEL [MODEL ...] [--json FILE] + +Two held-out sets, neither seen by any model's learning: + +* **stack**: the AB coverslip sweep's molecules that pass the selection (significance 5, the runs' setting) + but were not drawn into the 4000 learnt from (`molecule_rois`'s draw is seeded, so the same split as the + runs'). Every model scores them in the stack's geometry (`CoverslipStackGeometry`, STACK_MODEL's): its + pupil phase, γ and σ held, the geometry -- each sweep's focus, the focal plane's slope, the molecules' + height -- learnt again on 600 of the drawn molecules (the same 600 for every model), then the held-out + molecules localised with x, y, photons and background free. So a model is not charged for a focus offset + that only belongs to the other geometry, only for its PSF's shape. +* **in situ**: the nucleus movie's molecules in the *held out* and *not drawn* states (`movie_rois`'s + defaults, deterministic). An in situ model scores them with its own focus; a stack model through + INSITU_FOR_STACK, the in situ run that held every aberration of it and learnt only the focus (and σ). Each + molecule localised with x, y, z, photons and background free from five heights, the best kept. + +Each MODEL is a saved `_3dcal.h5` in OUTDIR; a stack model's name is STACK_MODEL itself. Reported: ½ Σ +deviance per molecule on each set (lower is better; a difference is a log-likelihood ratio, nats per +molecule), relative to the first MODEL. +""" +import argparse +import glob +import json +import os + +import numpy as np +import torch + +ROOT = os.environ.get("M2_DATA", os.path.expanduser("~/Library/Mobile Documents/com~apple~CloudDocs/Vienna/Data/" + "smappy test/261112_new")) +STACK = "261112_MR_Intercalib2_AB_50ms_coverslip/*/*.ome.tif" +MOVIE = "261112_MR_Intercalib2_BGAAF647_50ms_30i_nucleus_1/*_MMStack_Pos0.ome.tif" +STARTS_NM = (-200.0, 200.0, 600.0, 1000.0, 1400.0) +GEOMETRY_MOLECULES = 600 + + +def phase_by_noll(m) -> dict: + """{Noll index: rad} of a saved model: its learnt modes and the ones it held (in situ's *hold*).""" + pupil = m.model.channels[0].psf.pupil + out = {} + held = getattr(pupil, "held_phase", None) + if isinstance(held, dict): + out.update({int(j): float(v) for j, v in held.items()}) + values = torch.as_tensor(m.shared.get("pupil.phase", torch.zeros(0))).reshape(-1) + out.update({int(j): float(v) for j, v in zip(pupil.phase_modes, values, strict=False)}) + return out + + +def gamma_of(m) -> float: + if "pupil.gamma" in m.shared: + return float(torch.as_tensor(m.shared["pupil.gamma"])) + return float(m.model.channels[0].psf.pupil.held_gamma) + + +def half_deviance(model, noise, fit, problem) -> np.ndarray: + from uipsf.solve import Problem + dev = Problem(model, noise, problem.batch).deviance(fit.params) + return 0.5 * dev.reshape(dev.shape[0], -1).sum(1).double().cpu().numpy() + + +def stack_scores(out, stack_name, names): + from smappy.calibrate.molecule_stack import MoleculeStackSettings, molecule_rois + from smappy.calibrate.pupil import load_start + + from uipsf.params import Params + from uipsf.solve import LevenbergMarquardt, Problem + from uipsf.workflows.scoring import localise + + rois = molecule_rois(sorted(glob.glob(os.path.join(ROOT, STACK))), + MoleculeStackSettings(molecules=4000, significance=5.0, height_nm=None)) + drawn, held = rois.ids("used"), rois.ids("not drawn") + rng = np.random.default_rng(0) + geo_ids = np.sort(rng.choice(drawn, min(GEOMETRY_MOLECULES, len(drawn)), replace=False)) + geo_batch, noise = rois.batch(ids=geo_ids) + held_batch, _ = rois.batch(ids=held) + print(f"stack: {len(drawn)} drawn, {len(held)} held out; geometry from {len(geo_ids)}", flush=True) + template = load_start(os.path.join(out, f"{stack_name}_3dcal.h5")) + model = template.model + modes = list(model.channels[0].psf.pupil.phase_modes) + result = {} + for name in names: + m = template if name == stack_name else load_start(os.path.join(out, f"{name}_3dcal.h5")) + ph = phase_by_noll(m) + shared = {k: torch.as_tensor(v).detach().clone() for k, v in template.shared.items()} + shared["pupil.phase"] = torch.tensor([ph.get(j, 0.0) for j in modes], dtype=shared["pupil.phase"].dtype) + shared["pupil.gamma"] = torch.tensor(gamma_of(m), dtype=torch.float64) + shared["psf.sigma"] = torch.as_tensor(m.shared["psf.sigma"]).reshape(-1)[:1].clone() + # the geometry learnt again with this pupil held: the emitters first, then everything but the PSF + fit0, _ = localise(model, shared, geo_batch, noise) + values = dict(shared) + values.update({k: v.detach() for k, v in fit0.params.physical().items() if k.startswith("emitter.")}) + specs = model.specs(geo_batch) + p = Params(specs, geo_batch.n_emitters, dtype=geo_batch.data.dtype, device=geo_batch.data.device, + values=values) + p = p.fix(*[s.name for s in specs if s.scope == "shared" and not s.name.startswith("geometry.")]) + fit = LevenbergMarquardt(max_iter=60).solve(Problem(model, noise, geo_batch), p) + learnt = {k: v.detach() for k, v in fit.params.physical().items() if k.startswith("geometry.")} + shared.update(learnt) + hfit, hproblem = localise(model, shared, held_batch, noise) + e = half_deviance(model, noise, hfit, hproblem) + result[name] = e + print(f" {name:44s} stack held-out: {e.mean():9.2f} per molecule; height " + f"{float(learnt['geometry.height']):.0f} nm, plane {learnt['geometry.plane'].tolist()}", flush=True) + return result, len(held) + + +def insitu_scores(out, stack_name, insitu_for_stack, names): + from smappy.calibrate.insitu_run import movie_rois + from smappy.calibrate.pupil import load_start + + from uipsf.workflows.scoring import localise + + rois = movie_rois(sorted(glob.glob(os.path.join(ROOT, MOVIE)))) + ids = np.sort(np.concatenate([rois.ids("held out"), rois.ids("not drawn")])) + # the *held out* are drawn as the used are (every z bin's share); the *not drawn* are the bins' surplus, so + # they over-represent the heights where molecules are plentiful: reported apart as well + held_only = np.isin(ids, rois.ids("held out")) + batch, noise = rois.batch(ids=ids) + print(f"in situ: {len(ids)} held out ({len(rois.ids('held out'))} held out, " + f"{len(rois.ids('not drawn'))} not drawn)", flush=True) + result = {} + for name in names: + file = insitu_for_stack if name == stack_name else name + m = load_start(os.path.join(out, f"{file}_3dcal.h5")) + shared = {k: torch.as_tensor(v) for k, v in m.shared.items()} + best = np.full(batch.n_emitters, np.inf) + for z0 in STARTS_NM: + xyz = torch.zeros(batch.n_emitters, 3, dtype=torch.float64) + xyz[:, 2] = z0 + fit, problem = localise(m.model, shared, batch, noise, start={"emitter.xyz": xyz}) + best = np.minimum(best, half_deviance(m.model, noise, fit, problem)) + result[name] = best + result[name + "@held out"] = best[held_only] + result[name + "@not drawn"] = best[~held_only] + print(f" {name:44s} in situ held-out: {best.mean():9.2f} per molecule (scored as {file}); held out " + f"{best[held_only].mean():.2f}, not drawn {best[~held_only].mean():.2f}", flush=True) + return result, len(ids) + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("out") + ap.add_argument("stack") + ap.add_argument("insitu_for_stack") + ap.add_argument("names", nargs="+") + ap.add_argument("--json") + ap.add_argument("--only", choices=("stack", "insitu")) + a = ap.parse_args() + rows = {n: {} for n in a.names} + for kind, fn in (("stack", lambda: stack_scores(a.out, a.stack, a.names)), + ("insitu", lambda: insitu_scores(a.out, a.stack, a.insitu_for_stack, a.names))): + if a.only and a.only != kind: + continue + res, n = fn() + for key, e in res.items(): + name, _, part = key.partition("@") + col = kind + ("_" + part.replace(" ", "_") if part else "") + base = res[a.names[0] + ("@" + part if part else "")] + rows[name][f"{col}_molecules"] = len(e) + rows[name][f"{col}_per_molecule"] = float(e.mean()) + rows[name][f"{col}_vs_first_per_molecule"] = float((e - base).mean()) + rows[name][f"{col}_vs_first_median"] = float(np.median(e - base)) + print("\nnats per molecule against", a.names[0], "(negative: fits the held-out molecules better)") + for name, r in rows.items(): + nan = float("nan") + print(f" {name:44s} stack {r.get('stack_vs_first_per_molecule', nan):+8.3f} " + f"in situ {r.get('insitu_vs_first_per_molecule', nan):+8.3f} " + f"(held out {r.get('insitu_held_out_vs_first_per_molecule', nan):+.3f}, " + f"not drawn {r.get('insitu_not_drawn_vs_first_per_molecule', nan):+.3f})") + if a.json: + with open(a.json, "a") as f: + for name, r in rows.items(): + f.write(json.dumps(dict(model=name, **r)) + "\n") + + +if __name__ == "__main__": + main() diff --git a/benchmarks/uipsf/real/m2_pairs/fair_compare.py b/benchmarks/uipsf/real/m2_pairs/fair_compare.py new file mode 100644 index 00000000..ab2b17a9 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/fair_compare.py @@ -0,0 +1,100 @@ +"""Learnt molecule-stack models scored on ONE fixed set of molecules: a fair likelihood comparison. + + python fair_compare.py OUTDIR NAME [NAME ...] [--soft] [--set ab|nbx4] [--device cpu] + +Each learning run rejects molecules between its stages and rounds, so its own objective sums over its own +molecules and cannot be compared with another run's. Here the molecules are detected and selected once +(`molecule_rois`, every one that passes, no draw; ``--soft`` with soft_select.py's selection), and every saved +model ``OUTDIR/_3dcal.h5`` -- its forward model with the coverslip geometry and its learnt shared values +(pupil, σ, height, each sweep's focus, the focal plane's slope) -- localises them all again with x, y, photons and +background free (z is the stage's and the geometry's), `uipsf.workflows.scoring.localise`. The score of a model +is ½ Σ deviance over the molecules: lower is better, and differences are log-likelihood ratios (nats) between +models fitted to the same pixels. + +Reported per model: the total; the total over the molecules every model fits sensibly (each one's deviance per +pixel below 3 on every model, so that a few blow-ups cannot decide it); and per 200 nm of defocus, the sum and the +difference to the first model -- where in z one model is better. +""" +import argparse +import glob +import json +import os +import sys + +import numpy as np +import torch + +# the data are not in git: M2_DATA names the folder that holds 261112_new's sets +ROOT = os.environ.get("M2_DATA", os.path.expanduser("~/Library/Mobile Documents/com~apple~CloudDocs/Vienna/Data/" + "smappy test/261112_new")) +SETS = {"ab": "261112_MR_Intercalib2_AB_50ms_coverslip/*/*.ome.tif", + "nbx4": "261112_MR_Intercalib2_NBX4_50ms_coverslip/*/*.ome.tif"} + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("out") + ap.add_argument("names", nargs="+") + ap.add_argument("--set", default="ab") + ap.add_argument("--soft", action="store_true") + ap.add_argument("--device", default="cpu") + args = ap.parse_args() + os.environ.setdefault("UIPSF_DEVICE", args.device) + if args.soft: + sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + import soft_select # noqa: F401 + from smappy.calibrate.molecule_stack import MoleculeStackSettings, molecule_rois + from smappy.calibrate.pupil import load_start + + from uipsf.solve import Problem + from uipsf.workflows.scoring import localise + + files = sorted(glob.glob(os.path.join(ROOT, SETS[args.set]))) + rois = molecule_rois(files, MoleculeStackSettings(molecules=10 ** 6, significance=3.5 if args.soft else 5.0)) + used = rois.ids("used") + batch, noise = rois.batch() + d = np.asarray(rois.defocus_nm)[used] + print(f"{len(used)} molecules ({'soft' if args.soft else 'standard'} selection), {rois.sweeps} sweeps", flush=True) + + per = {} + for name in args.names: + learned = load_start(os.path.join(args.out, f"{name}_3dcal.h5")) + model = learned.model + shared = {k: torch.as_tensor(v) for k, v in learned.shared.items()} + n_focus = shared.get("geometry.focus") + if n_focus is not None and n_focus.numel() != rois.sweeps: + raise ValueError(f"{name}: {n_focus.numel()} sweep foci, the data have {rois.sweeps}") + fit, problem = localise(model, shared, batch, noise) + dev = Problem(model, noise, problem.batch).deviance(fit.params) # [E, C, K, Y, X] + pixels = dev[0].numel() + e = 0.5 * dev.reshape(dev.shape[0], -1).sum(1).double().numpy() # ½ deviance per molecule + per[name] = e + print(f"{name:24s} ½Σdeviance {e.sum():12.1f} per molecule {e.mean():7.2f} " + f"deviance/pixel {2 * e.mean() / pixels:5.3f} converged {fit.converged}", flush=True) + + names = args.names + E = np.stack([per[n] for n in names]) # [M, E] + pixels = rois.units.regions.shape[-1] ** 2 + sane = (2 * E / pixels < 3).all(0) + base = names[0] + print(f"\nagainst {base} (nats; negative: the model fits better); sane = {sane.sum()} of {len(sane)} molecules") + bins = np.arange(-1000, 1001, 200) + header = "".join(f"{b:+7d}" for b in bins) + print(f"{'model':24s} {'all':>10s} {'sane':>10s} | per 200 nm of defocus, sane: {header}") + rows = [] + for k, n in enumerate(names): + diff = E[k] - E[0] + by = [float(diff[sane & (np.abs(d - b) <= 100)].sum()) for b in bins] + print(f"{n:24s} {diff.sum():10.1f} {diff[sane].sum():10.1f} | " + "".join(f"{v:7.0f}" for v in by)) + rows.append(dict(model=n, total=float(E[k].sum()), vs_base=float(diff.sum()), + vs_base_sane=float(diff[sane].sum()), by_defocus=dict(zip(bins.tolist(), by, strict=False)))) + counts = [int((sane & (np.abs(d - b) <= 100)).sum()) for b in bins] + print(f"{'molecules per bin':24s} {'':21s} | " + "".join(f"{c:7d}" for c in counts)) + tag = "soft" if args.soft else "standard" + with open(os.path.join(args.out, f"fair_{args.set}_{tag}.json"), "w") as f: + json.dump(dict(molecules=len(used), sane=int(sane.sum()), selection=tag, rows=rows, bins=bins.tolist(), + counts=counts), f, indent=1) + + +if __name__ == "__main__": + main() diff --git a/benchmarks/uipsf/real/m2_pairs/fair_insitu.py b/benchmarks/uipsf/real/m2_pairs/fair_insitu.py new file mode 100644 index 00000000..39d060d8 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/fair_insitu.py @@ -0,0 +1,58 @@ +"""In situ models scored on ONE fixed set of molecules: each saved model localises the same molecules with x, y, +z (the height), photons and background free, from several heights, and keeps per molecule the best. + + python fair_insitu.py OUTDIR NAME [NAME ...] + +The detection is `movie_rois` with the default settings, deterministic, so every run used the same molecules; +the runs' own objectives are summed over each round's own set and cannot be compared. Heights start at +`STARTS_NM` because a single start falls to one side of the astigmatic ambiguity. +""" +import glob +import os +import sys + +import numpy as np +import torch + +# the data are not in git: M2_DATA names the folder that holds 261112_new's sets +ROOT = os.environ.get("M2_DATA", os.path.expanduser("~/Library/Mobile Documents/com~apple~CloudDocs/Vienna/Data/" + "smappy test/261112_new")) +MOVIE = "261112_MR_Intercalib2_BGAAF647_50ms_30i_nucleus_1/*_MMStack_Pos0.ome.tif" +STARTS_NM = (-200.0, 200.0, 600.0, 1000.0, 1400.0) + + +def main(): + out, names = sys.argv[1], sys.argv[2:] + from smappy.calibrate.insitu_run import movie_rois + from smappy.calibrate.pupil import load_start + + from uipsf.solve import Problem + from uipsf.workflows.scoring import localise + rois = movie_rois(sorted(glob.glob(os.path.join(ROOT, MOVIE)))) + batch, noise = rois.batch() + print(f"{batch.n_emitters} molecules", flush=True) + per, zs = {}, {} + for name in names: + m = load_start(os.path.join(out, f"{name}_3dcal.h5")) + model, shared = m.model, {k: torch.as_tensor(v) for k, v in m.shared.items()} + best = np.full(batch.n_emitters, np.inf) + z_best = np.full(batch.n_emitters, np.nan) + for z0 in STARTS_NM: + xyz = torch.zeros(batch.n_emitters, 3, dtype=torch.float64) + xyz[:, 2] = z0 + fit, problem = localise(model, shared, batch, noise, start={"emitter.xyz": xyz}) + dev = Problem(model, noise, problem.batch).deviance(fit.params) + e = 0.5 * dev.reshape(dev.shape[0], -1).sum(1).double().numpy() + z = fit.params.physical()["emitter.xyz"][:, 2].detach().cpu().double().numpy() + better = e < best + best[better], z_best[better] = e[better], z[better] + per[name], zs[name] = best, z_best + print(f"{name:20s} ½Σdeviance {best.sum():11.1f} heights p5/50/95 " + f"{np.percentile(z_best, [5, 50, 95]).round(0).tolist()}", flush=True) + base = names[0] + for n in names[1:]: + print(f"{n:20s} - {base}: {(per[n] - per[base]).sum():9.1f} nats") + + +if __name__ == "__main__": + main() diff --git a/benchmarks/uipsf/real/m2_pairs/insitu_control.py b/benchmarks/uipsf/real/m2_pairs/insitu_control.py new file mode 100644 index 00000000..2243f557 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/insitu_control.py @@ -0,0 +1,93 @@ +"""Control for in situ on M2's nucleus movie: a simulated movie with a known truth, learnt as the real one was. + + python insitu_control.py OUTDIR + +Truth: AB's model on the glass at n_med 1.345 (every aberration, γ, σ 31.5 nm) as the in situ run that held it +carries it (`insitu_all_n1345_tilt_s315_ab_n1345`), its tilt set to 0 and its focus kept (607 nm). The movie: +molecules 0-1000 nm above the glass, a tenth on it, the real movie's background and per-frame photons +(measured on its chosen molecules), 160 x 160 px, 4000 frames. Then `run_insitu` as for the real movie: started +from AB (n 1.345), γ and the phase above order 8 held, focus learnt, σ round and free. If in situ is sound +on this geometry it stays at the truth: the phase within its errors, no extra coma or spherical, the twin test +on the right sign. +""" +import glob +import json +import os +import sys + +import numpy as np +import torch + +# the data are not in git: M2_DATA names the folder that holds 261112_new's sets +ROOT = os.environ.get("M2_DATA", os.path.expanduser("~/Library/Mobile Documents/com~apple~CloudDocs/Vienna/Data/" + "smappy test/261112_new")) +MOVIE = "261112_MR_Intercalib2_BGAAF647_50ms_30i_nucleus_1/*_MMStack_Pos0.ome.tif" +WL = 690.0 + + +def main(): + out = sys.argv[1] + from smappy.calibrate.insitu import InSituSettings, insitu_rois + from smappy.calibrate.insitu_run import InSituModelSettings, movie_rois, run_insitu + from smappy.calibrate.pupil import ( + BeadSettings, + OpticsSettings, + PSFModelSettings, + RunSettings, + camera_for, + load_start, + ) + from smappy.simulate import BlinkingSettings + + from uipsf.movie import MovieSettings, simulate_movie + + real = sorted(glob.glob(os.path.join(ROOT, MOVIE))) + camera = camera_for(real[0]) + rr = movie_rois(real) + used = rr.ids("used") + g = rr.units.gauss + bg = float(np.nanmedian(np.asarray(g["background"])[used])) + ph = float(np.nanmedian(np.asarray(g["photons"])[used])) + print(f"real movie: background {bg:.1f} photons/px/frame, median photons per chosen molecule {ph:.0f}", + flush=True) + + truth_model = load_start(os.path.join(out, "insitu_all_n1345_tilt_s315_ab_n1345_3dcal.h5")) + model = truth_model.model + shared = {k: torch.as_tensor(v).detach().clone() for k, v in truth_model.shared.items()} + shared["geometry.tilt"] = torch.zeros_like(shared["geometry.tilt"]) + print("truth focus", float(shared["geometry.focus"]), "σ", shared["psf.sigma"].tolist(), flush=True) + movie = simulate_movie(model, shared, MovieSettings( + size_px=(160, 160), n_frames=4000, fluorophores=2500, heights_nm=(0.0, 1000.0), on_coverslip=0.1, + blinking=BlinkingSettings(photons=1.5 * ph, photons_std=0.75 * ph), background=bg, + read_noise_var=float(camera.readout_variance), seed=1)) + rois = insitu_rois(movie.frames, model.pixel_size_nm, InSituSettings(), + read_noise_var=float(camera.readout_variance), excess_noise=float(camera.excess_noise)) + rois.camera = camera + print("simulated:", rois.messages[-1] if rois.messages else len(rois.ids("used")), flush=True) + + optics = OpticsSettings(NA=1.43, wavelength_nm=WL, n_immersion=1.516, n_medium=1.345, + pixel_x_nm=127.0, pixel_y_nm=116.0) + res = run_insitu([], optics, BeadSettings(psf=PSFModelSettings(zernike_order=8)), InSituModelSettings(), + run=RunSettings(save_model=True, start_from=os.path.join(out, "ab_n1345_3dcal.h5")), + rois=rois, camera=camera, save_to=os.path.join(out, "insitu_control_3dcal.h5"), + progress=lambda *a: print(*a, flush=True)) + cal = res.cal + p = cal.result.params.physical() + pupil = cal.model.psf.pupil + learnt = {f"Z{int(j)}": round(float(v) * WL / (2 * np.pi), 1) + for j, v in zip(pupil.phase_modes, p["pupil.phase"].detach().cpu().reshape(-1), strict=False)} + ab = load_start(os.path.join(out, "ab_n1345_3dcal.h5")) + abp = ab.model.channels[0].psf.pupil + abv = torch.as_tensor(ab.shared["pupil.phase"]).cpu().reshape(-1) + truth = {f"Z{int(j)}": round(float(v) * WL / (2 * np.pi), 1) for j, v in zip(abp.phase_modes, abv, strict=False)} + row = dict(focus=float(p["geometry.focus"]), sigma=p["psf.sigma"].detach().cpu().tolist(), + messages=res.messages, used=int(len(rois.ids("used"))), + phase={k: (truth.get(k), learnt.get(k)) for k in + ["Z5", "Z6", "Z7", "Z8", "Z9", "Z10", "Z11", "Z12", "Z16", "Z17", "Z22", "Z37"]}) + print(json.dumps(row), flush=True) + with open(os.path.join(out, "insitu_control.json"), "w") as f: + json.dump(row, f, indent=1) + + +if __name__ == "__main__": + main() diff --git a/benchmarks/uipsf/real/m2_pairs/m2_new.py b/benchmarks/uipsf/real/m2_pairs/m2_new.py new file mode 100644 index 00000000..cece5dcf --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/m2_new.py @@ -0,0 +1,175 @@ +"""M2, 12 Nov 2026: beads vs molecules on the coverslip (NBX4, AB), minimal pupil model. + + python m2_new.py beads|nbx4|ab OUTDIR [--files i,j] +""" +import glob +import json +import math +import os +import sys +import time + +import numpy as np +import torch + +# the data are not in git: M2_DATA names the folder that holds 261112_new's sets +ROOT = os.environ.get("M2_DATA", os.path.expanduser("~/Library/Mobile Documents/com~apple~CloudDocs/Vienna/Data/" + "smappy test/261112_new")) +SETS = { + "beads": "261112_MR_Intercalib2_Beads_1_700/*/*.ome.tif", + "nbx4": "261112_MR_Intercalib2_NBX4_50ms_coverslip/*/*.ome.tif", + "ab": "261112_MR_Intercalib2_AB_50ms_coverslip/*/*.ome.tif", + "insitu": "261112_MR_Intercalib2_BGAAF647_50ms_30i_nucleus_1/*_MMStack_Pos0.ome.tif", +} +WAVELENGTH = float(os.environ.get("WL", 690.0)) +PIXEL = (127.0, 116.0) # iXon on M2's astigmatic path (docs/uipsf/microscopes.md) + + +def nm_of(pupil, values): + from uipsf.optics.zernike import noll_to_nm + return {f"Z{int(j)}{noll_to_nm(int(j))}": round(float(v) * WAVELENGTH / (2 * math.pi), 2) + for j, v in zip(pupil.phase_modes, values, strict=True)} + + +def main(): + which, out = sys.argv[1], sys.argv[2] + os.makedirs(out, exist_ok=True) + if torch.backends.mps.is_available(): + torch.mps.set_per_process_memory_fraction(0.6) + import functools + + import uipsf.workflows.calibrate as _c + _c.learn_beads = functools.partial(_c.learn_beads, chunk_size=int(os.environ.get("CHUNK", 16))) + from smappy.calibrate.pupil import BeadSettings, OpticsSettings, PSFModelSettings, RunSettings + if os.environ.get("GAMMA") is not None and os.environ.get("GAMMA") != "": + # γ held at a value (no setting holds it for a molecule stack): every pupil built holds it + import uipsf.model.build as build + _make = build.make_pupil + + def make_pupil(optics, spec, held=None, **kw): + held = held or build.Held() + if held.gamma is None: + held = build.Held(phase=held.phase, magnitude=held.magnitude, gamma=float(os.environ["GAMMA"]), + na=held.na, source="typed") + return _make(optics, spec, held, **kw) + build.make_pupil = make_pupil + if os.environ.get("NMED_RANGE"): + # the sample's index learnt within a range (a fixed, permeabilised cell in buffer: a little above water) + import uipsf.model.psf as psf_mod + from uipsf.params import Bounded, ParamSpec + lo_n, hi_n = (float(v) for v in os.environ["NMED_RANGE"].split(",")) + psf_mod.n_med_spec = lambda n_typed: ParamSpec("optics.n_med", (), init=float(n_typed), + transform=Bounded(lo_n, hi_n)) + if os.environ.get("SOFT"): + sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + import soft_select # noqa: F401 -- patches the selection + if os.environ.get("H_START"): + # the height's start (the molecule run drops a start model's geometry): put back where learning begins + import uipsf.workflows.molecule_stack as ms + _learn = ms.learn_molecule_stack + + def learn(model, batch, defocus_nm, noise=None, settings=None, start=None, **kw): + start = dict(start or {}) + start["geometry.height"] = torch.tensor(float(os.environ["H_START"])) + print("start:", {k: (v.reshape(-1)[:3].tolist() if hasattr(v, "reshape") else v) for k, v in start.items()}, + flush=True) + return _learn(model, batch, defocus_nm, noise, settings, start=start, **kw) + ms.learn_molecule_stack = learn + files = sorted(glob.glob(os.path.join(ROOT, SETS[which]))) + if "--files" in sys.argv: + keep = [int(i) for i in sys.argv[sys.argv.index("--files") + 1].split(",")] + files = [f for i, f in enumerate(files) if i + 1 in keep] + picked = "_" + sys.argv[sys.argv.index("--files") + 1].replace(",", "") if "--files" in sys.argv else "" + tag = which + os.environ.get("TAG", "") + picked + print(tag, [os.path.basename(f) for f in files], flush=True) + n_med = float(os.environ.get("NMED", 1.33)) + optics = OpticsSettings(NA=1.43, wavelength_nm=WAVELENGTH, n_immersion=1.516, n_medium=n_med, + pixel_x_nm=PIXEL[0], pixel_y_nm=PIXEL[1]) + env = os.environ.get + # minimal magnitude, round blur: the defaults + psf = PSFModelSettings(zernike_order=int(env("ORDER", 8)), learn_na=bool(env("LEARN_NA")), + learn_n_med=bool(env("LEARN_NMED")), blur="fixed" if env("BLUR_NM") else "round", + blur_nm=float(env("BLUR_NM", 20.0))) + model = BeadSettings(psf=psf, fit_tilt=bool(env("TILT"))) + save_to = os.path.join(out, f"{tag}_3dcal.h5") + t0 = time.perf_counter() + row = dict(set=tag, files=len(files), wavelength_nm=WAVELENGTH, pixel_nm=PIXEL) + if which == "beads": + from smappy.calibrate.pupil import fit_quality, run_calibration + model.bead_diameter_nm = 100.0 + model.drift = os.environ.get("DRIFT", "linear") + run = run_calibration(files, False, optics, model, run=RunSettings(save_model=True), save_to=save_to, + progress=lambda *a: print(*a, flush=True)) + cal = run.cal + q = fit_quality(run) + err = q["centred_error_nm"] + used = np.isin(q["bead_id"], np.asarray(cal.beads.used)) + z = q["nominal_z_nm"] + grid = np.arange(-1000, 1001, 100.0) + bend = [float(np.nanmedian(err[used & (np.abs(z - g) < 50)])) if np.any(used & (np.abs(z - g) < 50)) + else None for g in grid] + row.update(beads_used=len(cal.beads.used), beads_found=int(run.rois.batch.n_emitters) + if hasattr(run.rois.batch, "n_emitters") else None, + z_bend=dict(zip(grid.tolist(), bend, strict=False))) + elif which == "insitu": + from smappy.calibrate.insitu_run import InSituModelSettings, run_insitu + start = os.environ.get("START", "") + start_name = os.path.basename(start).split("_3dcal")[0] if start else "nostart" + tag = "insitu_" + env("HOLD", "start") + env("TAG", "") + "_" + start_name + save_to = os.path.join(out, f"{tag}_3dcal.h5") + row["set"] = tag + insitu = InSituModelSettings(hold=env("HOLD", "start"), focus_fit=env("FOCUS_FIT", "learnt")) + res = run_insitu(files, optics, model, insitu, + run=RunSettings(save_model=True, start_from=start), save_to=save_to, + progress=lambda *a: print(*a, flush=True)) + cal = res.cal + params = getattr(res.calibration, "parameters", {}) or {} + row["coverslip_tilt_deg"] = params.get("coverslip_tilt_deg") + row.update(focus_estimate_nm=res.focus_estimate, messages=res.messages + list(res.rois.messages), + molecules_used=int(len(res.rois.ids("used")))) + for k in ("geometry.focus", "pupil.gamma", "psf.n_med", "optics.n_med", "n_med"): + v = cal.result.params.physical().get(k) + if v is not None: + row[k] = np.round(v.detach().cpu().double().numpy().reshape(-1), 2).tolist() + else: + from smappy.calibrate.molecule_stack import MoleculeStackSettings + from smappy.calibrate.molecule_stack_run import run_molecule_stack + # HEIGHT unset: learnt (since 58f38c76 the setting's default holds 5 nm; these runs learnt it) + stack = MoleculeStackSettings(molecules=int(env("MOLECULES", 4000)), + illumination_px=float(env("RADIUS")) if env("RADIUS") else None, + significance=float(env("SIG", 5.0)), + height_nm=float(env("HEIGHT")) if env("HEIGHT") else None) + res = run_molecule_stack(files, optics, model, stack, + run=RunSettings(save_model=True, start_from=env("START", "")), + save_to=save_to, progress=lambda *a: print(*a, flush=True)) + cal = res.cal + ch = res.check + row.update(molecules_used=int(len(res.used())), height_nm=res.height_nm(), + height_crlb=(float(cal.result.std["geometry.height"]) if "geometry.height" in cal.result.std + else None), + bend_rms_600=ch.bend_rms(600.0), bend_rms_1000=ch.bend_rms(1000.0), scatter=float(ch.scatter), + z_bend=dict(zip(ch.grid_nm.tolist(), [None if not np.isfinite(b) else round(float(b), 1) + for b in ch.bend_nm], strict=False))) + try: + np.savez(os.path.join(out, f"{tag}_zcheck.npz"), dz=ch.dz_nm if hasattr(ch, "dz_nm") else ch[0], + grid=ch.grid_nm, bend=ch.bend_nm) + except Exception as e: # noqa: BLE001 + print("zcheck save:", e) + p, std = cal.result.params.physical(), cal.result.std + pupil = cal.model.psf.pupil + row["phase_nm"] = nm_of(pupil, p["pupil.phase"].detach().cpu().reshape(-1)[:len(pupil.phase_modes)]) + for k in ("pupil.gamma", "pupil.na", "psf.sigma"): + if k in p: + row[k] = np.round(p[k].detach().cpu().double().numpy().reshape(-1), 4).tolist() + if k in std: + row[k + "_crlb"] = np.round(std[k].detach().cpu().double().numpy().reshape(-1), 4).tolist() + row["params"] = sorted(p.keys()) + row["minutes"] = round((time.perf_counter() - t0) / 60, 2) + row["saved"] = save_to + print(json.dumps(row, default=str), flush=True) + with open(os.path.join(out, "summary.jsonl"), "a") as f: + f.write(json.dumps(row, default=str) + "\n") + + +if __name__ == "__main__": + main() diff --git a/benchmarks/uipsf/real/m2_pairs/npc_rings.chain.yaml b/benchmarks/uipsf/real/m2_pairs/npc_rings.chain.yaml new file mode 100644 index 00000000..400c9210 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/npc_rings.chain.yaml @@ -0,0 +1,48 @@ +# M2 nucleus movie: Spline 3D with AB's coverslip calibration, pores found, each pore's z profile fitted with two +# Gaussians (the two rings), the region table written. model.focus is overridden per job. +schema: smappy-chain-v1 +description: Spline 3D with AB's calibration, NPC rings' separation in z per pore +steps: + - plugin: Localize/Spline 3D + label: fit + values: + model.calibration: OUTDIR/ab_n1345_3dcal.h5 + model.medium: buffer + model.focus: calibrated + - plugin: Analysis/Process/Layers + label: layers + values: + layers: + - grouped: true + start: empty + bounds: + - {field: xy_err_nm, hi: 25} + - {field: logl_rel, lo: -2} + remove: false + - plugin: Analysis/Drift/RCC + label: drift + values: {} + - plugin: Analysis/Regions/Segment regions + label: find the pores + values: + preset: NPC + method: circle + circle.shape: ring + circle.min_radius_nm: 55.0 + circle.max_radius_nm: 55.0 + circle.ring_width_nm: 15.0 + keep: n_ring >= 4 and 40 <= radius_nm <= 70 and far_p >= 0.05 + replace: true + - block: each pore + regions: rois + steps: + - plugin: Analysis/Measure/Line Profile + label: z profile + values: + axis: z + source: selection + model: two_gauss + - plugin: Analysis/Regions/Summarize/Export table + label: export + values: + path: pores.csv diff --git a/benchmarks/uipsf/real/m2_pairs/rings.batch.yaml b/benchmarks/uipsf/real/m2_pairs/rings.batch.yaml new file mode 100644 index 00000000..380cc244 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/rings.batch.yaml @@ -0,0 +1,18 @@ +# One batch per calibration variant: this is the "auto" one (AB's model redrawn at the focus). The others set +# fit.model.focus: calibrated, or fit.model.calibration: OUTDIR/_3dcal.h5 with focus calibrated, +# and export.path / output.folder to pores_.csv / out_. OUTDIR, NPCDIR, M2_DATA: replace. +schema: smappy-batch-v1 +name: npc rings, focus auto +chain: npc_rings.chain.yaml +overrides: + fit.model.focus: auto + export.path: NPCDIR/pores_auto.csv +inputs: + - file: "M2_DATA/261112_MR_Intercalib2_BGAAF647_50ms_30i_nucleus_1/261112_MR_Intercalib2_BGAF647_50ms_30i_nucleus_1_MMStack_Pos0.ome.tif" +output: + folder: NPCDIR/out_auto + locs: true + figures: png + fitted: output +preflight: proceed +rerun: skip_identical diff --git a/benchmarks/uipsf/real/m2_pairs/rings_vs_z.py b/benchmarks/uipsf/real/m2_pairs/rings_vs_z.py new file mode 100644 index 00000000..70e3ff6c --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/rings_vs_z.py @@ -0,0 +1,88 @@ +"""NPC ring separation against the pore's z, for the fits of the nucleus movie with AB's calibration. + + python rings_vs_z.py NPCDIR calibrated auto [--json FILE] + +Per variant: the pores (`pores_.csv`, Line Profile's two Gaussians in z per pore) and the fitted table +(`out_/.../*_proc.h5`, the chain's drift-corrected table); each pore's z the median z of the localizations +within 100 nm of its centre. Pores kept: the +two-Gaussian fit determined (distance error < 10 nm), 20-120 nm apart, at least 40 localizations. Prints the +median separation per 150 nm of z and its slope against z; draws `rings_vs_z.png`. +""" +import glob +import json +import os +import sys + +import matplotlib +import numpy as np + +matplotlib.use("Agg") +import matplotlib.pyplot as plt # noqa: E402 + + +def pore_z(locs_path, xs, ys, r=100.0): + from smappy.io.formats import load + locs, _ = load(locs_path) + x, y, z = (np.asarray(locs[c], float) for c in ("x_nm", "y_nm", "z_nm")) + from scipy.spatial import cKDTree + tree = cKDTree(np.c_[x, y]) + return np.array([np.median(z[idx]) if len(idx) else np.nan + for idx in tree.query_ball_point(np.c_[xs, ys], r)]) + + +def main(): + args = sys.argv[1:] + out_json = None + if "--json" in args: + k = args.index("--json") + out_json = args[k + 1] + del args[k:k + 2] + d, variants = args[0], args[1:] + rows = [] + fig, axes = plt.subplots(1, 2, figsize=(12, 4.5)) + for v in variants: + import csv + rows_v = list(csv.DictReader(open(os.path.join(d, f"pores_{v}.csv")))) + f = lambda k, rows_v=rows_v: np.array([float(r[k]) if r.get(k) not in (None, "") else np.nan # noqa: E731 + for r in rows_v]) + dist, err, n = f("two_gauss_distance_nm"), f("two_gauss_distance_err_nm"), f("n_locs") + locs = glob.glob(os.path.join(d, f"out_{v}", "*", "*_proc.h5"))[0] + z = pore_z(locs, f("x_nm"), f("y_nm")) + ok = np.isfinite(dist) & (err < 10) & (dist > 20) & (dist < 120) & (n >= 40) & np.isfinite(z) + a, b = np.polyfit(z[ok], dist[ok], 1) + print(f"\n{v}: {ok.sum()} of {len(rows_v)} pores; separation median {np.median(dist[ok]):.1f} nm " + f"(robust sd {1.4826 * np.median(np.abs(dist[ok] - np.median(dist[ok]))):.1f}); " + f"slope {a * 1000:.1f} nm per µm of z; z of the pores {np.percentile(z[ok], [5, 50, 95]).round(0)}") + edges = np.arange(np.floor(np.nanmin(z[ok]) / 150) * 150, np.nanmax(z[ok]) + 150, 150) + centres, meds = [], [] + for lo in edges[:-1]: + k = ok & (z >= lo) & (z < lo + 150) + if k.sum() >= 5: + centres.append(lo + 75) + meds.append(np.median(dist[k])) + print(f" z {lo:6.0f}..{lo + 150:6.0f}: {k.sum():4d} pores, separation median {meds[-1]:5.1f} nm") + rows.append(dict(variant=v, pores=int(ok.sum()), of=len(rows_v), + separation_median_nm=float(np.median(dist[ok])), + separation_robust_sd_nm=float(1.4826 * np.median(np.abs(dist[ok] - np.median(dist[ok])))), + slope_nm_per_um=float(a * 1000), + z_p5_p50_p95_nm=np.percentile(z[ok], [5, 50, 95]).round(0).tolist(), + per_150nm=[dict(z_centre_nm=c, median_nm=float(m)) + for c, m in zip(centres, meds, strict=True)])) + axes[0].scatter(z[ok], dist[ok], s=6, alpha=0.4, label=v) + axes[1].plot(centres, meds, "o-", label=v) + for a in axes: + a.set(xlabel="pore z (nm): calibrated = defocus, auto = height above the coverslip", + ylabel="ring separation (nm)") + a.legend() + axes[0].set_title("each pore") + axes[1].set_title("median per 150 nm of z") + fig.tight_layout() + fig.savefig(os.path.join(d, "rings_vs_z.png"), dpi=110) + if out_json: + with open(out_json, "w") as f: + for r in rows: + f.write(json.dumps(r) + "\n") + + +if __name__ == "__main__": + main() diff --git a/benchmarks/uipsf/real/m2_pairs/soft_select.py b/benchmarks/uipsf/real/m2_pairs/soft_select.py new file mode 100644 index 00000000..4b192da4 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/soft_select.py @@ -0,0 +1,52 @@ +"""Softer out-of-focus selection for a molecule stack, as a patch of smappy.calibrate.molecule_stack (a test). + +Imported by m2_new.py when SOFT=1: significance 3.5; off centre within max(1.5 px, the curve's width); shape +tolerance 0.3 within ±400 nm, 0.6 beyond; brightness one window for all z from the in-focus spots (|d| < 300 nm), +from half their median to their median + 3 robust SDs (log), on photons corrected for the elliptical Gaussian's +bias on a defocused PSF (BIAS, measured on the AB model in a 21 px region). +""" +import numpy as np +import smappy.calibrate.molecule_stack as M + +BIAS_D = np.arange(-800, 801, 200.0) # measured: Gaussian / true photons on the AB model, 21 px +BIAS = np.array([0.96, 0.84, 0.76, 0.76, 0.73, 0.69, 0.64, 0.55, 0.58]) + + +def select(s, settings, roi_px): + h = roi_px // 2 + g = s["gauss"] + n = len(s["frame"]) + d = s["d_nm"] + state = ["candidate"] * n + + def out(mask, reason): + for i in np.flatnonzero(mask): + if state[i] == "candidate": + state[i] = "rejected: " + reason + fitted = np.isfinite(g["photons"]) & np.isfinite(g["sigma_x_pix"]) & np.isfinite(g["sigma_y_pix"]) + out(~fitted, "fit failed") + import os + width = np.hypot(s["sx_curve"], s["sy_curve"]) / np.sqrt(2) + lim = np.maximum(M.MAX_OFF_CENTRE_PX, float(os.environ.get("OFF_SCALE", 1.0)) * width) + tol = np.where(np.abs(d) <= 400, settings.width_tol, 2 * settings.width_tol) + with np.errstate(invalid="ignore"): + out(~(np.hypot(g["x_roi"] - h, g["y_roi"] - h) < lim), "off centre") + out(~((np.abs(np.log(g["sigma_x_pix"] / s["sx_curve"])) < tol) + & (np.abs(np.log(g["sigma_y_pix"] / s["sy_curve"])) < tol)), "shape") + rejected, masks = M.neighbours(s, roi_px, settings.neighbour_fraction) + out(rejected | ((~masks).mean((1, 2)) > settings.max_masked), "neighbour") + alive = np.array([st == "candidate" for st in state]) + with np.errstate(divide="ignore", invalid="ignore"): + logn = np.log(np.where(alive, g["photons"] / np.interp(d, BIAS_D, BIAS), np.nan)) + ref = alive & (np.abs(d) < 300) & np.isfinite(logn) + if ref.sum() >= 20: + med = np.median(logn[ref]) + mad = 1.4826 * np.median(np.abs(logn[ref] - med)) + bright = (logn >= med + np.log(0.5)) & (logn <= med + 3 * mad) + else: + bright = alive + out(alive & ~bright, "brightness") + return ["not drawn" if st == "candidate" else st for st in state], masks + + +M.select = select diff --git a/benchmarks/uipsf/real/m2_pairs/zfit_vs_zgt.py b/benchmarks/uipsf/real/m2_pairs/zfit_vs_zgt.py new file mode 100644 index 00000000..cc8cd9b1 --- /dev/null +++ b/benchmarks/uipsf/real/m2_pairs/zfit_vs_zgt.py @@ -0,0 +1,99 @@ +"""Spots drawn from AB's model propagated to known heights, localised with each in situ model: z_fit vs z_gt. + + python zfit_vs_zgt.py OUTDIR MODEL [MODEL ...] + +Truth: `insitu_all_n1345_tilt_s315_ab_n1345` (AB's every aberration, γ, σ 31.5 nm, n_med 1.345, focus 607 nm) +with its tilt set to 0 -- a molecule at height h in the sample, drawn by the in situ model's own physics. At +each height 0..1200 nm, `REP` spots at random sub-pixel positions, 4570 photons, background 98 / px (the real +movie's medians), Poisson noise. Each model localises them (x, y, z, photons, background free) from `STARTS_NM` +and keeps the best likelihood per spot. Prints per height the median z_fit - z_gt and its spread, the median x +and y error, and writes a figure `zfit_vs_zgt.png`. +""" +import os +import sys + +import matplotlib +import numpy as np +import torch + +matplotlib.use("Agg") +import matplotlib.pyplot as plt # noqa: E402 + +HEIGHTS = np.arange(0.0, 1201.0, 100.0) +REP, PHOTONS, BG = 40, 4570.0, 98.0 +STARTS_NM = (0.0, 300.0, 600.0, 900.0, 1200.0) + + +def main(): + out, names = sys.argv[1], sys.argv[2:] + from smappy.calibrate.pupil import load_start + + from uipsf.noise import ShiftedPoisson + from uipsf.simulate import parameters, simulate, template + from uipsf.solve import Problem + from uipsf.workflows.scoring import localise + + t = load_start(os.path.join(out, "insitu_all_n1345_tilt_s315_ab_n1345_3dcal.h5")) + tm = t.model + shared = {k: torch.as_tensor(v).detach().clone() for k, v in t.shared.items()} + shared["geometry.tilt"] = torch.zeros_like(shared["geometry.tilt"]) + rng = np.random.default_rng(0) + E = len(HEIGHTS) * REP + z_gt = np.repeat(HEIGHTS, REP) + px, py = tm.pixel_size_nm + xy = rng.uniform(-0.5, 0.5, (E, 2)) * np.array([px, py]) + roi = tuple(int(s) for s in tm.channels[0].psf.roi) if hasattr(tm.channels[0].psf, "roi") else (17, 17) + b0 = template(E, torch.zeros(1, dtype=torch.float64), roi, dtype=torch.float32) + values = dict(shared) + values.update({"emitter.xyz": torch.tensor(np.c_[xy, z_gt], dtype=torch.float64), + "emitter.photons": torch.full((E,), PHOTONS), "emitter.background": torch.full((E,), BG)}) + truth = parameters(tm, b0, values) + batch = simulate(tm, truth, b0, seed=1) + noise = ShiftedPoisson() + results = {} + for name in names: + m = load_start(os.path.join(out, f"{name}_3dcal.h5")) + sh = {k: torch.as_tensor(v) for k, v in m.shared.items()} + best = np.full(E, np.inf) + found = np.full((E, 3), np.nan) + for z0 in STARTS_NM: + start = torch.tensor(np.c_[xy * 0, np.full(E, z0)], dtype=torch.float64) + fit, problem = localise(m.model, sh, batch, noise, start={"emitter.xyz": start}) + dev = Problem(m.model, noise, problem.batch).deviance(fit.params) + e = 0.5 * dev.reshape(E, -1).sum(1).double().numpy() + f = fit.params.physical()["emitter.xyz"].detach().cpu().double().numpy() + better = e < best + best[better], found[better] = e[better], f[better] + results[name] = (found, best) + dz = found[:, 2] - z_gt + dx, dy = found[:, 0] - xy[:, 0], found[:, 1] - xy[:, 1] + print(f"\n{name} (½Σdeviance {best.sum():.0f}, deviance/pixel {2 * best.mean() / np.prod(roi):.3f})") + print(" z_gt z_fit-z_gt median robust sd x err y err (nm, medians)") + for h in HEIGHTS: + k = z_gt == h + mad = 1.4826 * np.median(np.abs(dz[k] - np.median(dz[k]))) + ex, ey = np.median(dx[k]), np.median(dy[k]) + print(f" {h:5.0f} {np.median(dz[k]):8.1f} {mad:6.1f} {ex:6.1f} {ey:6.1f}") + fig, axes = plt.subplots(1, 3, figsize=(15, 4.5)) + for name, (found, _) in results.items(): + med = [np.median(found[z_gt == h, 2] - h) for h in HEIGHTS] + axes[0].plot(HEIGHTS, [np.median(found[z_gt == h, 2]) for h in HEIGHTS], "o-", label=name[:40]) + axes[1].plot(HEIGHTS, med, "o-", label=name[:40]) + axes[2].plot(HEIGHTS, [np.median(found[z_gt == h, 0] - xy[z_gt == h, 0]) for h in HEIGHTS], "o-", + label=name[:40] + " x") + axes[2].plot(HEIGHTS, [np.median(found[z_gt == h, 1] - xy[z_gt == h, 1]) for h in HEIGHTS], "s--", + label=name[:40] + " y") + axes[0].plot(HEIGHTS, HEIGHTS, "k:", lw=1) + axes[0].set(xlabel="z ground truth (nm)", ylabel="z fit (nm)", title="z fit vs z gt (medians)") + axes[1].axhline(0, color="k", lw=0.5) + axes[1].set(xlabel="z ground truth (nm)", ylabel="z fit - z gt (nm)", title="z error") + axes[2].axhline(0, color="k", lw=0.5) + axes[2].set(xlabel="z ground truth (nm)", ylabel="xy error (nm)", title="x, y error") + for a in axes: + a.legend(fontsize=6) + fig.tight_layout() + fig.savefig(os.path.join(out, "zfit_vs_zgt.png"), dpi=110) + + +if __name__ == "__main__": + main() diff --git a/benchmarks/uipsf/results/m2_pairs_cross.jsonl b/benchmarks/uipsf/results/m2_pairs_cross.jsonl new file mode 100644 index 00000000..09d1eeb4 --- /dev/null +++ b/benchmarks/uipsf/results/m2_pairs_cross.jsonl @@ -0,0 +1,6 @@ +{"model": "ab_n1345", "stack_molecules": 553, "stack_per_molecule": 229.42928646701586, "stack_vs_first_per_molecule": 0.0, "stack_vs_first_median": 0.0, "insitu_molecules": 4328, "insitu_per_molecule": 289.21257501344803, "insitu_vs_first_per_molecule": 0.0, "insitu_vs_first_median": 0.0, "insitu_held_out_molecules": 223, "insitu_held_out_per_molecule": 302.4556099245901, "insitu_held_out_vs_first_per_molecule": 0.0, "insitu_held_out_vs_first_median": 0.0, "insitu_not_drawn_molecules": 4105, "insitu_not_drawn_per_molecule": 288.49316044945664, "insitu_not_drawn_vs_first_per_molecule": 0.0, "insitu_not_drawn_vs_first_median": 0.0, "run": "pupils"} +{"model": "insitu_start_edge_n1345_ab_n1345", "stack_molecules": 553, "stack_per_molecule": 233.94217062427597, "stack_vs_first_per_molecule": 4.512884157260116, "stack_vs_first_median": 1.3326416015625, "insitu_molecules": 4328, "insitu_per_molecule": 289.46703740893804, "insitu_vs_first_per_molecule": 0.25446239548998706, "insitu_vs_first_median": -0.477020263671875, "insitu_held_out_molecules": 223, "insitu_held_out_per_molecule": 300.7039509589362, "insitu_held_out_vs_first_per_molecule": -1.7516589656539028, "insitu_held_out_vs_first_median": -1.9927978515625, "insitu_not_drawn_molecules": 4105, "insitu_not_drawn_per_molecule": 288.8566033719954, "insitu_not_drawn_vs_first_per_molecule": 0.36344292253872945, "insitu_not_drawn_vs_first_median": -0.42132568359375, "run": "pupils"} +{"model": "insitu_ab", "stack_molecules": 553, "stack_per_molecule": 237.8561994611247, "stack_vs_first_per_molecule": 8.426912994108838, "stack_vs_first_median": 2.65264892578125, "insitu_molecules": 4328, "insitu_per_molecule": 289.54637149874253, "insitu_vs_first_per_molecule": 0.33379648529447603, "insitu_vs_first_median": 0.02642822265625, "insitu_held_out_molecules": 223, "insitu_held_out_per_molecule": 299.70201624027817, "insitu_held_out_vs_first_per_molecule": -2.7535936843119395, "insitu_held_out_vs_first_median": -1.96209716796875, "insitu_not_drawn_molecules": 4105, "insitu_not_drawn_per_molecule": 288.99467630328274, "insitu_not_drawn_vs_first_per_molecule": 0.5015158538260791, "insitu_not_drawn_vs_first_median": 0.0917205810546875, "run": "pupils"} +{"model": "ab_n1345", "insitu_molecules": 4328, "insitu_per_molecule": 289.21257501344803, "insitu_vs_first_per_molecule": 0.0, "insitu_vs_first_median": 0.0, "insitu_held_out_molecules": 223, "insitu_held_out_per_molecule": 302.4556099245901, "insitu_held_out_vs_first_per_molecule": 0.0, "insitu_held_out_vs_first_median": 0.0, "insitu_not_drawn_molecules": 4105, "insitu_not_drawn_per_molecule": 288.49316044945664, "insitu_not_drawn_vs_first_per_molecule": 0.0, "insitu_not_drawn_vs_first_median": 0.0, "run": "tilted, in situ set only"} +{"model": "insitu_start_edge_n1345_tilt_s315_ab_n1345", "insitu_molecules": 4328, "insitu_per_molecule": 291.1579490915464, "insitu_vs_first_per_molecule": 1.9453740780983746, "insitu_vs_first_median": 1.2657928466796875, "insitu_held_out_molecules": 223, "insitu_held_out_per_molecule": 301.2095277384258, "insitu_held_out_vs_first_per_molecule": -1.2460821861643427, "insitu_held_out_vs_first_median": -0.9002685546875, "insitu_not_drawn_molecules": 4105, "insitu_not_drawn_per_molecule": 290.6119071821057, "insitu_not_drawn_vs_first_per_molecule": 2.1187467326490657, "insitu_not_drawn_vs_first_median": 1.33172607421875, "run": "tilted, in situ set only"} +{"model": "insitu_all_n1345_tilt_s315_ab_n1345", "insitu_molecules": 4328, "insitu_per_molecule": 290.6412511568193, "insitu_vs_first_per_molecule": 1.4286761433712436, "insitu_vs_first_median": 0.5044403076171875, "insitu_held_out_molecules": 223, "insitu_held_out_per_molecule": 302.2358502443596, "insitu_held_out_vs_first_per_molecule": -0.2197596802305213, "insitu_held_out_vs_first_median": -0.2793731689453125, "insitu_not_drawn_molecules": 4105, "insitu_not_drawn_per_molecule": 290.0113862124779, "insitu_not_drawn_vs_first_per_molecule": 1.51822576302123, "insitu_not_drawn_vs_first_median": 0.51824951171875, "run": "tilted, in situ set only"} diff --git a/benchmarks/uipsf/results/m2_pairs_npc_rings.jsonl b/benchmarks/uipsf/results/m2_pairs_npc_rings.jsonl new file mode 100644 index 00000000..9ebc4d02 --- /dev/null +++ b/benchmarks/uipsf/results/m2_pairs_npc_rings.jsonl @@ -0,0 +1,7 @@ +{"variant": "calibrated", "pores": 177, "of": 689, "separation_median_nm": 62.09558676243755, "separation_robust_sd_nm": 7.055450303336022, "slope_nm_per_um": 2.0556890581200244, "z_p5_p50_p95_nm": [-112.0, -10.0, 565.0], "per_150nm": [{"z_centre_nm": -75.0, "median_nm": 62.42891633190309}, {"z_centre_nm": 75.0, "median_nm": 59.57461622452587}, {"z_centre_nm": 375.0, "median_nm": 65.66607432595691}, {"z_centre_nm": 525.0, "median_nm": 64.9961096836654}]} +{"variant": "auto", "pores": 153, "of": 628, "separation_median_nm": 55.010342097690945, "separation_robust_sd_nm": 6.930454727749339, "slope_nm_per_um": 24.09335754656479, "z_p5_p50_p95_nm": [404.0, 490.0, 987.0], "per_150nm": [{"z_centre_nm": 375.0, "median_nm": 54.20591268900542}, {"z_centre_nm": 525.0, "median_nm": 54.30774932248658}, {"z_centre_nm": 675.0, "median_nm": 60.23003423041951}, {"z_centre_nm": 825.0, "median_nm": 53.934535433549215}, {"z_centre_nm": 975.0, "median_nm": 61.67618543486164}]} +{"variant": "insitu_ab", "pores": 178, "of": 633, "separation_median_nm": 59.229067785564155, "separation_robust_sd_nm": 9.870488920136903, "slope_nm_per_um": 15.320401330652617, "z_p5_p50_p95_nm": [-76.0, 31.0, 564.0], "per_150nm": [{"z_centre_nm": -75.0, "median_nm": 63.883472856612514}, {"z_centre_nm": 75.0, "median_nm": 55.64487525772819}, {"z_centre_nm": 375.0, "median_nm": 71.26257704140184}, {"z_centre_nm": 525.0, "median_nm": 69.65761288314359}]} +{"variant": "insitu_beads", "pores": 179, "of": 622, "separation_median_nm": 58.63650957968538, "separation_robust_sd_nm": 8.923713560082, "slope_nm_per_um": 17.08120532142528, "z_p5_p50_p95_nm": [-49.0, 44.0, 565.0], "per_150nm": [{"z_centre_nm": -75.0, "median_nm": 63.769442930447}, {"z_centre_nm": 75.0, "median_nm": 56.615655998239916}, {"z_centre_nm": 225.0, "median_nm": 56.45402576475998}, {"z_centre_nm": 375.0, "median_nm": 70.6422501922091}, {"z_centre_nm": 525.0, "median_nm": 68.75936216562553}]} +{"variant": "insitu_start_edge_n1345_ab_n1345", "pores": 183, "of": 613, "separation_median_nm": 56.61241014089187, "separation_robust_sd_nm": 8.438762672028078, "slope_nm_per_um": 18.98733734177418, "z_p5_p50_p95_nm": [-76.0, 32.0, 538.0], "per_150nm": [{"z_centre_nm": -75.0, "median_nm": 61.33122995902325}, {"z_centre_nm": 75.0, "median_nm": 54.2647580563106}, {"z_centre_nm": 375.0, "median_nm": 67.41242553556896}, {"z_centre_nm": 525.0, "median_nm": 63.532470167019234}]} +{"variant": "insitu_start_edge_n1345_tilt_s315_ab_n1345", "pores": 160, "of": 613, "separation_median_nm": 59.62292251455143, "separation_robust_sd_nm": 7.206359010787257, "slope_nm_per_um": 36.838950924417055, "z_p5_p50_p95_nm": [-50.0, 39.0, 567.0], "per_150nm": [{"z_centre_nm": -75.0, "median_nm": 57.76147754928097}, {"z_centre_nm": 75.0, "median_nm": 58.672187969808874}, {"z_centre_nm": 375.0, "median_nm": 76.96064740827264}, {"z_centre_nm": 525.0, "median_nm": 78.05260106734752}]} +{"variant": "insitu_all_n1345_tilt_s315_ab_n1345", "pores": 167, "of": 630, "separation_median_nm": 53.40901750268715, "separation_robust_sd_nm": 6.55438572083987, "slope_nm_per_um": 27.58283235441793, "z_p5_p50_p95_nm": [-38.0, 30.0, 528.0], "per_150nm": [{"z_centre_nm": -75.0, "median_nm": 51.25263539669465}, {"z_centre_nm": 75.0, "median_nm": 52.84078172632685}, {"z_centre_nm": 375.0, "median_nm": 60.583603929777276}, {"z_centre_nm": 525.0, "median_nm": 66.69320561859845}]} diff --git a/benchmarks/uipsf/results/m2_pairs_runs.jsonl b/benchmarks/uipsf/results/m2_pairs_runs.jsonl new file mode 100644 index 00000000..d8e146b5 --- /dev/null +++ b/benchmarks/uipsf/results/m2_pairs_runs.jsonl @@ -0,0 +1,20 @@ +{"set": "beads", "files": 5, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "beads_used": 16, "beads_found": 19, "z_bend": {"-1000.0": 41.87492084503174, "-900.0": 39.16007137298584, "-800.0": 49.88228893280029, "-700.0": 42.82411575317383, "-600.0": 43.013370513916016, "-500.0": 41.47081661224365, "-400.0": 39.29233455657959, "-300.0": 32.538819313049316, "-200.0": 22.497514724731445, "-100.0": 12.59446907043457, "0.0": 4.6039581298828125, "100.0": 0.23059749603271484, "200.0": -5.250234603881836, "300.0": -8.806709289550781, "400.0": -8.467507362365723, "500.0": -10.13247013092041, "600.0": -12.354204177856445, "700.0": -16.57107162475586, "800.0": -18.385857582092285, "900.0": -22.322569847106934, "1000.0": -33.08820915222168}, "phase_nm": {"Z5(2, -2)": -4.08, "Z6(2, 2)": 57.82, "Z7(3, -1)": -5.46, "Z8(3, 1)": -3.32, "Z9(3, -3)": 2.68, "Z10(3, 3)": 0.38, "Z11(4, 0)": 21.35, "Z12(4, 2)": -0.49, "Z13(4, -2)": 0.15, "Z14(4, 4)": 2.18, "Z15(4, -4)": 0.52, "Z16(5, 1)": -6.45, "Z17(5, -1)": 4.93, "Z18(5, 3)": 2.74, "Z19(5, -3)": 1.55, "Z20(5, 5)": -1.67, "Z21(5, -5)": 2.2, "Z22(6, 0)": 3.61, "Z23(6, -2)": 0.68, "Z24(6, 2)": 0.24, "Z25(6, -4)": 1.12, "Z26(6, 4)": -0.36, "Z27(6, -6)": -1.05, "Z28(6, 6)": 1.65, "Z29(7, -1)": 0.54, "Z30(7, 1)": -2.86, "Z31(7, -3)": 1.97, "Z32(7, 3)": 0.79, "Z33(7, -5)": -0.44, "Z34(7, 5)": -0.22, "Z35(7, -7)": -0.73, "Z36(7, 7)": 0.52, "Z37(8, 0)": -5.49, "Z38(8, 2)": 0.97, "Z39(8, -2)": 0.42, "Z40(8, 4)": 1.32, "Z41(8, -4)": 0.77, "Z42(8, 6)": 0.62, "Z43(8, -6)": -0.81, "Z44(8, 8)": -0.23, "Z45(8, -8)": -1.28}, "pupil.gamma": [0.1021], "pupil.gamma_crlb": [0.0011], "psf.sigma": [50.805], "psf.sigma_crlb": [0.1373], "params": ["emitter.background", "emitter.bleaching", "emitter.photons", "emitter.xyz", "geometry.drift", "geometry.drift_rate", "geometry.z_scale", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase", "pupil.ring_h"], "minutes": 0.43, "saved": "beads_3dcal.h5"} +{"set": "nbx4", "files": 3, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 2057, "height_nm": 0.2650134563446045, "height_crlb": 4.7575473033710605, "bend_rms_600": 19.713298497083194, "bend_rms_1000": 19.713298497083194, "scatter": 0.9367620129892168, "z_bend": {"-1000.0": null, "-900.0": null, "-800.0": null, "-700.0": null, "-600.0": 57.4, "-500.0": 16.3, "-400.0": 9.2, "-300.0": 3.7, "-200.0": 12.0, "-100.0": 2.2, "0.0": -8.1, "100.0": -23.2, "200.0": -7.0, "300.0": -0.1, "400.0": 11.9, "500.0": -18.1, "600.0": null, "700.0": null, "800.0": null, "900.0": null, "1000.0": null}, "phase_nm": {"Z5(2, -2)": 5.4, "Z6(2, 2)": 70.88, "Z7(3, -1)": 27.54, "Z8(3, 1)": 53.95, "Z9(3, -3)": 10.18, "Z10(3, 3)": 0.11, "Z11(4, 0)": 6.11, "Z12(4, 2)": -6.11, "Z13(4, -2)": 9.88, "Z14(4, 4)": 16.29, "Z15(4, -4)": -0.12, "Z16(5, 1)": 50.37, "Z17(5, -1)": 34.87, "Z18(5, 3)": 4.6, "Z19(5, -3)": -9.02, "Z20(5, 5)": -26.58, "Z21(5, -5)": -15.64, "Z22(6, 0)": -3.49, "Z23(6, -2)": 19.83, "Z24(6, 2)": 3.0, "Z25(6, -4)": 0.54, "Z26(6, 4)": 11.96, "Z27(6, -6)": -16.55, "Z28(6, 6)": -5.21, "Z29(7, -1)": 6.08, "Z30(7, 1)": 5.64, "Z31(7, -3)": -16.33, "Z32(7, 3)": 13.26, "Z33(7, -5)": -3.54, "Z34(7, 5)": -4.78, "Z35(7, -7)": -31.8, "Z36(7, 7)": -0.25, "Z37(8, 0)": -6.81, "Z38(8, 2)": 5.87, "Z39(8, -2)": 23.3, "Z40(8, 4)": 11.51, "Z41(8, -4)": -6.27, "Z42(8, 6)": -2.39, "Z43(8, -6)": -13.74, "Z44(8, 8)": -27.45, "Z45(8, -8)": -0.2}, "pupil.gamma": [0.0], "pupil.gamma_crlb": [0.1415], "psf.sigma": [16.9051], "psf.sigma_crlb": [2.5581], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase"], "minutes": 17.09, "saved": "nbx4_3dcal.h5"} +{"set": "ab", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 3307, "height_nm": 75.25470733642578, "height_crlb": 3.2568464688937935, "bend_rms_600": 10.354740168161966, "bend_rms_1000": 17.626771226266275, "scatter": 1.355304680521842, "z_bend": {"-1000.0": null, "-900.0": -20.4, "-800.0": -15.6, "-700.0": -11.1, "-600.0": -0.6, "-500.0": 5.3, "-400.0": 6.6, "-300.0": 2.8, "-200.0": -3.1, "-100.0": -5.1, "0.0": -3.7, "100.0": -3.1, "200.0": -6.5, "300.0": -6.0, "400.0": -8.3, "500.0": 7.4, "600.0": 32.8, "700.0": 45.3, "800.0": -5.3, "900.0": 20.7, "1000.0": -38.8}, "phase_nm": {"Z5(2, -2)": -4.01, "Z6(2, 2)": 56.23, "Z7(3, -1)": -1.44, "Z8(3, 1)": 6.98, "Z9(3, -3)": 3.32, "Z10(3, 3)": -2.89, "Z11(4, 0)": 25.4, "Z12(4, 2)": -0.7, "Z13(4, -2)": 0.99, "Z14(4, 4)": 1.92, "Z15(4, -4)": -0.44, "Z16(5, 1)": 6.37, "Z17(5, -1)": 13.39, "Z18(5, 3)": -0.57, "Z19(5, -3)": 1.28, "Z20(5, 5)": -3.8, "Z21(5, -5)": -0.05, "Z22(6, 0)": 7.05, "Z23(6, -2)": 0.88, "Z24(6, 2)": 1.06, "Z25(6, -4)": -0.8, "Z26(6, 4)": 0.76, "Z27(6, -6)": -1.78, "Z28(6, 6)": 2.22, "Z29(7, -1)": 7.9, "Z30(7, 1)": 8.0, "Z31(7, -3)": 2.05, "Z32(7, 3)": -2.08, "Z33(7, -5)": -2.31, "Z34(7, 5)": -1.66, "Z35(7, -7)": -0.64, "Z36(7, 7)": 0.73, "Z37(8, 0)": -5.1, "Z38(8, 2)": 1.74, "Z39(8, -2)": 0.57, "Z40(8, 4)": 2.26, "Z41(8, -4)": -1.08, "Z42(8, 6)": 1.11, "Z43(8, -6)": -2.48, "Z44(8, 8)": 0.97, "Z45(8, -8)": 0.22}, "pupil.gamma": [0.0682], "pupil.gamma_crlb": [0.0083], "psf.sigma": [25.9842], "psf.sigma_crlb": [0.4369], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase"], "minutes": 3.98, "saved": "ab_3dcal.h5"} +{"set": "insitu_beads", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "focus_estimate_nm": 519.5898146511292, "messages": ["held from the start model: \u03b3 = 0.102 and the phase above order 8", "the data prefer the mirrored pupil by 973 nats: the sign of astigmatism and spherical aberration may be the other one", "44671 detections, 13006 blinks, 21140 frames: 223 held out, 4105 not drawn, 5972 rejected: brightness, 146 rejected: masked, 113 rejected: no fit, 5947 rejected: overlap, 802 rejected: photon step, 1345 rejected: shape, 436 rejected: wide, 274 rejected: z range, 1777 used", "18 of 361 blocks of 200 frames read"], "molecules_used": 1777, "geometry.focus": [941.89], "phase_nm": {"Z5(2, -2)": 0.2, "Z6(2, 2)": 82.88, "Z7(3, -1)": -3.71, "Z8(3, 1)": 48.21, "Z9(3, -3)": 5.39, "Z10(3, 3)": 1.67, "Z11(4, 0)": 76.38, "Z12(4, 2)": 27.02, "Z13(4, -2)": 5.64, "Z14(4, 4)": 10.47, "Z15(4, -4)": 4.53, "Z16(5, 1)": 34.0, "Z17(5, -1)": 4.41, "Z18(5, 3)": 5.6, "Z19(5, -3)": 2.54, "Z20(5, 5)": -12.11, "Z21(5, -5)": 0.68, "Z22(6, 0)": 47.69, "Z23(6, -2)": 6.25, "Z24(6, 2)": 22.71, "Z25(6, -4)": 4.98, "Z26(6, 4)": 4.58, "Z27(6, -6)": 0.79, "Z28(6, 6)": 6.38, "Z29(7, -1)": -1.89, "Z30(7, 1)": 12.93, "Z31(7, -3)": 1.75, "Z32(7, 3)": -0.15, "Z33(7, -5)": -1.15, "Z34(7, 5)": -5.74, "Z35(7, -7)": -2.37, "Z36(7, 7)": 1.21, "Z37(8, 0)": 21.59, "Z38(8, 2)": 15.29, "Z39(8, -2)": 4.8, "Z40(8, 4)": 2.77, "Z41(8, -4)": 2.64, "Z42(8, 6)": 2.69, "Z43(8, -6)": -0.5, "Z44(8, 8)": 1.57, "Z45(8, -8)": -1.66}, "psf.sigma": [37.1692], "psf.sigma_crlb": [0.6107], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "psf.sigma", "pupil.magnitude", "pupil.phase"], "minutes": 77.02, "saved": "insitu_beads_3dcal.h5"} +{"set": "ab_h10", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 3304, "height_nm": 10.0, "height_crlb": null, "bend_rms_600": 10.877963425792077, "bend_rms_1000": 22.77297252758714, "scatter": 1.3667825556261524, "z_bend": {"-1000.0": null, "-900.0": -28.3, "-800.0": -22.0, "-700.0": -16.7, "-600.0": -4.9, "-500.0": 2.1, "-400.0": 3.7, "-300.0": 2.1, "-200.0": -3.8, "-100.0": -5.1, "0.0": -1.9, "100.0": -0.7, "200.0": -3.2, "300.0": -1.7, "400.0": -4.0, "500.0": 11.6, "600.0": 36.9, "700.0": 49.0, "800.0": 3.5, "900.0": 47.5, "1000.0": -50.4}, "phase_nm": {"Z5(2, -2)": -4.27, "Z6(2, 2)": 56.24, "Z7(3, -1)": -2.15, "Z8(3, 1)": 6.37, "Z9(3, -3)": 3.1, "Z10(3, 3)": -2.69, "Z11(4, 0)": 25.24, "Z12(4, 2)": -0.68, "Z13(4, -2)": 0.71, "Z14(4, 4)": 1.67, "Z15(4, -4)": -0.34, "Z16(5, 1)": 5.7, "Z17(5, -1)": 12.82, "Z18(5, 3)": -0.45, "Z19(5, -3)": 1.11, "Z20(5, 5)": -3.78, "Z21(5, -5)": 0.01, "Z22(6, 0)": 8.03, "Z23(6, -2)": 0.57, "Z24(6, 2)": 1.27, "Z25(6, -4)": -0.79, "Z26(6, 4)": 0.81, "Z27(6, -6)": -1.61, "Z28(6, 6)": 2.16, "Z29(7, -1)": 7.68, "Z30(7, 1)": 8.02, "Z31(7, -3)": 1.84, "Z32(7, 3)": -2.18, "Z33(7, -5)": -2.33, "Z34(7, 5)": -1.77, "Z35(7, -7)": -0.68, "Z36(7, 7)": 0.81, "Z37(8, 0)": -3.38, "Z38(8, 2)": 2.4, "Z39(8, -2)": 0.17, "Z40(8, 4)": 2.37, "Z41(8, -4)": -1.03, "Z42(8, 6)": 0.88, "Z43(8, -6)": -2.34, "Z44(8, 8)": 0.95, "Z45(8, -8)": 0.33}, "pupil.gamma": [0.2142], "pupil.gamma_crlb": [0.0046], "psf.sigma": [25.1759], "psf.sigma_crlb": [0.4475], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase"], "minutes": 10.49, "saved": "ab_h10_3dcal.h5"} +{"set": "ab_h10_g0_na", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 3293, "height_nm": 10.0, "height_crlb": null, "bend_rms_600": 10.794401166808601, "bend_rms_1000": 20.54852478542919, "scatter": 1.348099553906181, "z_bend": {"-1000.0": null, "-900.0": -19.2, "-800.0": -15.3, "-700.0": -9.6, "-600.0": 0.5, "-500.0": 6.7, "-400.0": 6.4, "-300.0": 2.9, "-200.0": -3.0, "-100.0": -5.5, "0.0": -5.3, "100.0": -5.1, "200.0": -7.9, "300.0": -6.8, "400.0": -8.9, "500.0": 6.1, "600.0": 33.4, "700.0": 49.0, "800.0": -5.4, "900.0": 3.4, "1000.0": -62.3}, "phase_nm": {"Z5(2, -2)": -4.0, "Z6(2, 2)": 55.69, "Z7(3, -1)": -0.03, "Z8(3, 1)": 8.43, "Z9(3, -3)": 3.54, "Z10(3, 3)": -3.12, "Z11(4, 0)": 26.15, "Z12(4, 2)": -1.33, "Z13(4, -2)": 1.03, "Z14(4, 4)": 2.32, "Z15(4, -4)": -0.82, "Z16(5, 1)": 8.17, "Z17(5, -1)": 15.3, "Z18(5, 3)": -0.87, "Z19(5, -3)": 1.7, "Z20(5, 5)": -3.87, "Z21(5, -5)": 0.0, "Z22(6, 0)": 7.27, "Z23(6, -2)": 0.79, "Z24(6, 2)": -0.02, "Z25(6, -4)": -1.34, "Z26(6, 4)": 1.02, "Z27(6, -6)": -2.03, "Z28(6, 6)": 2.44, "Z29(7, -1)": 9.2, "Z30(7, 1)": 9.39, "Z31(7, -3)": 2.45, "Z32(7, 3)": -2.25, "Z33(7, -5)": -2.17, "Z34(7, 5)": -1.75, "Z35(7, -7)": -0.42, "Z36(7, 7)": 0.6, "Z37(8, 0)": -4.79, "Z38(8, 2)": 0.67, "Z39(8, -2)": 0.67, "Z40(8, 4)": 2.24, "Z41(8, -4)": -1.34, "Z42(8, 6)": 1.39, "Z43(8, -6)": -2.64, "Z44(8, 8)": 1.07, "Z45(8, -8)": -0.0}, "pupil.na": [1.4032], "pupil.na_crlb": [0.0005], "psf.sigma": [25.1164], "psf.sigma_crlb": [0.4433], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.magnitude", "pupil.na", "pupil.phase"], "minutes": 12.16, "saved": "ab_h10_g0_na_3dcal.h5"} +{"set": "ab_g0_na", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 3338, "height_nm": 93.98873138427734, "height_crlb": 7.800069682331293, "bend_rms_600": 10.536651011760334, "bend_rms_1000": 20.691963795121747, "scatter": 1.360209320720763, "z_bend": {"-1000.0": null, "-900.0": -20.4, "-800.0": -15.9, "-700.0": -10.5, "-600.0": -0.1, "-500.0": 5.7, "-400.0": 6.5, "-300.0": 3.0, "-200.0": -2.4, "-100.0": -4.9, "0.0": -3.7, "100.0": -3.4, "200.0": -7.3, "300.0": -6.3, "400.0": -8.9, "500.0": 6.8, "600.0": 33.4, "700.0": 55.2, "800.0": -9.5, "900.0": -16.2, "1000.0": -55.4}, "phase_nm": {"Z5(2, -2)": -4.09, "Z6(2, 2)": 56.04, "Z7(3, -1)": -1.41, "Z8(3, 1)": 7.02, "Z9(3, -3)": 3.46, "Z10(3, 3)": -2.9, "Z11(4, 0)": 26.09, "Z12(4, 2)": -0.73, "Z13(4, -2)": 0.78, "Z14(4, 4)": 2.23, "Z15(4, -4)": -0.32, "Z16(5, 1)": 5.93, "Z17(5, -1)": 13.21, "Z18(5, 3)": -0.54, "Z19(5, -3)": 1.48, "Z20(5, 5)": -3.8, "Z21(5, -5)": 0.07, "Z22(6, 0)": 7.16, "Z23(6, -2)": 0.59, "Z24(6, 2)": 1.15, "Z25(6, -4)": -0.51, "Z26(6, 4)": 1.03, "Z27(6, -6)": -1.85, "Z28(6, 6)": 2.2, "Z29(7, -1)": 7.83, "Z30(7, 1)": 7.9, "Z31(7, -3)": 2.34, "Z32(7, 3)": -2.03, "Z33(7, -5)": -2.12, "Z34(7, 5)": -1.76, "Z35(7, -7)": -0.66, "Z36(7, 7)": 0.74, "Z37(8, 0)": -5.54, "Z38(8, 2)": 1.54, "Z39(8, -2)": 0.42, "Z40(8, 4)": 2.39, "Z41(8, -4)": -0.66, "Z42(8, 6)": 1.2, "Z43(8, -6)": -2.54, "Z44(8, 8)": 1.06, "Z45(8, -8)": 0.22}, "pupil.na": [1.4279], "pupil.na_crlb": [0.0043], "psf.sigma": [25.4049], "psf.sigma_crlb": [0.4379], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.magnitude", "pupil.na", "pupil.phase"], "minutes": 17.33, "saved": "ab_g0_na_3dcal.h5"} +{"set": "ab_g0_na_from_h10", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 3343, "height_nm": 98.42145538330078, "height_crlb": 7.741764080159286, "bend_rms_600": 10.383697586388243, "bend_rms_1000": 19.098687318324263, "scatter": 1.3573439652716446, "z_bend": {"-1000.0": null, "-900.0": -20.3, "-800.0": -16.1, "-700.0": -10.5, "-600.0": -0.0, "-500.0": 5.7, "-400.0": 6.5, "-300.0": 3.1, "-200.0": -2.3, "-100.0": -4.9, "0.0": -3.6, "100.0": -3.3, "200.0": -7.5, "300.0": -6.4, "400.0": -9.0, "500.0": 6.7, "600.0": 32.6, "700.0": 53.6, "800.0": -11.7, "900.0": -15.4, "1000.0": -44.1}, "phase_nm": {"Z5(2, -2)": -4.02, "Z6(2, 2)": 56.08, "Z7(3, -1)": -1.55, "Z8(3, 1)": 6.9, "Z9(3, -3)": 3.45, "Z10(3, 3)": -2.85, "Z11(4, 0)": 26.11, "Z12(4, 2)": -0.66, "Z13(4, -2)": 0.9, "Z14(4, 4)": 2.26, "Z15(4, -4)": -0.28, "Z16(5, 1)": 5.69, "Z17(5, -1)": 12.99, "Z18(5, 3)": -0.42, "Z19(5, -3)": 1.45, "Z20(5, 5)": -3.77, "Z21(5, -5)": 0.08, "Z22(6, 0)": 7.18, "Z23(6, -2)": 0.71, "Z24(6, 2)": 1.29, "Z25(6, -4)": -0.43, "Z26(6, 4)": 1.07, "Z27(6, -6)": -1.82, "Z28(6, 6)": 2.16, "Z29(7, -1)": 7.69, "Z30(7, 1)": 7.69, "Z31(7, -3)": 2.33, "Z32(7, 3)": -1.95, "Z33(7, -5)": -2.08, "Z34(7, 5)": -1.71, "Z35(7, -7)": -0.65, "Z36(7, 7)": 0.79, "Z37(8, 0)": -5.59, "Z38(8, 2)": 1.59, "Z39(8, -2)": 0.42, "Z40(8, 4)": 2.51, "Z41(8, -4)": -0.6, "Z42(8, 6)": 1.09, "Z43(8, -6)": -2.52, "Z44(8, 8)": 1.12, "Z45(8, -8)": 0.24}, "pupil.na": [1.4295], "pupil.na_crlb": [0.0036], "psf.sigma": [25.4653], "psf.sigma_crlb": [0.4434], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.magnitude", "pupil.na", "pupil.phase"], "minutes": 22.66, "saved": "ab_g0_na_from_h10_3dcal.h5"} +{"set": "insitu_ab", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "focus_estimate_nm": 543.5297620875684, "messages": ["held from the start model: \u03b3 = 0.068 and the phase above order 8", "the data prefer the mirrored pupil by 1258 nats: the sign of astigmatism and spherical aberration may be the other one", "44671 detections, 13006 blinks, 21140 frames: 223 held out, 4105 not drawn, 5972 rejected: brightness, 146 rejected: masked, 113 rejected: no fit, 5947 rejected: overlap, 802 rejected: photon step, 1345 rejected: shape, 436 rejected: wide, 274 rejected: z range, 1777 used", "18 of 361 blocks of 200 frames read"], "molecules_used": 1777, "geometry.focus": [1052.03], "phase_nm": {"Z5(2, -2)": -1.72, "Z6(2, 2)": 86.7, "Z7(3, -1)": -5.83, "Z8(3, 1)": 49.82, "Z9(3, -3)": 3.67, "Z10(3, 3)": 1.72, "Z11(4, 0)": 80.77, "Z12(4, 2)": 30.7, "Z13(4, -2)": 3.42, "Z14(4, 4)": 12.7, "Z15(4, -4)": 3.4, "Z16(5, 1)": 35.01, "Z17(5, -1)": 2.43, "Z18(5, 3)": 5.72, "Z19(5, -3)": 0.85, "Z20(5, 5)": -12.29, "Z21(5, -5)": 1.68, "Z22(6, 0)": 50.36, "Z23(6, -2)": 4.5, "Z24(6, 2)": 25.86, "Z25(6, -4)": 4.12, "Z26(6, 4)": 6.41, "Z27(6, -6)": 1.64, "Z28(6, 6)": 7.2, "Z29(7, -1)": -2.81, "Z30(7, 1)": 12.68, "Z31(7, -3)": 0.64, "Z32(7, 3)": -0.27, "Z33(7, -5)": -0.46, "Z34(7, 5)": -5.68, "Z35(7, -7)": -2.22, "Z36(7, 7)": 0.79, "Z37(8, 0)": 22.67, "Z38(8, 2)": 16.81, "Z39(8, -2)": 3.77, "Z40(8, 4)": 3.74, "Z41(8, -4)": 2.03, "Z42(8, 6)": 2.8, "Z43(8, -6)": 0.11, "Z44(8, 8)": 0.7, "Z45(8, -8)": -2.1}, "psf.sigma": [36.2933], "psf.sigma_crlb": [0.6157], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "psf.sigma", "pupil.magnitude", "pupil.phase"], "minutes": 85.34, "saved": "insitu_ab_3dcal.h5"} +{"set": "ab_soft", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 4180, "height_nm": 60.03734588623047, "height_crlb": 2.9646522788980456, "bend_rms_600": 9.212886200838312, "bend_rms_1000": 12.187933818495507, "scatter": 1.3409405825141434, "z_bend": {"-1000.0": null, "-900.0": -8.8, "-800.0": -15.9, "-700.0": -9.2, "-600.0": -1.1, "-500.0": 3.0, "-400.0": 8.6, "-300.0": 4.7, "-200.0": 0.0, "-100.0": -4.4, "0.0": -3.5, "100.0": -1.7, "200.0": -6.2, "300.0": -6.4, "400.0": -8.6, "500.0": 5.9, "600.0": 28.3, "700.0": 28.1, "800.0": -0.7, "900.0": -8.4, "1000.0": -24.2}, "phase_nm": {"Z5(2, -2)": -4.21, "Z6(2, 2)": 56.72, "Z7(3, -1)": -2.7, "Z8(3, 1)": 5.58, "Z9(3, -3)": 3.18, "Z10(3, 3)": -2.58, "Z11(4, 0)": 25.02, "Z12(4, 2)": 0.18, "Z13(4, -2)": 0.62, "Z14(4, 4)": 1.89, "Z15(4, -4)": 0.05, "Z16(5, 1)": 3.3, "Z17(5, -1)": 10.55, "Z18(5, 3)": 0.04, "Z19(5, -3)": 1.26, "Z20(5, 5)": -3.72, "Z21(5, -5)": 0.1, "Z22(6, 0)": 7.35, "Z23(6, -2)": 0.73, "Z24(6, 2)": 2.52, "Z25(6, -4)": 0.27, "Z26(6, 4)": 0.68, "Z27(6, -6)": -1.38, "Z28(6, 6)": 2.13, "Z29(7, -1)": 5.55, "Z30(7, 1)": 6.06, "Z31(7, -3)": 2.15, "Z32(7, 3)": -1.61, "Z33(7, -5)": -2.02, "Z34(7, 5)": -1.97, "Z35(7, -7)": -0.95, "Z36(7, 7)": 1.04, "Z37(8, 0)": -4.73, "Z38(8, 2)": 3.19, "Z39(8, -2)": -0.01, "Z40(8, 4)": 2.26, "Z41(8, -4)": 0.14, "Z42(8, 6)": 0.77, "Z43(8, -6)": -1.87, "Z44(8, 8)": 0.67, "Z45(8, -8)": 0.48}, "pupil.gamma": [0.1347], "pupil.gamma_crlb": [0.0072], "psf.sigma": [27.3642], "psf.sigma_crlb": [0.3964], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase"], "minutes": 18.95, "saved": "ab_soft_3dcal.h5"} +{"set": "nbx4_o6", "files": 3, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 2050, "height_nm": 0.00048229002277366817, "height_crlb": 18.82561746591409, "bend_rms_600": 11.590578332825677, "bend_rms_1000": 11.590578332825677, "scatter": 0.921350089757218, "z_bend": {"-1000.0": null, "-900.0": null, "-800.0": null, "-700.0": null, "-600.0": 12.7, "-500.0": -21.6, "-400.0": -23.0, "-300.0": -4.0, "-200.0": 13.0, "-100.0": 10.2, "0.0": -1.2, "100.0": -15.5, "200.0": 1.4, "300.0": -2.4, "400.0": -4.1, "500.0": -5.6, "600.0": null, "700.0": null, "800.0": null, "900.0": null, "1000.0": null}, "phase_nm": {"Z5(2, -2)": 11.47, "Z6(2, 2)": 58.18, "Z7(3, -1)": 31.5, "Z8(3, 1)": 56.16, "Z9(3, -3)": 6.42, "Z10(3, 3)": -23.52, "Z11(4, 0)": 36.52, "Z12(4, 2)": -13.82, "Z13(4, -2)": -6.5, "Z14(4, 4)": -28.51, "Z15(4, -4)": -17.02, "Z16(5, 1)": 46.24, "Z17(5, -1)": 23.63, "Z18(5, 3)": -3.79, "Z19(5, -3)": -4.04, "Z20(5, 5)": -2.95, "Z21(5, -5)": -25.04, "Z22(6, 0)": 5.88, "Z23(6, -2)": -21.81, "Z24(6, 2)": -6.52, "Z25(6, -4)": 2.3, "Z26(6, 4)": -10.24, "Z27(6, -6)": -35.72, "Z28(6, 6)": -8.07}, "pupil.gamma": [0.0], "pupil.gamma_crlb": [0.0386], "psf.sigma": [24.0451], "psf.sigma_crlb": [1.8248], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase"], "minutes": 7.2, "saved": "nbx4_o6_3dcal.h5"} +{"set": "beads_nodrift", "files": 5, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "beads_used": 17, "beads_found": 19, "z_bend": {"-1000.0": 39.4588565826416, "-900.0": 38.893598556518555, "-800.0": 48.25132656097412, "-700.0": 43.14210033416748, "-600.0": 45.45684623718262, "-500.0": 43.8126163482666, "-400.0": 40.82784557342529, "-300.0": 36.140668869018555, "-200.0": 26.997817993164062, "-100.0": 15.983320236206055, "0.0": 6.366229057312012, "100.0": 0.3364086151123047, "200.0": -6.142448425292969, "300.0": -10.894298553466797, "400.0": -9.68200397491455, "500.0": -10.027552604675293, "600.0": -12.246988296508789, "700.0": -16.14011859893799, "800.0": -19.08116912841797, "900.0": -23.57157611846924, "1000.0": -33.46070671081543}, "phase_nm": {"Z5(2, -2)": -4.72, "Z6(2, 2)": 58.69, "Z7(3, -1)": -4.88, "Z8(3, 1)": -3.59, "Z9(3, -3)": 2.64, "Z10(3, 3)": 0.48, "Z11(4, 0)": 22.24, "Z12(4, 2)": -0.46, "Z13(4, -2)": -0.8, "Z14(4, 4)": 2.31, "Z15(4, -4)": 0.67, "Z16(5, 1)": -5.76, "Z17(5, -1)": 3.77, "Z18(5, 3)": 2.74, "Z19(5, -3)": 1.54, "Z20(5, 5)": -1.86, "Z21(5, -5)": 2.16, "Z22(6, 0)": 4.08, "Z23(6, -2)": 0.24, "Z24(6, 2)": 0.67, "Z25(6, -4)": 1.21, "Z26(6, 4)": -0.44, "Z27(6, -6)": -1.05, "Z28(6, 6)": 1.71, "Z29(7, -1)": -0.35, "Z30(7, 1)": -2.58, "Z31(7, -3)": 1.95, "Z32(7, 3)": 0.64, "Z33(7, -5)": -0.4, "Z34(7, 5)": -0.52, "Z35(7, -7)": -0.62, "Z36(7, 7)": 0.47, "Z37(8, 0)": -4.84, "Z38(8, 2)": 1.35, "Z39(8, -2)": -0.16, "Z40(8, 4)": 1.41, "Z41(8, -4)": 0.83, "Z42(8, 6)": 0.78, "Z43(8, -6)": -0.85, "Z44(8, 8)": -0.26, "Z45(8, -8)": -1.28}, "pupil.gamma": [0.0847], "pupil.gamma_crlb": [0.0014], "psf.sigma": [52.3697], "psf.sigma_crlb": [0.1365], "params": ["emitter.background", "emitter.bleaching", "emitter.photons", "emitter.xyz", "geometry.drift", "geometry.z_scale", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase", "pupil.ring_h"], "minutes": 0.8, "saved": "beads_nodrift_3dcal.h5"} +{"set": "ab_c50", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 882, "height_nm": 33.95889663696289, "height_crlb": 5.721443077615446, "bend_rms_600": 17.107530561628728, "bend_rms_1000": 17.083504663646234, "scatter": 1.3279015005700059, "z_bend": {"-1000.0": null, "-900.0": null, "-800.0": -13.9, "-700.0": -9.4, "-600.0": 9.3, "-500.0": 1.1, "-400.0": 4.6, "-300.0": 4.0, "-200.0": -5.1, "-100.0": 2.1, "0.0": 3.5, "100.0": -5.9, "200.0": -4.7, "300.0": -7.2, "400.0": 1.0, "500.0": 19.7, "600.0": 60.6, "700.0": null, "800.0": null, "900.0": null, "1000.0": null}, "phase_nm": {"Z5(2, -2)": -4.52, "Z6(2, 2)": 57.32, "Z7(3, -1)": -1.68, "Z8(3, 1)": 7.56, "Z9(3, -3)": 3.78, "Z10(3, 3)": -2.72, "Z11(4, 0)": 25.28, "Z12(4, 2)": 0.2, "Z13(4, -2)": 0.5, "Z14(4, 4)": 2.02, "Z15(4, -4)": -0.65, "Z16(5, 1)": 5.26, "Z17(5, -1)": 12.96, "Z18(5, 3)": -0.78, "Z19(5, -3)": 0.76, "Z20(5, 5)": -4.38, "Z21(5, -5)": -0.75, "Z22(6, 0)": 7.5, "Z23(6, -2)": -0.39, "Z24(6, 2)": 2.32, "Z25(6, -4)": -0.51, "Z26(6, 4)": 0.89, "Z27(6, -6)": -2.04, "Z28(6, 6)": 1.08, "Z29(7, -1)": 7.76, "Z30(7, 1)": 7.66, "Z31(7, -3)": 2.25, "Z32(7, 3)": -1.74, "Z33(7, -5)": -2.61, "Z34(7, 5)": -2.13, "Z35(7, -7)": -0.46, "Z36(7, 7)": 0.95, "Z37(8, 0)": -4.56, "Z38(8, 2)": 3.68, "Z39(8, -2)": -1.68, "Z40(8, 4)": 2.61, "Z41(8, -4)": -1.34, "Z42(8, 6)": 0.12, "Z43(8, -6)": -2.32, "Z44(8, 8)": 1.19, "Z45(8, -8)": 0.65}, "pupil.gamma": [0.1991], "pupil.gamma_crlb": [0.0158], "psf.sigma": [23.6649], "psf.sigma_crlb": [0.9098], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase"], "minutes": 2.16, "saved": "ab_c50_3dcal.h5"} +{"set": "ab_soft_c50", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 1126, "height_nm": 47.270511627197266, "height_crlb": 5.85979649917353, "bend_rms_600": 14.938210146677847, "bend_rms_1000": 16.355556931534945, "scatter": 1.32170122052651, "z_bend": {"-1000.0": null, "-900.0": -1.5, "-800.0": -2.1, "-700.0": -7.5, "-600.0": 6.6, "-500.0": 1.1, "-400.0": 7.8, "-300.0": 10.9, "-200.0": -4.4, "-100.0": 1.7, "0.0": 1.2, "100.0": -9.4, "200.0": -2.2, "300.0": -3.4, "400.0": 8.6, "500.0": 14.5, "600.0": 53.3, "700.0": 47.2, "800.0": 8.1, "900.0": 27.6, "1000.0": -0.2}, "phase_nm": {"Z5(2, -2)": -4.51, "Z6(2, 2)": 57.68, "Z7(3, -1)": -2.02, "Z8(3, 1)": 7.4, "Z9(3, -3)": 3.87, "Z10(3, 3)": -2.78, "Z11(4, 0)": 24.13, "Z12(4, 2)": 0.58, "Z13(4, -2)": 0.3, "Z14(4, 4)": 1.48, "Z15(4, -4)": -0.31, "Z16(5, 1)": 4.84, "Z17(5, -1)": 11.98, "Z18(5, 3)": -0.64, "Z19(5, -3)": 0.94, "Z20(5, 5)": -4.25, "Z21(5, -5)": -0.96, "Z22(6, 0)": 6.37, "Z23(6, -2)": -0.23, "Z24(6, 2)": 3.16, "Z25(6, -4)": 0.13, "Z26(6, 4)": 0.25, "Z27(6, -6)": -2.1, "Z28(6, 6)": 1.11, "Z29(7, -1)": 6.58, "Z30(7, 1)": 6.86, "Z31(7, -3)": 1.84, "Z32(7, 3)": -1.52, "Z33(7, -5)": -2.65, "Z34(7, 5)": -2.13, "Z35(7, -7)": -0.61, "Z36(7, 7)": 1.63, "Z37(8, 0)": -5.31, "Z38(8, 2)": 4.64, "Z39(8, -2)": -1.61, "Z40(8, 4)": 2.19, "Z41(8, -4)": -0.62, "Z42(8, 6)": -0.17, "Z43(8, -6)": -2.12, "Z44(8, 8)": 1.62, "Z45(8, -8)": 0.57}, "pupil.gamma": [0.2105], "pupil.gamma_crlb": [0.0159], "psf.sigma": [27.6433], "psf.sigma_crlb": [0.859], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase"], "minutes": 5.45, "saved": "ab_soft_c50_3dcal.h5"} +{"set": "insitu_all_ab", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "focus_estimate_nm": 543.4049393027128, "messages": ["held from the start model: every aberration; learnt: the focus and the blur", "44671 detections, 13006 blinks, 21140 frames: 223 held out, 4105 not drawn, 5972 rejected: brightness, 146 rejected: masked, 113 rejected: no fit, 5947 rejected: overlap, 802 rejected: photon step, 1345 rejected: shape, 436 rejected: wide, 274 rejected: z range, 1777 used", "18 of 361 blocks of 200 frames read"], "molecules_used": 1777, "geometry.focus": [354.81], "phase_nm": {}, "psf.sigma": [38.5287], "psf.sigma_crlb": [0.5608], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "psf.sigma", "pupil.magnitude", "pupil.phase"], "minutes": 35.72, "saved": "insitu_all_ab_3dcal.h5"} +{"set": "insitu_all_nmed_ab", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "focus_estimate_nm": 543.1729519004834, "messages": ["held from the start model: every aberration; learnt: the focus and the blur", "44671 detections, 13006 blinks, 21140 frames: 223 held out, 4105 not drawn, 5972 rejected: brightness, 146 rejected: masked, 113 rejected: no fit, 5947 rejected: overlap, 802 rejected: photon step, 1345 rejected: shape, 436 rejected: wide, 274 rejected: z range, 1777 used", "18 of 361 blocks of 200 frames read"], "molecules_used": 1777, "geometry.focus": [468.39], "optics.n_med": [1.41], "phase_nm": {}, "psf.sigma": [53.2354], "psf.sigma_crlb": [0.4141], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "optics.n_med", "psf.sigma", "pupil.magnitude", "pupil.phase"], "minutes": 68.86, "saved": "insitu_all_nmed_ab_3dcal.h5"} +{"set": "ab_n1345", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "molecules_used": 3468, "height_nm": 75.22473907470703, "height_crlb": 3.667071417694877, "bend_rms_600": 7.737651146674769, "bend_rms_1000": 10.990525920689162, "scatter": 1.3818307109767598, "z_bend": {"-1000.0": null, "-900.0": -12.5, "-800.0": -15.9, "-700.0": -9.5, "-600.0": -1.5, "-500.0": 2.8, "-400.0": 6.8, "-300.0": 2.0, "-200.0": -2.6, "-100.0": -3.6, "0.0": -1.2, "100.0": -2.4, "200.0": -7.3, "300.0": -5.4, "400.0": -7.3, "500.0": 4.8, "600.0": 23.2, "700.0": 25.6, "800.0": 2.1, "900.0": -17.8, "1000.0": -14.6}, "phase_nm": {"Z5(2, -2)": -4.03, "Z6(2, 2)": 56.55, "Z7(3, -1)": -3.55, "Z8(3, 1)": 4.59, "Z9(3, -3)": 3.17, "Z10(3, 3)": -2.36, "Z11(4, 0)": 24.23, "Z12(4, 2)": 0.17, "Z13(4, -2)": 0.71, "Z14(4, 4)": 2.08, "Z15(4, -4)": 0.14, "Z16(5, 1)": 1.68, "Z17(5, -1)": 8.71, "Z18(5, 3)": 0.36, "Z19(5, -3)": 1.39, "Z20(5, 5)": -3.41, "Z21(5, -5)": 0.35, "Z22(6, 0)": 7.35, "Z23(6, -2)": 1.09, "Z24(6, 2)": 2.68, "Z25(6, -4)": 0.54, "Z26(6, 4)": 0.8, "Z27(6, -6)": -1.15, "Z28(6, 6)": 2.07, "Z29(7, -1)": 3.68, "Z30(7, 1)": 4.52, "Z31(7, -3)": 2.06, "Z32(7, 3)": -1.28, "Z33(7, -5)": -1.77, "Z34(7, 5)": -1.75, "Z35(7, -7)": -1.01, "Z36(7, 7)": 0.87, "Z37(8, 0)": -4.1, "Z38(8, 2)": 3.64, "Z39(8, -2)": -0.14, "Z40(8, 4)": 2.36, "Z41(8, -4)": 0.46, "Z42(8, 6)": 0.6, "Z43(8, -6)": -1.58, "Z44(8, 8)": 0.67, "Z45(8, -8)": 0.39}, "pupil.gamma": [0.1222], "pupil.gamma_crlb": [0.0078], "psf.sigma": [31.5444], "psf.sigma_crlb": [0.3835], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.height", "geometry.plane", "psf.sigma", "pupil.gamma", "pupil.magnitude", "pupil.phase"], "minutes": 8.5, "saved": "ab_n1345_3dcal.h5"} +{"set": "insitu_start_edge_n1345_ab_n1345", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "focus_estimate_nm": 528.1454202943705, "messages": ["held from the start model: \u03b3 = 0.122 and the phase above order 8", "the data prefer the mirrored pupil by 867 nats: the sign of astigmatism and spherical aberration may be the other one", "44671 detections, 13006 blinks, 21140 frames: 223 held out, 4105 not drawn, 5972 rejected: brightness, 146 rejected: masked, 113 rejected: no fit, 5947 rejected: overlap, 802 rejected: photon step, 1345 rejected: shape, 436 rejected: wide, 274 rejected: z range, 1777 used", "18 of 361 blocks of 200 frames read"], "molecules_used": 1777, "geometry.focus": [682.49], "phase_nm": {"Z5(2, -2)": -2.2, "Z6(2, 2)": 71.87, "Z7(3, -1)": -3.51, "Z8(3, 1)": 41.28, "Z9(3, -3)": 3.83, "Z10(3, 3)": 1.59, "Z11(4, 0)": 55.08, "Z12(4, 2)": 17.4, "Z13(4, -2)": 3.11, "Z14(4, 4)": 1.03, "Z15(4, -4)": 2.42, "Z16(5, 1)": 30.56, "Z17(5, -1)": 5.05, "Z18(5, 3)": 5.65, "Z19(5, -3)": 1.39, "Z20(5, 5)": -10.08, "Z21(5, -5)": 1.11, "Z22(6, 0)": 34.41, "Z23(6, -2)": 4.51, "Z24(6, 2)": 15.89, "Z25(6, -4)": 3.55, "Z26(6, 4)": -2.3, "Z27(6, -6)": 0.44, "Z28(6, 6)": 3.11, "Z29(7, -1)": -1.61, "Z30(7, 1)": 13.52, "Z31(7, -3)": 0.73, "Z32(7, 3)": 0.15, "Z33(7, -5)": -0.96, "Z34(7, 5)": -5.47, "Z35(7, -7)": -2.14, "Z36(7, 7)": 1.17, "Z37(8, 0)": 17.51, "Z38(8, 2)": 12.43, "Z39(8, -2)": 3.83, "Z40(8, 4)": -0.73, "Z41(8, -4)": 1.64, "Z42(8, 6)": 0.86, "Z43(8, -6)": -0.89, "Z44(8, 8)": -0.99, "Z45(8, -8)": -1.8}, "psf.sigma": [38.8398], "psf.sigma_crlb": [0.5807], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "psf.sigma", "pupil.magnitude", "pupil.phase"], "minutes": 60.2, "saved": "insitu_start_edge_n1345_ab_n1345_3dcal.h5"} +{"set": "insitu_start_edge_n1345_tilt_s315_ab_n1345", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "coverslip_tilt_deg": [[-1.6015218391302566, 0.023378054939884624], [-0.8090826512951427, 0.023687280281542916]], "focus_estimate_nm": 527.8653898224168, "messages": ["held from the start model: \u03b3 = 0.122 and the phase above order 8", "the data prefer the mirrored pupil by 867 nats: the sign of astigmatism and spherical aberration may be the other one", "44671 detections, 13006 blinks, 21140 frames: 223 held out, 4105 not drawn, 5972 rejected: brightness, 146 rejected: masked, 113 rejected: no fit, 5947 rejected: overlap, 802 rejected: photon step, 1345 rejected: shape, 436 rejected: wide, 274 rejected: z range, 1777 used", "18 of 361 blocks of 200 frames read"], "molecules_used": 1777, "geometry.focus": [1220.47], "phase_nm": {"Z5(2, -2)": -4.66, "Z6(2, 2)": 57.82, "Z7(3, -1)": -22.85, "Z8(3, 1)": 9.94, "Z9(3, -3)": 4.18, "Z10(3, 3)": 2.94, "Z11(4, 0)": 37.65, "Z12(4, 2)": -0.09, "Z13(4, -2)": -0.32, "Z14(4, 4)": 1.52, "Z15(4, -4)": -0.57, "Z16(5, 1)": 0.51, "Z17(5, -1)": -12.23, "Z18(5, 3)": 3.43, "Z19(5, -3)": 3.44, "Z20(5, 5)": -7.4, "Z21(5, -5)": 0.68, "Z22(6, 0)": 12.6, "Z23(6, -2)": 0.54, "Z24(6, 2)": 4.21, "Z25(6, -4)": -0.46, "Z26(6, 4)": 0.31, "Z27(6, -6)": 4.83, "Z28(6, 6)": -1.4, "Z29(7, -1)": -10.19, "Z30(7, 1)": -3.71, "Z31(7, -3)": 1.62, "Z32(7, 3)": -0.33, "Z33(7, -5)": -0.81, "Z34(7, 5)": -2.94, "Z35(7, -7)": -2.49, "Z36(7, 7)": 0.26, "Z37(8, 0)": 3.29, "Z38(8, 2)": 4.2, "Z39(8, -2)": 1.3, "Z40(8, 4)": 1.13, "Z41(8, -4)": -0.34, "Z42(8, 6)": -0.95, "Z43(8, -6)": 2.95, "Z44(8, 8)": -2.91, "Z45(8, -8)": -2.76}, "psf.sigma": [31.5444, 31.5444], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.tilt", "psf.sigma", "pupil.magnitude", "pupil.phase"], "minutes": 91.83, "saved": "insitu_start_edge_n1345_tilt_s315_ab_n1345_3dcal.h5"} +{"set": "insitu_all_n1345_tilt_s315_ab_n1345", "files": 1, "wavelength_nm": 690.0, "pixel_nm": [127.0, 116.0], "coverslip_tilt_deg": [[-2.9094230239083623, 0.03758280869758423], [-0.03852071278403147, 0.02513294850233905]], "focus_estimate_nm": 527.9233190203054, "messages": ["held from the start model: every aberration; learnt: the focus and the blur", "44671 detections, 13006 blinks, 21140 frames: 223 held out, 4105 not drawn, 5972 rejected: brightness, 146 rejected: masked, 113 rejected: no fit, 5947 rejected: overlap, 802 rejected: photon step, 1345 rejected: shape, 436 rejected: wide, 274 rejected: z range, 1777 used", "18 of 361 blocks of 200 frames read"], "molecules_used": 1777, "geometry.focus": [607.37], "phase_nm": {}, "psf.sigma": [31.5444, 31.5444], "params": ["emitter.background", "emitter.photons", "emitter.xyz", "geometry.focus", "geometry.tilt", "psf.sigma", "pupil.magnitude", "pupil.phase"], "minutes": 41.39, "saved": "insitu_all_n1345_tilt_s315_ab_n1345_3dcal.h5"} diff --git a/benchmarks/uipsf/results/m2_pairs_scores.jsonl b/benchmarks/uipsf/results/m2_pairs_scores.jsonl new file mode 100644 index 00000000..c6813cb1 --- /dev/null +++ b/benchmarks/uipsf/results/m2_pairs_scores.jsonl @@ -0,0 +1,18 @@ +{"score": "fair_stack", "molecules_set": "AB stack, standard selection (learnt on)", "molecules": 4553, "sane": 4535, "model": "ab", "total": 997229.8355102539, "vs_base": 0.0, "vs_base_sane": 0.0, "by_defocus": {"-1000": 0.0, "-800": 0.0, "-600": 0.0, "-400": 0.0, "-200": 0.0, "0": 0.0, "200": 0.0, "400": 0.0, "600": 0.0, "800": 0.0, "1000": 0.0}} +{"score": "fair_stack", "molecules_set": "AB stack, standard selection (learnt on)", "molecules": 4553, "sane": 4535, "model": "ab_n1345", "total": 996550.7789154053, "vs_base": -679.0565948486328, "vs_base_sane": -656.9994659423828, "by_defocus": {"-1000": -70.18093872070312, "-800": -203.30751037597656, "-600": 25.663055419921875, "-400": 322.08274841308594, "-200": 422.2266387939453, "0": 442.4532928466797, "200": 341.2464599609375, "400": 195.7303924560547, "600": -399.0663604736328, "800": -724.3517456054688, "1000": -691.0227813720703}} +{"score": "fair_stack", "molecules_set": "AB stack, standard selection (learnt on)", "molecules": 4553, "sane": 4535, "model": "ab_soft", "total": 996786.8818817139, "vs_base": -442.95362854003906, "vs_base_sane": -427.9673614501953, "by_defocus": {"-1000": -44.68913269042969, "-800": -128.88197326660156, "-600": 13.265121459960938, "-400": 219.33026123046875, "-200": 253.5052947998047, "0": 287.7421875, "200": 242.89186096191406, "400": 111.72506713867188, "600": -238.24859619140625, "800": -483.9878845214844, "1000": -467.0294189453125}} +{"score": "fair_stack", "molecules_set": "AB stack, soft selection (learnt on)", "molecules": 4859, "sane": 4840, "model": "ab", "total": 1044726.0648193359, "vs_base": 0.0, "vs_base_sane": 0.0, "by_defocus": {"-1000": 0.0, "-800": 0.0, "-600": 0.0, "-400": 0.0, "-200": 0.0, "0": 0.0, "200": 0.0, "400": 0.0, "600": 0.0, "800": 0.0, "1000": 0.0}} +{"score": "fair_stack", "molecules_set": "AB stack, soft selection (learnt on)", "molecules": 4859, "sane": 4840, "model": "ab_soft", "total": 1044261.0709075928, "vs_base": -464.99391174316406, "vs_base_sane": -412.1973419189453, "by_defocus": {"-1000": -81.13829040527344, "-800": -127.33319091796875, "-600": 5.9512481689453125, "-400": 209.53013610839844, "-200": 261.33203125, "0": 293.85206604003906, "200": 242.37240600585938, "400": 108.73225402832031, "600": -225.1828155517578, "800": -424.13258361816406, "1000": -454.392822265625}} +{"score": "fair_stack", "molecules_set": "AB stack, soft selection (learnt on)", "molecules": 4859, "sane": 4840, "model": "ab_h10", "total": 1044745.1733398438, "vs_base": 19.1085205078125, "vs_base_sane": 30.3577880859375, "by_defocus": {"-1000": -17.606536865234375, "-800": 24.176345825195312, "-600": 4.659423828125, "-400": 11.193603515625, "-200": 68.30110168457031, "0": 39.40135192871094, "200": 76.46546936035156, "400": 18.940628051757812, "600": 82.72067260742188, "800": -49.17973327636719, "1000": -155.58444213867188}} +{"score": "fair_stack", "molecules_set": "AB stack, soft selection (learnt on)", "molecules": 4859, "sane": 4840, "model": "ab_g0_na", "total": 1044798.2276153564, "vs_base": 72.16279602050781, "vs_base_sane": 62.56385803222656, "by_defocus": {"-1000": 26.479400634765625, "-800": 18.500534057617188, "-600": 22.136276245117188, "-400": 6.8141937255859375, "-200": 15.507293701171875, "0": 17.260406494140625, "200": 15.973907470703125, "400": 12.897552490234375, "600": -35.93193054199219, "800": -41.531402587890625, "1000": -16.404403686523438}} +{"score": "fair_insitu", "molecules_set": "nucleus movie, the 1777 used (learnt on)", "molecules": 1777, "model": "insitu_all_ab", "total": 530550.8, "vs_insitu_all_ab": 0.0} +{"score": "fair_insitu", "molecules_set": "nucleus movie, the 1777 used (learnt on)", "molecules": 1777, "model": "insitu_all_nmed_ab", "total": 529900.4, "vs_insitu_all_ab": -650.4} +{"score": "fair_insitu", "molecules_set": "nucleus movie, the 1777 used (learnt on)", "molecules": 1777, "model": "insitu_ab", "total": 525219.7, "vs_insitu_all_ab": -5331.1} +{"score": "fair_insitu", "molecules_set": "nucleus movie, the 1777 used (learnt on)", "molecules": 1777, "model": "insitu_all_n1345_tilt_s315_ab_n1345", "total": 529813.7, "vs_insitu_all_ab": -737.1} +{"score": "fair_insitu", "molecules_set": "nucleus movie, the 1777 used (learnt on)", "molecules": 1777, "model": "insitu_start_edge_n1345_tilt_s315_ab_n1345", "total": 526995.1, "vs_insitu_all_ab": -3555.7} +{"score": "insitu_control", "focus": 607.041259765625, "sigma": [30.22918128967285], "messages": ["held from the start model: \u03b3 = 0.122 and the phase above order 8"], "used": 1805, "phase": {"Z5": [-4.0, -4.5], "Z6": [56.6, 55.4], "Z7": [-3.6, -3.3], "Z8": [4.6, 4.3], "Z9": [3.2, 3.3], "Z10": [-2.4, -2.3], "Z11": [24.2, 23.6], "Z12": [0.2, -1.0], "Z16": [1.7, 1.2], "Z17": [8.7, 8.9], "Z22": [7.3, 6.3], "Z37": [-4.1, -5.3]}} +{"score": "zfit_vs_zgt", "truth": "AB propagated, n 1.345, focus 607 nm, no tilt", "model": "insitu_all_n1345_tilt_s315_ab_n1345", "slope": 0.99, "rms_about_line_nm": 6} +{"score": "zfit_vs_zgt", "truth": "AB propagated, n 1.345, focus 607 nm, no tilt", "model": "insitu_ab", "slope": 1.08, "rms_about_line_nm": 15} +{"score": "zfit_vs_zgt", "truth": "AB propagated, n 1.345, focus 607 nm, no tilt", "model": "insitu_start_edge_n1345_ab_n1345", "slope": 1.03, "rms_about_line_nm": 12} +{"score": "zfit_vs_zgt", "truth": "AB propagated, n 1.345, focus 607 nm, no tilt", "model": "insitu_start_edge_n1345_tilt_s315_ab_n1345", "slope": 1.13, "rms_about_line_nm": 13} +{"score": "zfit_vs_zgt", "truth": "AB propagated, n 1.345, focus 607 nm, no tilt", "model": "ab_n1345 spline, no depth (coverslip_fit.py)", "slope": 1.17, "rms_about_line_nm": 37} diff --git a/docs/uipsf/architecture.md b/docs/uipsf/architecture.md index 9941cf5d..e6b0a2ad 100644 --- a/docs/uipsf/architecture.md +++ b/docs/uipsf/architecture.md @@ -2477,6 +2477,169 @@ data); γ the microscope's, never learnt by default. **Open**: which γ M2's ob August beads' 0.16 (the same objective and colour, another camera: γ is not as fixed as decided) or what its January molecules ask for, 0.36; the dual channel's focus at 25 px. +## In situ against molecule stacks on M2 (November 2026) + +The question: on one microscope on one day, does in situ learning from a blinking movie inside a cell give the +same PSF as learning from molecules on the coverslip in z sweeps (M9, `molecule-stacks.md`)? And which of the +two should be used to fit the cell? Scripts are in `benchmarks/uipsf/real/m2_pairs/` and results in +`benchmarks/uipsf/results/m2_pairs_*.jsonl`. The data are not in git; the scripts read them from `$M2_DATA`. + +**The paired data** were taken on M2 on 12 November 2026 with the Andor iXon (EM, pre-amp gain 1, chip ROI +254-59-202-218, 127 × 116 nm pixels on the astigmatic path), 50 ms frames, 638 nm excitation, emission taken as +690 nm, and the same objective (NA 1.43, oil 1.516). All three sets share the camera ROI and laser settings +and were taken within 3.5 hours: +- `261112_MR_Intercalib2_Beads_1_700`: 5 bead stacks of 61 frames, ±1.5 µm in 50 nm steps (19:11). +- `261112_MR_Intercalib2_BGAAF647_50ms_30i_nucleus_1`: the in situ movie, BG-AF647 on nuclear pores of a fixed, + permeabilised cell in a dSTORM GLOX buffer. Two files, ~72 000 frames, the focus held by the focus lock + (20:16). +- `261112_MR_Intercalib2_AB_50ms_coverslip`: AF647 molecules on the glass, 10 sweeps of 61 frames, ±1.5 µm in + 50 nm steps (22:25); its buffer is not recorded. + +A second molecule set, `NBX4_50ms_coverslip`, gave too few molecules to learn from (2050; order 6 still +fails). The metadata do not record the cylindrical lens or the collar. Every model's Noll 6 of 57-87 nm says +the lens was in throughout. The user confirmed that the movie was taken under the beads' conditions. + +**The runs** all use the minimal pupil (`model.MinimalPupil`), Zernike phase to order 8 and a round σ. They are +run by `m2_new.py` with environment variables, one line of `m2_pairs_runs.jsonl` each. +- *Molecule stack* `ab_n1345`: n_med 1.345 (a GLOX buffer, below). γ learnt. σ round and learnt. The height + above the glass learnt (h; since 58f38c76 the default holds it at 5 nm, so a rerun needs `HEIGHT=` unset to + *auto*). A focus per sweep and the focal plane's slope learnt. The region is 21 px (`REGION_NM` 2600 nm). + The selection is the soft one, now the default (525e9cb1), at significance 5. 4000 molecules were drawn of + 4553 that passed and 3468 kept after two rounds. 8.5 min on Apple's GPU. +- *In situ* (`run_insitu`, the region 25 px, `REGION_NM` 3000 nm), 1777 molecules used, 223 held out and 4105 + not drawn, started from the stack model: + - `insitu_start_edge_n1345_ab_n1345` is the main comparison. *hold* is the start's: γ 0.122 and the phase + above order 8 (none at order 8) held from the stack model. The phase to order 8 and σ are learnt, and the + focus comes from the coverslip edge (`FOCUS_FIT=coverslip`). n_med is 1.345. + - `insitu_ab` is the free variant: n_med 1.33, γ 0.068 held from an earlier AB model (n 1.33), and the focus + learnt. + - `insitu_start_edge_n1345_tilt_s315_ab_n1345` adds a learnt coverslip tilt with σ held at the stack's 31.5 nm. + - `insitu_all_n1345_ab_n1345` holds every aberration of the stack model and learns only the focus and σ. + `insitu_all_n1345_tilt_s315_ab_n1345` does the same with a tilt and σ held. +- *Beads* (`beads`), for reference: 16 beads of 100 nm, linear drift, γ and σ learnt. + +**The index.** The literature has 1.34-1.35 for a GLOX/MEA dSTORM buffer, and the user expects a fixed, +permeabilised cell to be only slightly higher, so n_med is held at 1.345. Learnt in situ with every aberration of the stack held, it went to 1.41 and gained only 650 nats over 1777 +molecules (`insitu_all_nmed_ab`). The index presets in the PSF calibration and +the fitters (a251380e) came from this. + +**The comparison.** Phase in nm rms. Noll 4 is not a learnt mode, since each geometry's focus takes the +defocus, so the focus column stands in for it. The two Δnats columns score each model on molecules that no +model learnt from, using `cross_score.py`, and are given in nats per molecule against the stack model (negative: +fits better): +- *stack held-out*: the 553 AB molecules that passed but were not drawn. Each model's pupil, γ and σ are + held, the stack geometry (sweep foci, plane, h) is learnt again on the same 600 drawn molecules, and then x, + y, photons and background are free. +- *in situ held-out*: the movie's 223 *held out* molecules, drawn like the 1777 used (each z bin's share). + Apart from them, its 4105 *not drawn*: the bins' surplus, which over-represent the heights where molecules + are plentiful. x, y, z, photons and background + are free from five heights, and the best start is kept. An in situ model uses its own focus. The stack + model enters as `insitu_all_n1345_ab_n1345`: every aberration held, the focus and σ learnt (420 nm, + 39.5 nm). The stack held with a tilt (`insitu_all_n1345_tilt_s315_ab_n1345`) scores −0.22 / +1.52. + +| model | Z5 | Z6 | Z7 | Z8 | Z11 | Z12 | Z16 | Z22 | Z37 | γ | σ (nm) | focus (nm) | h (nm) | Δ stack held-out | Δ in situ held out / not drawn | +|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| +| stack `ab_n1345` | −4.0 | 56.6 | −3.6 | 4.6 | 24.2 | 0.2 | 1.7 | 7.4 | −4.1 | 0.122 (learnt) | 31.5 | per sweep | 75 ± 4 (68 refit) | 0 | 0 / 0 (focus 420, σ 39.5) | +| in situ, edge, n 1.345 | −2.2 | 71.9 | −3.5 | 41.3 | 55.1 | 17.4 | 30.6 | 34.4 | 17.5 | 0.122 (held) | 38.8 | 682 | (151 refit) | +4.51 | −1.75 / +0.36 | +| in situ free, n 1.33 | −1.7 | 86.7 | −5.8 | 49.8 | 80.8 | 30.7 | 35.0 | 50.4 | 22.7 | 0.068 (held) | 36.3 | 1052 | (200 refit, the bound) | +8.43 | −2.75 / +0.50 | +| in situ, edge + tilt, σ held | −4.7 | 57.8 | −22.9 | 9.9 | 37.7 | −0.1 | 0.5 | 12.6 | 3.3 | 0.122 (held) | 31.5 (held) | 1220 | – | – | −1.25 / +2.12 | +| beads | −4.1 | 57.8 | −5.5 | −3.3 | 21.4 | −0.5 | −6.5 | 3.6 | – | 0.102 (learnt) | 50.8 | – | – | – | – | + +Things to read from the table: +- *The stack and the beads agree*. Astigmatism matches within 1.3 nm and spherical within 3 nm. The x coma + (Z8, Z16) differs by 8 nm, and it is not the beads' sideways drift: without drift Z8 is −3.6. +- *In situ does not agree with them.* The free and edge-pinned runs put 15-30 nm more into astigmatism (Z6), + 31-57 nm more into primary spherical (Z11), and 30-50 nm into x coma (Z8, Z16), secondary spherical (Z22, + Z37) and Z12. These are the pupil's even and x-odd modes, the ones that depth, the index and a tilt about y + all produce. +- *A tilt takes most of the excess.* With a coverslip tilt learnt (−1.6° about y, σ held), Z6, Z8, Z16 and + Z12 return to the stack's within 6 nm. Z11 keeps 13 nm extra and y coma (Z7, Z17) takes −20 nm instead. A + 1.6° tilt is larger than the user expects. Held at every aberration of the stack, the movie asks for + −2.9°. +- *On held-out molecules each model wins on its own data.* On the stack set the in situ pupils lose 4.5 and + 8.4 nats per molecule, and the refit then pushes the molecules' height to 151 and 200 nm (the bound), against + the stack's own 68-75 nm. On the in situ set's own held-out molecules the in situ pupils win by + 1.75 and 2.75 nats per molecule. The surplus molecules (*not drawn*) go the other way by 0.36-0.50. Which + heights the surplus crowds at, and so where in z the stack's pupil is the better one, is not yet checked. On the + molecules they learnt from, the in situ pupils had led by ~3 nats per molecule (`fair_insitu`), so part of + that lead was fitting their own molecules. The two samples still ask for different PSFs: no single pupil + with only the focus learnt serves both. + +**z linearity in the cell**, from the simulation in `zfit_vs_zgt.py`. The truth is the stack model propagated +into the sample (n 1.345, focus 607 nm, no tilt) at heights 0-1200 nm, with the movie's photons (4570) and +background (98). Each model localises the spots, and the table gives the slope of z_fit against z_gt and the +rms about the line over 0-1000 nm: + +| model | slope | rms (nm) | +|---|---|---| +| stack held, tilt learnt (`insitu_all_n1345_tilt_s315`) | 0.99 | 6 | +| in situ edge, n 1.345 | 1.03 | 12 | +| in situ free, n 1.33 | 1.08 | 15 | +| in situ edge + tilt, σ held | 1.13 | 13 | +| the stack's spline on the glass, no depth (`coverslip_fit.py`) | 1.17 | 37, strongly bent | + +Every in situ model, and the stack model redrawn at depth, stays far straighter than a coverslip calibration +used as it is. For fitting a cell, the depth matters more than which pupil is used. + +**The control** (`insitu_control.py`) simulates a movie from the stack model at depth: molecules 0-1000 nm high, +a tenth on the glass, the movie's photons and background, 160 × 160 px, 4000 frames. It is learnt as the real +movie was. Every mode comes back within ~1 nm (Z6 55.4 for a truth of 56.6, Z11 23.6 for 24.2), the focus +607 nm, σ 30.2 for 31.5. So in situ on this geometry and these settings is sound. The 15-60 nm differences in +the table are in the data, not the method. + +**NPC ring separation against z** (`npc_rings.chain.yaml`, `rings.batch.yaml`, `rings_vs_z.py`; +`m2_pairs_npc_rings.jsonl`). The movie was fitted with Spline 3D under each calibration and drift-corrected +with RCC. The pores come from *Segment regions*' NPC preset, with a two-Gaussian Line Profile in z per pore. +The table keeps pores whose separation error is below 10 nm, 20-120 nm apart, with at least 40 localisations: + +| calibration | pores | separation (nm, median) | slope against z (nm per µm) | +|---|---|---|---| +| stack spline as calibrated (no depth) | 177 | 62.1 | 2 | +| stack redrawn at the focus (*auto*) | 153 | 55.0 | 24 | +| in situ free, n 1.33 | 178 | 59.2 | 15 | +| in situ from beads | 179 | 58.6 | 17 | +| in situ edge, n 1.345 | 183 | 56.6 | 19 | +| in situ edge + tilt, σ held | 160 | 59.6 | 37 | +| stack held + tilt | 167 | 53.4 | 28 | + +The pores sit at two depths, near the coverslip and ~550 nm up. The upper group reads 2-22 nm wider under +every calibration, more than the z scale explains. Those pores are likely tilted on the nuclear envelope, so +this is not yet a clean test of linearity. + +**Ruled out**: +- *A wrong index alone.* At 1.345 the gap stays. Learning n_med goes to 1.41 and recovers only 650 nats. +- *The molecule selection.* Soft and standard selections, significance 3.5 or 5, a wider off-centre limit and + the central field only (`ab_c50`, `ab_soft_c50`) move every mode by at most 3 nm. +- *h, γ and the NA in the stack.* With h held at 10 nm, γ 0 with the NA free (1.403-1.430), or a restart from + h = 10, the phase stays within ~2 nm. Learnt h ranges from 34 to 98 nm across the variants. +- *The method.* The simulated control recovers the truth. +- *The beads' drift for the coma.* It changes Z8 by 0.3 nm. + +**Open hypotheses**: +- *A sample tilt or curvature.* The tilt explains most of the excess but needs 1.6-2.9°, and the pores' own + tilt on the nuclear envelope may be what the model reads as one. +- *Focus drift over the 72 000 frames.* A changing focus would blur the depth signal, and so the even modes. + It is not yet measured per time block. +- *Refractive-index structure of the nucleus* above the buffer's, which a single n_med cannot hold. +- *The stack's h of 75 nm*: AF647 on the glass should sit a few nm up. Yet learnt h stays at 34-98 nm in every + variant, and the in situ pupils push it higher still. The supercritical ring's brightness is how h is told, + and the magnitude and γ trade with it. +- *The cross-check of item 9's next step*: in situ with γ and the phase above order 6 held from the stack model. + Running when this was written (`insitu_o6_edge_n1345_ab_n1345`). + +**The scripts** (`benchmarks/uipsf/real/m2_pairs/`; each says how it is called): +- `m2_new.py`: every learning run, steered by environment variables (`ORDER`, `HOLD`, `START`, `NMED`, + `FOCUS_FIT`, `TILT`, `BLUR_NM`, `HEIGHT`, `SIG`, `SOFT`, ...). It appends a row to `summary.jsonl`, which is + `m2_pairs_runs.jsonl` here. +- `soft_select.py`: the soft selection as a patch, the prototype of 525e9cb1. +- `fair_compare.py` and `fair_insitu.py`: models scored on one fixed set of the molecules they learnt from + (`m2_pairs_scores.jsonl`, `fair_*`). +- `cross_score.py`: the held-out scores of the table (`m2_pairs_cross.jsonl`). +- `insitu_control.py`: the simulated control. +- `zfit_vs_zgt.py` and `coverslip_fit.py`: z linearity (`m2_pairs_scores.jsonl`, `zfit_vs_zgt`, copied from + their printout). +- `npc_rings.chain.yaml`, `rings.batch.yaml` and `rings_vs_z.py`: the NPC rings (`m2_pairs_npc_rings.jsonl`). + ## 4Pi from beads (October 2026; `docs/4pi.md` D7 and §8) ``` diff --git a/docs/uipsf/roadmap.md b/docs/uipsf/roadmap.md index 8cf58130..6bf6cbaa 100644 --- a/docs/uipsf/roadmap.md +++ b/docs/uipsf/roadmap.md @@ -138,6 +138,9 @@ when a milestone lands or an item moves. pupil; Spline 3D's *focus in situ* is stable to 12 nm from three starts. Open: γ decides January's astigmatism (its beads' 0.08 gives theirs, the 0.36 its molecules learn gives 0.25 rad more and fits them better, the dual channel prefers its beads' γ by 2 nats per molecule) -- which γ M2's objective has; the dual channel's focus. + **In situ against molecule stacks on M2** (12 November 2026, architecture.md, "In situ against molecule stacks + on M2"): the stack and the beads agree, in situ in the nucleus puts 15–57 nm more into astigmatism, spherical + and x coma, each model wins on its own held-out molecules; a sample tilt takes most of it; open. 10. **Release (M6):** the real benchmark against tuned v1 with no per-dataset settings, CUDA and Windows GPU runs, uipsf documentation, 2.0.