Skip to content

Architecture — synaptome

synaptome (distributed as mindmap-synaptome, part of the mindmap collection; imported as synaptome) is a Python library that keeps a research study's analysis-ready data in one portable object: who ran it and how (identity, protocol), which units were observed (a hierarchy such as site > subject > session), what each variable means (a strict data dictionary), and the values themselves. A Study can be saved as an open .syn file (Parquet + JSON) and handed to a collaborator. A separate, array-level statistics engine (engine/) provides the tests, estimators, confidence intervals, bootstrap, corrections and cluster permutation that analyses will use. datasets/ builds toy studies with planted effects, one per study design. questions/ turns "compare X by Y" into a resolved design (paired or independent, groups, pairs, n) and an analysis table. estimates/ answers "how large?" and hypotheses/ "is there a difference?" (two-group, omnibus, cluster and normality tests), as results/ values that carry their question, data fingerprint and pre-registration timing (study.verify, .synr files, formatted tables, corrections across results). The protocol stores pre-specified questions with an amendment log. plot/ draws data and results with plain Matplotlib. The documentation site (docs/, mkdocs.yml) renders concepts, the executed tutorials and the API reference.

1. Big picture

flowchart LR
    user([User code / notebook])
    study[Study<br/>study/study.py]
    units[UnitHierarchy<br/>study/units.py]
    vars[VariableDictionary<br/>study/variables.py]
    store[ValueStore<br/>study/values.py]
    meta[StudyInfo · Protocol · Attachments]
    syn[(.syn folder / zip<br/>io/syn.py)]
    engine[engine/<br/>plain arrays]
    question[Question · Design<br/>questions/]
    estimate[estimates/ registry + runner]
    test[hypotheses/ registry + runner]
    result[Estimate · Pairwise · Omnibus ·<br/>Cluster · Normality · Describe<br/>results/]
    synr[(.synr file)]

    user -->|add, add_units, to_df, select| study
    user -->|compare, compare_along, distribution| question
    question -->|to_df, units, reducers| study
    question -->|q.estimate| estimate
    question -->|q.test| test
    test -->|effect sizes| estimate
    test -->|engine tests| engine
    estimate -->|engine functions| engine
    estimate --> result
    test --> result
    user -->|syn.correct| result
    result <-->|save / load_result| synr
    result -.->|study.verify| study
    study --> units
    study --> vars
    study --> store
    study --> meta
    study <-->|save / load / peek| syn
    user -.->|arrays from to_df| engine

Study is the only object users normally touch. It owns four parts that know nothing about each other's internals: the unit hierarchy, the variable dictionary, the value store, and descriptive metadata. io/syn.py reads and writes the whole thing. engine/ is standalone: it works on NumPy arrays, and nothing in study/ calls it; estimates/ and hypotheses/ call it on a question's data.

2. Components

Component Path Responsibility Talks to
Public API src/synaptome/__init__.py Exports Study, concat, load, peek, InferenceNotice, datasets, load_result, correct, and plot (imported on first use) study, io, datasets, results, plot
Study src/synaptome/study/study.py Container; add/add_units, views (to_df, table, describe, with reduce= and joins up the hierarchy), manipulation (select, drop, rename, copy, concat), save; entry points compare / compare_along / distribution / question / verify and plot (lazy); protocol property binding the protocol to the study all of study/, io/syn.py, lazily questions/, plot/
Reducers src/synaptome/study/reduce.py parse_reduce, reduce_dim, reduce_level: named reductions (mean … slope, auc, ("at", c)) on long tables —
Unit hierarchy src/synaptome/study/units.py Levels as a DAG (nesting and crossing), shorthand parser ("a > b", "t < s * x"), unit id tables, internal unit keys, path resolution between levels —
Variable dictionary src/synaptome/study/variables.py Dim (with kind for replicate axes), Variable (with replicates_of), VariableDictionary: definitions, inference from first values, strict validation, replicate links units (level names)
Value store src/synaptome/study/values.py One long table per variable (_uid, dimension columns, value); added_at / first_added_at; InferenceNotice —
Identity & plan src/synaptome/study/info.py, protocol.py StudyInfo/Person, Protocol/Arm dataclasses with to_dict/from_dict; the protocol's pre-specified questions (Registration: spec, status, registered_at), add_question / remove_question with the amendment log, questions rebuilt on the bound study, match study.question (lazy)
Attachments src/synaptome/study/attachments.py Embedded files or path references, both with SHA-256 checksums —
Storage src/synaptome/io/syn.py .syn writer/reader (format 2: questions/, first-added times; reads format 1), peek, partial load(variables=...) study/*
Atomic writes src/synaptome/io/_atomic.py atomic_replace: write elsewhere, then swap in —
Engine src/synaptome/engine/ Hypothesis tests, estimators and effect sizes, analytic and bootstrap intervals, p-value correction, effective sample size, cluster permutation NumPy/SciPy only
Toy studies src/synaptome/datasets/toy.py Eight seeded generators (case_control, crossover, longitudinal, simulation_benchmark, timepoint_pairing, repeated_trials, crossed, method_comparison), each returning a fully defined Study; planted effects (real and null) in study.info.extra["planted"] study (public API only)
Questions src/synaptome/questions/ Question base (base.py: roles, validation, to_dict/from_dict, memoized design / data / data_key, pair_data); kinds Compare, CompareAlong, Distribution; resolve.py (subset → reduce → paired/independent → analysis table, guard rails); design.py (Design); fingerprint.py (data_key) study (public API: to_df, units, reducers)
Estimates src/synaptome/estimates/ registry.py: one Estimator per estimator (family group / pair / omnibus, designs, scales per design, min_groups, binary, engine function, analytic interval, bounded, flip); requirements.py: checks shared with tests (scale wording, fitting estimators, serial-correlation summary, assume_independent); run.py: compute_estimate checks the estimator against q.design (guard rails naming alternatives) and computes rows with analytic / bootstrap / upstream-replicate intervals (optionally returning the draws); group_samples builds one sample per group for omnibus statistics engine, questions
Tests src/synaptome/hypotheses/ registry.py: one Test per test (answers, designs, scales, binary, engine call, params, default effect sizes, ordered-unit rule, offset, result kind, min_groups, default correction); run.py: compute_test checks the test against q.design and dispatches on its result kind: per pair on q.pair_data (pairwise), once on all groups (omnibus), per pair on curves (cluster), per group or per pair of differences (normality); effect sizes through compute_estimate; correction_columns, cluster_correction engine, estimates, questions
Results src/synaptome/results/ base.py: Result (question spec, method, table, extra tables, data_key, times, versions), to_frame / to_markdown, .synr save, load_result; estimate.py: EstimateResult with vs(), run_estimate; tested.py: TestResult, RowsResult (correct of one p per row); pairwise.py: PairwiseResult (vs, differences, draws); omnibus.py, normality.py; cluster.py: ClusterResult (correct(family=), verdict, curve, null, vs); describe.py: DescribeResult, run_describe; run.py: run_test (result type from the registry); correct.py: syn.correct (one family across results); format.py: APA p values, estimate cells, Markdown tables and notes for every type; timing.py: timing(question) (registration vs first data) stamped on every result estimates, hypotheses, io/_atomic
Plots src/synaptome/plot/ accessor.py: PlotAccessor (study.plot), the data views and thin result-view methods, draw_categorical; results.py: the result views (comparison, differences, along, estimate / forest, normality, omnibus), the stale-result check, plot_result (result.plot()); _data.py: the frame a view draws (view_frame: subset, reduce, unit collapse, pooling record), summaries (ci through the estimator registry), box statistics, ECDF, Bland–Altman; _draw.py: matplotlib renderers, no statistics; style.py: font size, stable colours; figure.py: Plot study (public API), estimates, _utils
Docs site docs/, mkdocs.yml Concept pages, docs/tutorials → ../tutorials (executed at build), API reference pages (synaptome.<package>), development pages included from ARCHITECTURE / CONTRIBUTING / CHANGELOG; docs/_hooks/notebook_links.py rewrites links between tutorials the package (docstrings), tutorials/
Helpers src/synaptome/_utils.py JSON-safe conversion, filter freezing/serialization, match_values (subset/select matching) —

Engine files

File Contents
engine/hypothesis.py StatResult; paired_test (Wilcoxon with zero_method, t, t with effective n, exact McNemar), independent_test (Mann-Whitney, Student, Welch), both with offset; normality, omnibus_paired, omnibus_independent
engine/effect_sizes.py Estimators: mean_diff, hodges_lehmann, prop_diff, odds_ratio; Cohen's d/dz, Hedges' g/gz, CLES, rank-biserial, Kendall's W, η², partial η² (RM), ε²
engine/intervals.py Analytic CIs: t (optional n_eff), Welch, signed-rank and Mann-Whitney (Hodges-Lehmann), exact binomial (median), Wilson, Newcombe, odds ratio
engine/bootstrap.py bootstrap_draws, bootstrap_interval (percentile, basic, BCa), bootstrap_pvalue (matches the interval), bootstrap_bias, jackknife acceleration, bootstrap_ci (one call, accepts pre-computed draws)
engine/correction.py correct_pvalues (none, Bonferroni, Holm, BH, BY)
engine/ess.py effective_sample_size for serially correlated samples
engine/cluster.py cluster_permutation (1-D, paired sign flips or independent label shuffles, exact enumeration when small) → ClusterStatResult

Each estimator follows one signature per family: one sample f(x), paired f(x, y, paired=True) (or f(x, y) for paired-only estimators), independent f(a, b). Positive always means the first sample is larger. Placeholder packages for the later layers (hypotheses/, plot/, and the test result modules of results/) hold only a docstring naming the step that builds them.

3. Main flow: adding values, then saving

  1. study.add("weight", df) (study/study.py). The input is either a long DataFrame (unit id columns, dimension columns, value column) or an array for one unit, with ids and coordinates passed as keywords (converted by _array_to_frame).
  2. Level and dimensions. If the variable is new, its level comes from the id columns (_infer_level) and its dimensions from the remaining columns. Variable.infer (study/variables.py) guesses the dtype, and an InferenceNotice warning shows the definition. If the variable already exists, the given dimensions are checked against its definition.
  3. Validation. Variable.validate checks dtype, categories and range. study.add itself rejects missing coordinates and duplicate addresses.
  4. Units. The first data that mentions a level creates that level's units. Afterwards, unknown ids raise unless create_units=True. UnitHierarchy.lookup turns the id columns into internal _uids.
  5. Storage. ValueStore.put (study/values.py) appends the rows. Writing to an address that already holds a value raises unless overwrite=True.
  6. Rollback. On any error, the unit tables are restored from a snapshot and a newly inferred definition is dropped, so a failed add leaves the study unchanged.
  7. study.save("trial.syn") → io/syn.save. _write_tree writes the files listed below into a temporary folder, which is then zipped (path ends in .syn) or renamed into place. Only an existing synaptome save is ever overwritten.
  8. units/<level>.parquet
  9. values/<variable>.parquet, each carrying its variable definition in Parquet metadata
  10. questions/<title>.json, the protocol's pre-specified questions
  11. study.json (info, protocol with its amendment log, levels, dictionary, first / last added times)
  12. manifest.json (format 2; format 1 still loads)
  13. syn.load(path) reverses this. It rebuilds levels, units and definitions, then replays the values through study.add(..., create_units=False), so hand-edited files are validated again.

Asking a question

  1. study.compare("error", by="method", subset=..., reduce=...) (study/study.py) imports questions/ and builds a Compare. Creation checks names only (outcome, by, reducers), so a question can exist before its data.
  2. First access to q.design / q.data calls questions/resolve.resolve:
  3. to_df(outcome) gives the raw long table; subset filters coordinates, unit ids, or units by a scalar variable (match_values);
  4. the unit is fixed (given, or the level the reductions lead to), and every level between the outcome and the unit must be reduced (pseudo-replication guard);
  5. by is classified: a dimension → within-unit factor (paired); a variable at the unit's level → between-unit factor (independent); a variable at a level crossed with the unit → within-unit (paired); anything else raises;
  6. unused dimensions must be reduced or left with one coordinate; reductions run in the order written (reduce_dim, reduce_level from study/reduce.py);
  7. the analysis table (unit ids, by, along, outcome) and the Design (groups, pairs, n per pair on complete cases, scale) are built.
  8. The result is memoized on the question. q.data_key (questions/fingerprint.py) hashes the sorted table and the meaning-bearing fields of the definitions read.
  9. q.to_dict() records the roles (no values); study.question(spec) rebuilds it on any study.

Computing an estimate

  1. q.estimate("hodges_lehmann", ci="analytic") (questions/base.py) imports results/estimate.py (results sit above estimates) and calls run_estimate.
  2. estimates/run.compute_estimate looks the estimator up (estimates/registry.py) and checks it against q.design: question kind (pairs need compare), paired / independent, binary, scale, ordered unit, interval availability. Each refusal names the estimators or settings that fit.
  3. Rows come from q.data (per group) or q.pair_data(a, b) (per pair), per along coordinate. Analytic intervals are the registry's engine functions (n_eff for an ordered unit); bootstrap uses engine.bootstrap_draws / jackknife_* / bootstrap_interval with the recorded seed, or the draws of a replicate variable, resolved like the outcome (resolve(..., keep=(draw_dim,))).
  4. run_estimate wraps the table and method in an EstimateResult with the question's to_dict(), data_key, time and versions. result.save() writes a .synr zip; study.verify(result) rebuilds the question on the current study and compares data_key.

Running a test

  1. q.test("wilcoxon", alternative="less") (questions/base.py) imports results/run.py and calls run_test, which picks the result type from the registry's result (pairwise, omnibus, cluster, normality).
  2. hypotheses/run.compute_test looks the test up (hypotheses/registry.py) and checks it against q.design: kind (compare), paired / independent, binary, scale, the ordered-unit rule (refused with the measured effective sample size unless assume_independent=True; ttest_ess only there), offset.
  3. Per pair, the engine test runs on q.pair_data(a, b); bootstrap instead takes its estimator's draws from compute_estimate(..., return_draws=True) and reads the p value with engine.bootstrap_pvalue. Effect sizes are compute_estimate tables joined on the pair, so they equal q.estimate. The p values are corrected across the pairs (engine.correct_pvalues). Omnibus tests read group_samples (one matched sample per group); cluster tests pivot each pair to units × coordinates in along order and call engine.cluster_permutation (corrected by cluster_correction, family "cluster" or "pair"); normality tests read per group, or each pair's differences when paired.
  4. run_test wraps it in its result (extra tables such as draws, pairs, curve, null saved in .synr). q.describe() goes through results/describe.run_describe instead. result.correct(...) and syn.correct([...]) (one family across results) return new results; to_markdown() / to_frame(pretty=True) format it through results/format.py.

Pre-specifying a question

  1. study.protocol.add_question(q, status="primary") (study/protocol.py) stores q.to_dict() with its status and the current time (Registration). Only names are checked, so it works before any value.
  2. study.save writes each registration to questions/<safe title>.json, the amendment log and the first / last added times to study.json (io/syn.py); load restores them, peek lists them.
  3. study.protocol.questions[title] rebuilds the question with study.question(spec) on the current data (the protocol is bound to its study by the Study.protocol setter).
  4. Every result is stamped by results/timing.timing(question): protocol.match (same title and analysis) gives the registration; the variables read are the resolved definitions; "before data" when the registration precedes the earliest first_added_at among them.

Drawing a data view

  1. study.plot.violin("error", x="method", subset=...): the study.plot property imports plot/ lazily and returns a PlotAccessor.
  2. _data.view_frame reads study.to_df(var, with_=..., reduce=...), filters with subset, collapses to one value per unit if asked, and records what is pooled (values, units, dimensions left).
  3. _data.summary_table computes what is drawn (centers, intervals, box statistics); colours come from style.colors (position among all levels of the variable).
  4. _draw renders those numbers only; the view returns a Plot with data, points and artists.

Drawing a result

  1. r.plot() (results/base.py) imports plot/results.plot_result, which picks the view for the type and draws on r.question.study; study.plot.comparison(r) etc. draw on that study.
  2. _check rebuilds the question from r.question_spec on the study and compares data_key: a mismatch raises (out of date).
  3. The view draws the question's data (question.data, pair_data, draws, curve) through the same _data / _draw helpers as data views, and the result's own numbers (verdicts, effect sizes oriented with vs()); brackets, annotations, forest rows and cluster bars are in Plot.data / artists.

4. Data model

erDiagram
    Study ||--|| StudyInfo : info
    Study ||--|| Protocol : protocol
    Study ||--|| UnitHierarchy : units
    UnitHierarchy ||--|{ Level : levels
    Level }o--o{ Level : "parents (DAG)"
    Study ||--|| VariableDictionary : variables
    VariableDictionary ||--o{ Variable : defines
    Variable }o--|| Level : "attached to"
    Variable ||--o{ Dim : "shape"
    Variable |o--o{ Variable : "replicates_of"
    Variable ||--o{ Value : "observed as"
    Study ||--o{ Attachment : attachments
    Protocol ||--o{ Registration : "pre-specified questions"

A value's address is (unit at the variable's level, a coordinate on each dimension). Unit attributes such as group, age and sex are not a separate concept. add_units stores them as scalar variables at that level.

5. Where do I change X?

  • Add a variable field (e.g. a new metadata key) → Variable in study/variables.py. It must also round-trip through to_dict/from_dict.
  • Change what counts as a valid value → Variable.validate and the _to_* converters in study/variables.py.
  • Change dtype or level inference → _infer_dtype in study/variables.py, Study._infer_level in study/study.py.
  • Change the level shorthand or hierarchy rules → UnitHierarchy.define / add_level / paths in study/units.py.
  • Add a view or manipulation (to_df, table, select, …) → study/study.py.
  • Add a reducer → REDUCERS and reduce_dim in study/reduce.py (and LEVEL_REDUCERS if it makes sense for unordered units).
  • Change how levels are reduced or joined → Study._reduce_frame, _reduction_chain, _join in study/study.py.
  • Change replicate rules → Variable.__post_init__ and _check_replicate in study/variables.py; dependents are guarded in VariableDictionary.update / remove.
  • Change the on-disk format → io/syn.py (_write_tree, load). Bump FORMAT_VERSION when old readers would misread the files.
  • Add a statistical test or estimator → engine/hypothesis.py or engine/effect_sizes.py; an analytic interval → engine/intervals.py. Export it in engine/__init__.py.
  • Change how bootstrap intervals or p-values are read from draws → engine/bootstrap.py (bootstrap_interval and bootstrap_pvalue must stay consistent with each other).
  • Add a study-level field (ethics, funding, …) → study/info.py or study/protocol.py.
  • Add or change a toy study → datasets/toy.py (export it in datasets/__init__.py). It must define every variable explicitly, list its planted effects (with at least one null) in the docstring and in _planted(...) entries, and get a recovery test in tests/unit/test_datasets_toy.py.
  • Add a question kind → a Question subclass in questions/ with its kind, _role_names and _check_roles; resolution goes through questions/resolve.py; add an entry point in study/study.py.
  • Change how paired / independent is decided, or a guard rail → _classify_by and the checks in resolve() (questions/resolve.py); error wording uses between-/within-unit factor vocabulary.
  • Change what data_key depends on → _FIELDS / _DIM_FIELDS in questions/fingerprint.py (bump VERSION if old keys must stop matching).
  • Change a dimension's ordering rules → Dim.effective_scale and check_dim_coordinates (study/variables.py), the scale checks in reduce_dim (study/reduce.py).
  • Add an estimator → an Estimator entry in estimates/registry.py (engine function per design, analytic interval if any, scales, bounded, flip); the runner and vs() pick it up.
  • Change an estimator guard rail → _check_requirements in estimates/run.py; wording shared with tests (scales, serial correlation, assume_independent) in estimates/requirements.py.
  • Add a test → an engine function (engine/hypothesis.py) and a Test entry in hypotheses/registry.py (answers, designs, scales, binary, params, default effect sizes, result); compute_test and the result type pick it up. A new kind of result needs a _<kind>_rows builder in hypotheses/run.py, a class in results/ registered in results/run._RESULTS, and its pretty_* / notes in results/format.py. Give the test a statistic symbol and a name in results/format.py.
  • Change summary statistics → results/describe.py (columns per scale in _INTERVAL / _ORDINAL / _BINARY).
  • Change the cluster correction families → cluster_correction in hypotheses/run.py (used by the runner and ClusterResult.correct).
  • Change a test guard rail → _check_requirements / _check_offset / _effect_sizes in hypotheses/run.py.
  • Change how p values are corrected or pooled → engine/correction.py (methods), PairwiseResult.correct (one result), results/correct.py (across results).
  • Change pre-specified questions or amendments → Protocol.add_question / remove_question / match in study/protocol.py; their storage in _write_tree / load (io/syn.py); the timing rule in results/timing.py (and timing_note in results/format.py).
  • Add or change a data view → plot/accessor.py (arguments, layout), plot/_data.py (numbers), plot/_draw.py (artists). Keep statistics out of _draw.py. Baselines: regenerate with pytest --mpl-generate-path=tests/unit/baseline -k image and check the images.
  • Add or change a result view → plot/results.py (and its thin method in plot/accessor.py, its result.plot() mapping in _VIEWS); annotation text in plot/_data.py (annotation_lines).
  • Change colours or fonts → plot/style.py (colors, set_style, STYLE).
  • Add a documentation page → docs/ and the nav of mkdocs.yml; a public name → its package's __all__ and a NumPy docstring (it then appears in docs/reference/); tutorials are in the site through the docs/tutorials symlink, and links between them are rewritten by docs/_hooks/notebook_links.py.
  • Change formatted tables → results/format.py (format_p, format_number, pretty_pairwise, pretty_estimate, the notes); Result.to_frame / to_markdown in results/base.py.
  • Change what a result stores or how .synr is written → results/base.py (to_dict, save, load_result; bump RESULT_FORMAT_VERSION for incompatible changes).
  • Change how vs() reorients → EstimateResult.vs and _flip in results/estimate.py, PairwiseResult.vs in results/pairwise.py (also flips alternative and offset).
  • Change a public API used in a tutorial → update the notebook in tutorials/ in the same change. Notebooks are committed without outputs; tutorials/README.md lists them in order.

6. Key decisions

  • Definitions are separate from values. A variable is defined once and observed many times, which makes strict validation possible.
  • Validation is strict after the first values. Inference makes quick work easy, and strictness afterwards catches typos in ids and categories.
  • Within-unit factors are dimensions, between-unit factors are variables. Analyses can then tell paired from independent data without being told.
  • Repetitions are unit levels. Trials, seeds and folds go in the unit hierarchy, not in dimensions, so collapsing them is an explicit step.
  • The hierarchy is a DAG, not a tree. This is needed for crossed designs (trial < subject * stimulus).
  • Ids are stored as given and made unique internally. "Trial 1" can repeat under every subject.
  • Storage is Parquet + JSON. Any Parquet reader (pandas, R, DuckDB) can open the data without synaptome.
  • Saves are atomic, and only synaptome saves are overwritten. A crash or a typo'd path can't destroy data.
  • engine/ works on arrays and does not depend on Study. It is testable on its own and reusable outside the study model. It needs no MNE: the cluster permutation is plain NumPy/SciPy.
  • A test's offset moves only the p-value. Effect sizes always describe the raw difference; alternative stays two-sided unless asked.
  • Reductions are explicit. Views and questions never average repetitions silently: table(level) refuses a variable with several values per unit until reduce= says how to collapse them.
  • Joins only go up the hierarchy. Each row then gets exactly one value; one-to-many relations must be reduced first.
  • Upstream resampling is a replicate variable, not a unit level. Draws aren't independent units; replicates_of links them to the variable they resample.
  • synaptome never processes data. Values arrive already derived; provenance is documented, not run.
  • Questions read the design off the data model. Nobody passes paired=True: where by lives (a dimension, a variable at the unit's level, a variable at a crossed level) decides. Reductions are never guessed, and each pair of a comparison keeps its own complete cases.
  • Questions use only the study's public API. resolve.py builds on to_df, units and the reducers; the study.compare-style entry points import questions/ lazily, the only upward reference.
  • Estimates refuse what doesn't fit. Scale, binary outcome, design and serial correlation are checked before computing, and the error lists what fits: guard rails are a feature for users who aren't statisticians. Bootstrap is seeded by default, so every result is reproducible.
  • Serial correlation is refused, with a recorded override. An ordered unit (unit="time") refuses tests and intervals that assume independence, naming the effective sample size; ttest_ess is allowed, and assume_independent=True is recorded in the result and its tables. synaptome can't check independence, so the user states it.
  • Omnibus and pairwise tests are separate calls. Nothing runs behind the user's back after a significant omnibus test; normality tests are diagnostics, uncorrected by default.
  • Timing is recorded by synaptome, not declared. "Before data" compares the protocol's own registration time with the first time each variable read got values; amendments are logged and re-timed.
  • A result is drawn only on its own data. Result views rebuild the question and refuse a changed data_key; they draw the result's verdicts, never re-test.
  • Figures compute nothing they don't report. Plain matplotlib (no seaborn); _data.py computes every number drawn and Plot.data returns it. Data views pool and say so; questions guard the statistics.
  • Corrections make new results. result.correct and syn.correct([...]) (one family pooled across results, e.g. per sensor type) never change a result in place; the family is recorded in method["correction"].
  • Results are values. A result holds its question's spec and the data_key it read; nothing is cached in the study. study.verify(result) re-asks the question and compares keys.
  • Toy studies carry their own truth. Planted effects live in study.info.extra["planted"], shaped like the question that recovers them (outcome, by, contrast, value, optional subset / reduce / unit / along), so they survive save/load and tests read them instead of hard-coding numbers.
  • Scale (2026-11, laptop). method_comparison(n_sources=7000), about 1.95 M values, the size of the mindmap-bem manuscript: generating and adding 0.9 s, to_df(reduce={"source": "median"}) 0.1 s, save 0.3 s (19 MB), load 0.8 s (0.4 s for one variable). Adding one subject at a time costs about 4x one batch, since each add merges with what is stored; append per subject or run, not per sample.

7. Glossary

  • Level: a kind of unit (subject, session, trial). Levels form a DAG through their parents.
  • Unit: one member of a level, with an id and links to its parents. Always a statistical unit; the unit of measurement of a variable or dimension is its measurement_unit ("kg", "ms").
  • Variable: a defined quantity attached to one level, with a dtype, a scale and optional dimensions.
  • Dimension (Dim): an ordered or within-unit axis of a variable (time, channel, condition). It is not a unit level.
  • Address: (unit, coordinates). Exactly one value lives at each address.
  • Replicate variable: resampled values of another variable (replicates_of), with one extra dimension of kind replicate (bootstrap draw) or jackknife (left-out unit).
  • Reduction: collapsing a dimension or a unit level to one value with a named reducer (reduce=).
  • Inferred definition: a definition guessed from the first values and flagged with InferenceNotice.
  • .syn: the storage layout, as a folder or an uncompressed zip.
  • Question: what is compared on which data (outcome, by, subset, reduce, unit, ...); no numbers, no test. Design: what a question resolves to (paired or independent, groups, pairs, n).
  • Between- / within-unit factor: a factor constant within each unit (a variable at the unit's level) or varying within it (a dimension, or a variable at a crossed level); gives independent / paired comparisons.
  • data_key: the fingerprint of the data a question read.
  • Estimate / result: an answer to "how large?" (EstimateResult), with confidence intervals; a result is a plain value with its question, method, table and data_key, saved alone as a .synr file.
  • vs(): a pair estimate or test reoriented around the reference so that positive means the reference is better (a test's alternative and offset turn with it).
  • Test / PairwiseResult: an answer to "is there a difference?", one row per pair with p, corrected p, verdict and effect sizes. Family: the p values corrected together (a result's pairs, or several results with syn.correct).
  • Omnibus test: one test of all the groups at once ("do they differ at all?"). Cluster: neighbouring coordinates whose t passes the cluster-forming threshold; its mass is the sum of their t.
  • Registration / amendment: a question pre-specified in the protocol, with the time synaptome recorded; a logged replacement or removal of one. Timing: before data / after data / not pre-specified / unknown.
  • Data view / Plot: a figure of a variable's values (study.plot.<view>), and what it returns (axes, numbers drawn, artists). Pooled: values of dimensions or levels not on the axes drawn together.
  • assume_independent: the recorded statement that positions along an ordered unit are independent.
  • Dimension scale: Dim.scale; numeric coordinates are interval by default, others nominal.
  • Toy study / planted effect: a generated study from synaptome.datasets, and a true difference (or a null, 0) built into it on purpose, recorded in study.info.extra["planted"].

8. Testing strategy

  • Tests live in tests/unit/test_<package>_<module>.py, one file per module. Run them with pytest. Warnings are errors (filterwarnings = ["error"] in pyproject.toml).
  • Lint and format with ruff check . and ruff format --check ..
  • CI (.github/workflows/ci.yml) runs lint, then the tests on Python 3.10–3.13 with coverage. It also runs the tutorials (tutorials/NN_topic.ipynb) with pytest --nbmake tutorials. They double as end-to-end checks of the public API. A docs job builds the site with mkdocs build --strict (tutorials executed, griffe warnings on docstrings are errors); .github/workflows/docs.yml publishes it to GitHub Pages on pushes to main.
  • tests/unit/test_public_api.py checks that every public name and method has a docstring (the API reference has no empty entry) and that import synaptome doesn't load Matplotlib.
  • Figures: Plot.data is tested in the default run; six image baselines (tests/unit/baseline/) are compared with pytest --mpl.

9. Further reading

  • DESIGN.md: the agreed model and API, and the dated decisions log (§14).
  • PLAN.md: the build order. Steps 0–15 are done; 16 is the release.
  • tutorials/: notebook 00 covers installation; 01–05 walk through the study, units, variables (including replicate variables), values, views (including reduce=) and storage; 06 covers the engine on plain arrays; 07 the toy studies; 08 questions; 09 estimates; 10 tests and corrections; 11 comparing along a dimension; 12 pre-registration; 13 plotting.
  • The documentation site (docs/): concept pages, the tutorials executed, the API reference; README.md, CHANGELOG.md, CONTRIBUTING.md.

Doc metadata - project_type: library - sections: [big-picture, components, main-flow, data-model, where-to-change, decisions, glossary, testing, further-reading] - last_commit: 80cf5b19a216052d358167d615ee68374f6eaa0e - last_updated: 2026-11-26 - project_notes: Feature-complete for v0.1 (steps 0–15); the release (PyPI) is step 16.