Testing helpers#
Convenience helpers for using minisim as test fixtures for an analysis pipeline.
Unlike the rest of the reference, these live in the minisim.testing submodule
(from minisim.testing import make_recording, score). See the how-to guide
Use minisim in your test suite for the recommended pytest wiring.
make_recording#
- minisim.testing.make_recording(*, n_cells=6, n_px=128, pixel_size_um=1.0, duration_s=2.0, fps=20.0, seed=0, depth_um=50.0, soma_radius_um=5.0, morphology='soma', motion=False, activity=None, sensor=None, extra_steps=(), save_intermediates=False)[source]#
A small, fast, deterministic recording with ground truth, for CI tests.
Places
n_cellswell-separated somata on a jittered grid at a singledepth_umand runs the minimal forward chain (place_neurons → cell_activity → optics → composite → sensor) on a squaren_px × n_pxsensor atpixel_size_umper pixel. Cell count, positions, and every pixel are fully determined by the arguments, so the sameseed(and the same arguments) always yields the same recording - the property a fixture needs.Defaults are tuned for CI: a 128 px FOV at 1 µm/px (128 µm), six cells at 50 µm depth, two seconds at 20 fps, with a lively, brightly-exposed default activity/sensor so every placed cell reliably fires and is detectable. Shrink
n_px/duration_sfor an even faster fixture, or raisen_cellsfor a denser one.- Parameters:
n_cells (int) – Number of somata to place (exactly this many; grid-arranged and separated).
n_px (int) – Square sensor side, pixels (both height and width).
pixel_size_um (float) – Object-space size of one pixel, µm. Realized via a sensor pitch of
8.0µm and a matching magnification, so the FOV isn_px · pixel_size_um.duration_s (float) – Sampling and the master RNG seed.
fps (float) – Sampling and the master RNG seed.
seed (int) – Sampling and the master RNG seed.
depth_um (float) – Common depth of every soma below the tissue surface, µm. The focal plane is
"auto", so it resolves here and the cells are in focus.soma_radius_um (float) – Cell shape:
"soma"(body only, fast) or"cytosolic"(soma plus proximal dendrites).morphology (str) – Cell shape:
"soma"(body only, fast) or"cytosolic"(soma plus proximal dendrites).motion (bool) – When
True, append a defaultBrainMotionstep, soground_truth.shiftsis populated (lets you exercise motion correction).activity (CellActivity | None) – Override the
CellActivitymodel or theSensorexposure step;Noneuses defaults.sensor (Sensor | None) – Override the
CellActivitymodel or theSensorexposure step;Noneuses defaults.extra_steps (Sequence[Annotated[PlaceNeurons | CellActivity | CellOptics | Composite | Neuropil | Vasculature | Bleaching | BrainMotion | IlluminationProfile | Vignette | Leakage | Sensor, Discriminator(discriminator=kind, custom_error_type=None, custom_error_message=None, custom_error_context=None)]]) – Additional steps to append (
Neuropil,Vignette,Leakage, …); the spec re-sorts into canonical order, so order here is free.save_intermediates (bool) – Persist per-stage snapshots (see
Output).
- Returns:
rec.observedis the movie,rec.ground_truththe exact truth.- Return type:
score#
- minisim.testing.score(estimate, ground_truth, *, iou_threshold=0.5, tol_frames=2, restrict_to_detectable=True)[source]#
Score a pipeline’s
Estimateagainst the ground truth, in one call.Runs the standard recovery pipeline: match estimated footprints to true ones by spatial overlap (
hungarian_match()againstA_observed, the recoverable target), then score the temporal recovery of the matched pairs. The conventions the a-la-carte recipe asks you to remember are applied here:matches against
A_observed(not the optics-freeA_planted);scores recall over the detectable cells by default (the fair denominator; see
detectable_subset());reduces per-pair trace correlations with a nan-safe median;
treats an estimated motion trajectory as a correction (negated) when comparing to
GroundTruth.shifts.
- Parameters:
estimate (Estimate) – The pipeline output. Only
Estimate.Ais required.ground_truth (GroundTruth) – The recording’s
ground_truth.iou_threshold (float) – Minimum IoU for a matched pair to count as a true positive.
tol_frames (int) – Spike-timing tolerance, frames (see
spike_precision_recall()).restrict_to_detectable (bool) – Score against
detectable_subset()(default). SetFalseto score against every planted cell, detectable or not.
- Returns:
The scorecard. Unsupplied estimate fields score
nan/None.- Return type:
Estimate#
- class minisim.testing.Estimate(A, C=None, S=None, shifts=None)[source]#
Bases:
NamedTupleWhat a pipeline recovered, as the input to
score().Ais the only required field.C/S/shiftsare optional; whenNone, the matching score in theReportisnan(orNonefor motion). Arrays may benumpyorxarray(minian’s CNMF returnsxr.DataArray); both are accepted.A- spatial footprints,(n_units, height, width).C- calcium traces,(n_units, frame).S- deconvolved spikes,(n_units, frame).shifts- estimated per-frame(dy, dx)motion,(frame, 2). A motion correction trajectory (the negation of the applied shift);score()negates it to compare againstGroundTruth.shifts.
Report#
- class minisim.testing.Report(n_true, n_est, n_matched, recall, precision, mean_iou, trace_corr, spike_precision, spike_recall, shift_rmse)[source]#
Bases:
objectThe recovery scorecard
score()returns.Cell counts and spatial scores are always present; temporal scores are
nanwhen the matching estimate field was not supplied, andshift_rmseisNonewhen motion truth or a motion estimate is absent.- Parameters: