mindmap-synaptome 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. mindmap_synaptome-0.1.0/.gitignore +28 -0
  2. mindmap_synaptome-0.1.0/ARCHITECTURE.md +446 -0
  3. mindmap_synaptome-0.1.0/CHANGELOG.md +42 -0
  4. mindmap_synaptome-0.1.0/CONTRIBUTING.md +79 -0
  5. mindmap_synaptome-0.1.0/LICENSE +21 -0
  6. mindmap_synaptome-0.1.0/PKG-INFO +95 -0
  7. mindmap_synaptome-0.1.0/README.md +62 -0
  8. mindmap_synaptome-0.1.0/docs/_hooks/notebook_links.py +16 -0
  9. mindmap_synaptome-0.1.0/docs/concepts/answers.md +57 -0
  10. mindmap_synaptome-0.1.0/docs/concepts/plots.md +40 -0
  11. mindmap_synaptome-0.1.0/docs/concepts/preregistration.md +32 -0
  12. mindmap_synaptome-0.1.0/docs/concepts/questions.md +50 -0
  13. mindmap_synaptome-0.1.0/docs/concepts/study.md +56 -0
  14. mindmap_synaptome-0.1.0/docs/development/architecture.md +1 -0
  15. mindmap_synaptome-0.1.0/docs/development/changelog.md +1 -0
  16. mindmap_synaptome-0.1.0/docs/development/contributing.md +1 -0
  17. mindmap_synaptome-0.1.0/docs/index.md +36 -0
  18. mindmap_synaptome-0.1.0/docs/install.md +36 -0
  19. mindmap_synaptome-0.1.0/docs/reference/datasets.md +3 -0
  20. mindmap_synaptome-0.1.0/docs/reference/engine.md +3 -0
  21. mindmap_synaptome-0.1.0/docs/reference/estimates.md +3 -0
  22. mindmap_synaptome-0.1.0/docs/reference/hypotheses.md +3 -0
  23. mindmap_synaptome-0.1.0/docs/reference/io.md +3 -0
  24. mindmap_synaptome-0.1.0/docs/reference/plot.md +3 -0
  25. mindmap_synaptome-0.1.0/docs/reference/questions.md +3 -0
  26. mindmap_synaptome-0.1.0/docs/reference/results.md +3 -0
  27. mindmap_synaptome-0.1.0/docs/reference/study.md +3 -0
  28. mindmap_synaptome-0.1.0/docs/reference/synaptome.md +5 -0
  29. mindmap_synaptome-0.1.0/docs/tutorials/00_setup.ipynb +214 -0
  30. mindmap_synaptome-0.1.0/docs/tutorials/01_quickstart.ipynb +793 -0
  31. mindmap_synaptome-0.1.0/docs/tutorials/02_units_and_variables.ipynb +519 -0
  32. mindmap_synaptome-0.1.0/docs/tutorials/03_adding_values.ipynb +291 -0
  33. mindmap_synaptome-0.1.0/docs/tutorials/04_selecting_and_reshaping.ipynb +331 -0
  34. mindmap_synaptome-0.1.0/docs/tutorials/05_save_and_share.ipynb +336 -0
  35. mindmap_synaptome-0.1.0/docs/tutorials/06_array_statistics.ipynb +316 -0
  36. mindmap_synaptome-0.1.0/docs/tutorials/07_toy_studies.ipynb +389 -0
  37. mindmap_synaptome-0.1.0/docs/tutorials/08_questions.ipynb +450 -0
  38. mindmap_synaptome-0.1.0/docs/tutorials/09_estimates.ipynb +321 -0
  39. mindmap_synaptome-0.1.0/docs/tutorials/10_tests_and_corrections.ipynb +536 -0
  40. mindmap_synaptome-0.1.0/docs/tutorials/11_comparing_along_a_dimension.ipynb +276 -0
  41. mindmap_synaptome-0.1.0/docs/tutorials/12_preregistration.ipynb +264 -0
  42. mindmap_synaptome-0.1.0/docs/tutorials/13_plotting.ipynb +376 -0
  43. mindmap_synaptome-0.1.0/docs/tutorials/README.md +34 -0
  44. mindmap_synaptome-0.1.0/mkdocs.yml +112 -0
  45. mindmap_synaptome-0.1.0/pyproject.toml +91 -0
  46. mindmap_synaptome-0.1.0/src/synaptome/__init__.py +34 -0
  47. mindmap_synaptome-0.1.0/src/synaptome/_utils.py +126 -0
  48. mindmap_synaptome-0.1.0/src/synaptome/datasets/__init__.py +35 -0
  49. mindmap_synaptome-0.1.0/src/synaptome/datasets/toy.py +983 -0
  50. mindmap_synaptome-0.1.0/src/synaptome/engine/__init__.py +99 -0
  51. mindmap_synaptome-0.1.0/src/synaptome/engine/bootstrap.py +461 -0
  52. mindmap_synaptome-0.1.0/src/synaptome/engine/cluster.py +261 -0
  53. mindmap_synaptome-0.1.0/src/synaptome/engine/correction.py +77 -0
  54. mindmap_synaptome-0.1.0/src/synaptome/engine/effect_sizes.py +368 -0
  55. mindmap_synaptome-0.1.0/src/synaptome/engine/ess.py +67 -0
  56. mindmap_synaptome-0.1.0/src/synaptome/engine/hypothesis.py +485 -0
  57. mindmap_synaptome-0.1.0/src/synaptome/engine/intervals.py +271 -0
  58. mindmap_synaptome-0.1.0/src/synaptome/estimates/__init__.py +10 -0
  59. mindmap_synaptome-0.1.0/src/synaptome/estimates/registry.py +329 -0
  60. mindmap_synaptome-0.1.0/src/synaptome/estimates/requirements.py +119 -0
  61. mindmap_synaptome-0.1.0/src/synaptome/estimates/run.py +412 -0
  62. mindmap_synaptome-0.1.0/src/synaptome/hypotheses/__init__.py +9 -0
  63. mindmap_synaptome-0.1.0/src/synaptome/hypotheses/registry.py +280 -0
  64. mindmap_synaptome-0.1.0/src/synaptome/hypotheses/run.py +559 -0
  65. mindmap_synaptome-0.1.0/src/synaptome/io/__init__.py +8 -0
  66. mindmap_synaptome-0.1.0/src/synaptome/io/_atomic.py +43 -0
  67. mindmap_synaptome-0.1.0/src/synaptome/io/syn.py +416 -0
  68. mindmap_synaptome-0.1.0/src/synaptome/plot/__init__.py +11 -0
  69. mindmap_synaptome-0.1.0/src/synaptome/plot/_data.py +499 -0
  70. mindmap_synaptome-0.1.0/src/synaptome/plot/_draw.py +604 -0
  71. mindmap_synaptome-0.1.0/src/synaptome/plot/accessor.py +932 -0
  72. mindmap_synaptome-0.1.0/src/synaptome/plot/figure.py +66 -0
  73. mindmap_synaptome-0.1.0/src/synaptome/plot/results.py +1051 -0
  74. mindmap_synaptome-0.1.0/src/synaptome/plot/style.py +113 -0
  75. mindmap_synaptome-0.1.0/src/synaptome/py.typed +0 -0
  76. mindmap_synaptome-0.1.0/src/synaptome/questions/__init__.py +25 -0
  77. mindmap_synaptome-0.1.0/src/synaptome/questions/base.py +484 -0
  78. mindmap_synaptome-0.1.0/src/synaptome/questions/compare.py +80 -0
  79. mindmap_synaptome-0.1.0/src/synaptome/questions/compare_along.py +43 -0
  80. mindmap_synaptome-0.1.0/src/synaptome/questions/design.py +137 -0
  81. mindmap_synaptome-0.1.0/src/synaptome/questions/distribution.py +39 -0
  82. mindmap_synaptome-0.1.0/src/synaptome/questions/fingerprint.py +65 -0
  83. mindmap_synaptome-0.1.0/src/synaptome/questions/resolve.py +468 -0
  84. mindmap_synaptome-0.1.0/src/synaptome/results/__init__.py +27 -0
  85. mindmap_synaptome-0.1.0/src/synaptome/results/base.py +396 -0
  86. mindmap_synaptome-0.1.0/src/synaptome/results/cluster.py +170 -0
  87. mindmap_synaptome-0.1.0/src/synaptome/results/correct.py +73 -0
  88. mindmap_synaptome-0.1.0/src/synaptome/results/describe.py +110 -0
  89. mindmap_synaptome-0.1.0/src/synaptome/results/estimate.py +149 -0
  90. mindmap_synaptome-0.1.0/src/synaptome/results/format.py +537 -0
  91. mindmap_synaptome-0.1.0/src/synaptome/results/normality.py +37 -0
  92. mindmap_synaptome-0.1.0/src/synaptome/results/omnibus.py +37 -0
  93. mindmap_synaptome-0.1.0/src/synaptome/results/pairwise.py +159 -0
  94. mindmap_synaptome-0.1.0/src/synaptome/results/run.py +54 -0
  95. mindmap_synaptome-0.1.0/src/synaptome/results/tested.py +72 -0
  96. mindmap_synaptome-0.1.0/src/synaptome/results/timing.py +51 -0
  97. mindmap_synaptome-0.1.0/src/synaptome/study/__init__.py +38 -0
  98. mindmap_synaptome-0.1.0/src/synaptome/study/attachments.py +176 -0
  99. mindmap_synaptome-0.1.0/src/synaptome/study/info.py +169 -0
  100. mindmap_synaptome-0.1.0/src/synaptome/study/protocol.py +368 -0
  101. mindmap_synaptome-0.1.0/src/synaptome/study/reduce.py +213 -0
  102. mindmap_synaptome-0.1.0/src/synaptome/study/study.py +991 -0
  103. mindmap_synaptome-0.1.0/src/synaptome/study/units.py +516 -0
  104. mindmap_synaptome-0.1.0/src/synaptome/study/values.py +117 -0
  105. mindmap_synaptome-0.1.0/src/synaptome/study/variables.py +717 -0
  106. mindmap_synaptome-0.1.0/tests/conftest.py +25 -0
  107. mindmap_synaptome-0.1.0/tests/unit/baseline/test_image_agreement.png +0 -0
  108. mindmap_synaptome-0.1.0/tests/unit/baseline/test_image_along.png +0 -0
  109. mindmap_synaptome-0.1.0/tests/unit/baseline/test_image_box.png +0 -0
  110. mindmap_synaptome-0.1.0/tests/unit/baseline/test_image_comparison.png +0 -0
  111. mindmap_synaptome-0.1.0/tests/unit/baseline/test_image_ecdf.png +0 -0
  112. mindmap_synaptome-0.1.0/tests/unit/baseline/test_image_forest.png +0 -0
  113. mindmap_synaptome-0.1.0/tests/unit/test_datasets_toy.py +318 -0
  114. mindmap_synaptome-0.1.0/tests/unit/test_engine_bootstrap.py +261 -0
  115. mindmap_synaptome-0.1.0/tests/unit/test_engine_cluster.py +149 -0
  116. mindmap_synaptome-0.1.0/tests/unit/test_engine_correction.py +81 -0
  117. mindmap_synaptome-0.1.0/tests/unit/test_engine_effect_sizes.py +223 -0
  118. mindmap_synaptome-0.1.0/tests/unit/test_engine_ess.py +49 -0
  119. mindmap_synaptome-0.1.0/tests/unit/test_engine_hypothesis.py +411 -0
  120. mindmap_synaptome-0.1.0/tests/unit/test_engine_intervals.py +203 -0
  121. mindmap_synaptome-0.1.0/tests/unit/test_estimates_registry.py +124 -0
  122. mindmap_synaptome-0.1.0/tests/unit/test_estimates_run.py +437 -0
  123. mindmap_synaptome-0.1.0/tests/unit/test_hypotheses_registry.py +119 -0
  124. mindmap_synaptome-0.1.0/tests/unit/test_hypotheses_run.py +530 -0
  125. mindmap_synaptome-0.1.0/tests/unit/test_io_atomic.py +41 -0
  126. mindmap_synaptome-0.1.0/tests/unit/test_io_syn.py +418 -0
  127. mindmap_synaptome-0.1.0/tests/unit/test_package.py +7 -0
  128. mindmap_synaptome-0.1.0/tests/unit/test_plot_accessor.py +169 -0
  129. mindmap_synaptome-0.1.0/tests/unit/test_plot_data.py +170 -0
  130. mindmap_synaptome-0.1.0/tests/unit/test_plot_figure.py +13 -0
  131. mindmap_synaptome-0.1.0/tests/unit/test_plot_results.py +286 -0
  132. mindmap_synaptome-0.1.0/tests/unit/test_plot_style.py +54 -0
  133. mindmap_synaptome-0.1.0/tests/unit/test_public_api.py +55 -0
  134. mindmap_synaptome-0.1.0/tests/unit/test_questions_base.py +142 -0
  135. mindmap_synaptome-0.1.0/tests/unit/test_questions_compare.py +94 -0
  136. mindmap_synaptome-0.1.0/tests/unit/test_questions_compare_along.py +47 -0
  137. mindmap_synaptome-0.1.0/tests/unit/test_questions_design.py +268 -0
  138. mindmap_synaptome-0.1.0/tests/unit/test_questions_distribution.py +44 -0
  139. mindmap_synaptome-0.1.0/tests/unit/test_questions_fingerprint.py +93 -0
  140. mindmap_synaptome-0.1.0/tests/unit/test_questions_resolve.py +272 -0
  141. mindmap_synaptome-0.1.0/tests/unit/test_results_base.py +102 -0
  142. mindmap_synaptome-0.1.0/tests/unit/test_results_cluster.py +73 -0
  143. mindmap_synaptome-0.1.0/tests/unit/test_results_correct.py +106 -0
  144. mindmap_synaptome-0.1.0/tests/unit/test_results_describe.py +71 -0
  145. mindmap_synaptome-0.1.0/tests/unit/test_results_estimate.py +120 -0
  146. mindmap_synaptome-0.1.0/tests/unit/test_results_format.py +255 -0
  147. mindmap_synaptome-0.1.0/tests/unit/test_results_normality.py +32 -0
  148. mindmap_synaptome-0.1.0/tests/unit/test_results_omnibus.py +49 -0
  149. mindmap_synaptome-0.1.0/tests/unit/test_results_pairwise.py +156 -0
  150. mindmap_synaptome-0.1.0/tests/unit/test_results_timing.py +137 -0
  151. mindmap_synaptome-0.1.0/tests/unit/test_study.py +31 -0
  152. mindmap_synaptome-0.1.0/tests/unit/test_study_info.py +93 -0
  153. mindmap_synaptome-0.1.0/tests/unit/test_study_protocol.py +116 -0
  154. mindmap_synaptome-0.1.0/tests/unit/test_study_reduce.py +299 -0
  155. mindmap_synaptome-0.1.0/tests/unit/test_study_units.py +245 -0
  156. mindmap_synaptome-0.1.0/tests/unit/test_study_values.py +467 -0
  157. mindmap_synaptome-0.1.0/tests/unit/test_study_variables.py +426 -0
  158. mindmap_synaptome-0.1.0/tests/unit/test_utils.py +89 -0
@@ -0,0 +1,28 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+
8
+ # Environments
9
+ .venv/
10
+
11
+ # Tooling
12
+ .pytest_cache/
13
+ .ruff_cache/
14
+ .coverage
15
+ coverage.xml
16
+ htmlcov/
17
+
18
+ # Notebooks
19
+ .ipynb_checkpoints/
20
+
21
+ # Docs
22
+ site/
23
+ .cache/
24
+
25
+ # Editors / OS
26
+ .vscode/
27
+ .idea/
28
+ .DS_Store
@@ -0,0 +1,446 @@
1
+ # Architecture — synaptome
2
+
3
+ > synaptome (distributed as `mindmap-synaptome`, part of the mindmap collection; imported as `synaptome`) is a
4
+ > Python library that keeps a research study's analysis-ready data in one portable object: who
5
+ > ran it and how (identity, protocol), which units were observed (a hierarchy such as `site > subject > session`),
6
+ > what each variable means (a strict data dictionary), and the values themselves. A `Study` can be saved as an
7
+ > open `.syn` file (Parquet + JSON) and handed to a collaborator. A separate, array-level statistics engine
8
+ > (`engine/`) provides the tests, estimators, confidence intervals, bootstrap, corrections and cluster
9
+ > permutation that analyses will use. `datasets/` builds toy studies with planted effects, one per study
10
+ > design. `questions/` turns "compare X by Y" into a resolved design (paired or independent, groups, pairs,
11
+ > n) and an analysis table. `estimates/` answers "how large?" and `hypotheses/` "is there a difference?"
12
+ > (two-group, omnibus, cluster and normality tests), as `results/` values that carry their question, data
13
+ > fingerprint and pre-registration timing (`study.verify`, `.synr` files, formatted tables, corrections across
14
+ > results). The protocol stores pre-specified questions with an amendment log. `plot/` draws data and results
15
+ > with plain Matplotlib. The documentation site (`docs/`, `mkdocs.yml`) renders concepts, the executed
16
+ > tutorials and the API reference.
17
+
18
+ ## 1. Big picture
19
+
20
+ ```mermaid
21
+ flowchart LR
22
+ user([User code / notebook])
23
+ study[Study<br/>study/study.py]
24
+ units[UnitHierarchy<br/>study/units.py]
25
+ vars[VariableDictionary<br/>study/variables.py]
26
+ store[ValueStore<br/>study/values.py]
27
+ meta[StudyInfo · Protocol · Attachments]
28
+ syn[(.syn folder / zip<br/>io/syn.py)]
29
+ engine[engine/<br/>plain arrays]
30
+ question[Question · Design<br/>questions/]
31
+ estimate[estimates/ registry + runner]
32
+ test[hypotheses/ registry + runner]
33
+ result[Estimate · Pairwise · Omnibus ·<br/>Cluster · Normality · Describe<br/>results/]
34
+ synr[(.synr file)]
35
+
36
+ user -->|add, add_units, to_df, select| study
37
+ user -->|compare, compare_along, distribution| question
38
+ question -->|to_df, units, reducers| study
39
+ question -->|q.estimate| estimate
40
+ question -->|q.test| test
41
+ test -->|effect sizes| estimate
42
+ test -->|engine tests| engine
43
+ estimate -->|engine functions| engine
44
+ estimate --> result
45
+ test --> result
46
+ user -->|syn.correct| result
47
+ result <-->|save / load_result| synr
48
+ result -.->|study.verify| study
49
+ study --> units
50
+ study --> vars
51
+ study --> store
52
+ study --> meta
53
+ study <-->|save / load / peek| syn
54
+ user -.->|arrays from to_df| engine
55
+ ```
56
+
57
+ `Study` is the only object users normally touch. It owns four parts that know nothing about each other's
58
+ internals: the unit hierarchy, the variable dictionary, the value store, and descriptive metadata. `io/syn.py`
59
+ reads and writes the whole thing. `engine/` is standalone: it works on NumPy arrays, and nothing in `study/`
60
+ calls it; `estimates/` and `hypotheses/` call it on a question's data.
61
+
62
+ ## 2. Components
63
+
64
+ | Component | Path | Responsibility | Talks to |
65
+ |---|---|---|---|
66
+ | 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` |
67
+ | 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/` |
68
+ | Reducers | `src/synaptome/study/reduce.py` | `parse_reduce`, `reduce_dim`, `reduce_level`: named reductions (`mean` … `slope`, `auc`, `("at", c)`) on long tables | — |
69
+ | 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 | — |
70
+ | 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) |
71
+ | Value store | `src/synaptome/study/values.py` | One long table per variable (`_uid`, dimension columns, `value`); `added_at` / `first_added_at`; `InferenceNotice` | — |
72
+ | 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) |
73
+ | Attachments | `src/synaptome/study/attachments.py` | Embedded files or path references, both with SHA-256 checksums | — |
74
+ | Storage | `src/synaptome/io/syn.py` | `.syn` writer/reader (format 2: `questions/`, first-added times; reads format 1), `peek`, partial `load(variables=...)` | `study/*` |
75
+ | Atomic writes | `src/synaptome/io/_atomic.py` | `atomic_replace`: write elsewhere, then swap in | — |
76
+ | 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 |
77
+ | 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) |
78
+ | 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) |
79
+ | 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` |
80
+ | 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` |
81
+ | 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` |
82
+ | 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` |
83
+ | 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/` |
84
+ | Helpers | `src/synaptome/_utils.py` | JSON-safe conversion, filter freezing/serialization, `match_values` (subset/select matching) | — |
85
+
86
+ ### Engine files
87
+
88
+ | File | Contents |
89
+ |---|---|
90
+ | `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` |
91
+ | `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), ε² |
92
+ | `engine/intervals.py` | Analytic CIs: t (optional n_eff), Welch, signed-rank and Mann-Whitney (Hodges-Lehmann), exact binomial (median), Wilson, Newcombe, odds ratio |
93
+ | `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) |
94
+ | `engine/correction.py` | `correct_pvalues` (none, Bonferroni, Holm, BH, BY) |
95
+ | `engine/ess.py` | `effective_sample_size` for serially correlated samples |
96
+ | `engine/cluster.py` | `cluster_permutation` (1-D, paired sign flips or independent label shuffles, exact enumeration when small) → `ClusterStatResult` |
97
+
98
+ Each estimator follows one signature per family: one sample `f(x)`, paired `f(x, y, paired=True)` (or
99
+ `f(x, y)` for paired-only estimators), independent `f(a, b)`. Positive always means the first sample is
100
+ larger. Placeholder packages for the later layers (`hypotheses/`, `plot/`, and the test result modules of
101
+ `results/`) hold only a docstring naming the step that builds them.
102
+
103
+ ## 3. Main flow: adding values, then saving
104
+
105
+ 1. **`study.add("weight", df)`** (`study/study.py`). The input is either a long DataFrame (unit id columns,
106
+ dimension columns, value column) or an array for one unit, with ids and coordinates passed as keywords
107
+ (converted by `_array_to_frame`).
108
+ 2. **Level and dimensions.** If the variable is new, its level comes from the id columns
109
+ (`_infer_level`) and its dimensions from the remaining columns. `Variable.infer` (`study/variables.py`)
110
+ guesses the dtype, and an `InferenceNotice` warning shows the definition. If the variable already
111
+ exists, the given dimensions are checked against its definition.
112
+ 3. **Validation.** `Variable.validate` checks dtype, categories and range. `study.add` itself rejects
113
+ missing coordinates and duplicate addresses.
114
+ 4. **Units.** The first data that mentions a level creates that level's units. Afterwards, unknown ids
115
+ raise unless `create_units=True`. `UnitHierarchy.lookup` turns the id columns into internal `_uid`s.
116
+ 5. **Storage.** `ValueStore.put` (`study/values.py`) appends the rows. Writing to an address that already
117
+ holds a value raises unless `overwrite=True`.
118
+ 6. **Rollback.** On any error, the unit tables are restored from a snapshot and a newly inferred
119
+ definition is dropped, so a failed `add` leaves the study unchanged.
120
+ 7. **`study.save("trial.syn")`** → `io/syn.save`. `_write_tree` writes the files listed below into a
121
+ temporary folder, which is then zipped (path ends in `.syn`) or renamed into place. Only an existing
122
+ synaptome save is ever overwritten.
123
+ - `units/<level>.parquet`
124
+ - `values/<variable>.parquet`, each carrying its variable definition in Parquet metadata
125
+ - `questions/<title>.json`, the protocol's pre-specified questions
126
+ - `study.json` (info, protocol with its amendment log, levels, dictionary, first / last added times)
127
+ - `manifest.json` (format 2; format 1 still loads)
128
+ 8. **`syn.load(path)`** reverses this. It rebuilds levels, units and definitions, then replays the values
129
+ through `study.add(..., create_units=False)`, so hand-edited files are validated again.
130
+
131
+ ### Asking a question
132
+
133
+ 1. **`study.compare("error", by="method", subset=..., reduce=...)`** (`study/study.py`) imports
134
+ `questions/` and builds a `Compare`. Creation checks names only (outcome, `by`, reducers), so a question
135
+ can exist before its data.
136
+ 2. **First access to `q.design` / `q.data`** calls `questions/resolve.resolve`:
137
+ 1. `to_df(outcome)` gives the raw long table; `subset` filters coordinates, unit ids, or units by a
138
+ scalar variable (`match_values`);
139
+ 2. the unit is fixed (given, or the level the reductions lead to), and every level between the outcome
140
+ and the unit must be reduced (pseudo-replication guard);
141
+ 3. `by` is classified: a dimension → within-unit factor (paired); a variable at the unit's level →
142
+ between-unit factor (independent); a variable at a level crossed with the unit → within-unit
143
+ (paired); anything else raises;
144
+ 4. unused dimensions must be reduced or left with one coordinate; reductions run in the order written
145
+ (`reduce_dim`, `reduce_level` from `study/reduce.py`);
146
+ 5. the analysis table (unit ids, `by`, `along`, outcome) and the `Design` (groups, pairs, n per pair on
147
+ complete cases, scale) are built.
148
+ 3. The result is memoized on the question. **`q.data_key`** (`questions/fingerprint.py`) hashes the sorted
149
+ table and the meaning-bearing fields of the definitions read.
150
+ 4. **`q.to_dict()`** records the roles (no values); `study.question(spec)` rebuilds it on any study.
151
+
152
+ ### Computing an estimate
153
+
154
+ 1. **`q.estimate("hodges_lehmann", ci="analytic")`** (`questions/base.py`) imports `results/estimate.py`
155
+ (results sit above estimates) and calls `run_estimate`.
156
+ 2. **`estimates/run.compute_estimate`** looks the estimator up (`estimates/registry.py`) and checks it
157
+ against `q.design`: question kind (pairs need `compare`), paired / independent, binary, scale, ordered
158
+ unit, interval availability. Each refusal names the estimators or settings that fit.
159
+ 3. Rows come from `q.data` (per group) or `q.pair_data(a, b)` (per pair), per `along` coordinate. Analytic
160
+ intervals are the registry's engine functions (`n_eff` for an ordered unit); bootstrap uses
161
+ `engine.bootstrap_draws` / `jackknife_*` / `bootstrap_interval` with the recorded seed, or the draws of a
162
+ replicate variable, resolved like the outcome (`resolve(..., keep=(draw_dim,))`).
163
+ 4. `run_estimate` wraps the table and method in an `EstimateResult` with the question's `to_dict()`,
164
+ `data_key`, time and versions. `result.save()` writes a `.synr` zip; `study.verify(result)` rebuilds the
165
+ question on the current study and compares `data_key`.
166
+
167
+ ### Running a test
168
+
169
+ 1. **`q.test("wilcoxon", alternative="less")`** (`questions/base.py`) imports `results/run.py` and calls
170
+ `run_test`, which picks the result type from the registry's `result` (pairwise, omnibus, cluster,
171
+ normality).
172
+ 2. **`hypotheses/run.compute_test`** looks the test up (`hypotheses/registry.py`) and checks it against
173
+ `q.design`: kind (`compare`), paired / independent, binary, scale, the ordered-unit rule (refused with the
174
+ measured effective sample size unless `assume_independent=True`; `ttest_ess` only there), `offset`.
175
+ 3. Per pair, the engine test runs on `q.pair_data(a, b)`; `bootstrap` instead takes its estimator's draws from
176
+ `compute_estimate(..., return_draws=True)` and reads the p value with `engine.bootstrap_pvalue`. Effect
177
+ sizes are `compute_estimate` tables joined on the pair, so they equal `q.estimate`. The p values are
178
+ corrected across the pairs (`engine.correct_pvalues`).
179
+ Omnibus tests read `group_samples` (one matched sample per group); cluster tests pivot each pair to units ×
180
+ coordinates in `along` order and call `engine.cluster_permutation` (corrected by `cluster_correction`,
181
+ family `"cluster"` or `"pair"`); normality tests read per group, or each pair's differences when paired.
182
+ 4. `run_test` wraps it in its result (extra tables such as `draws`, `pairs`, `curve`, `null` saved in `.synr`).
183
+ `q.describe()` goes through `results/describe.run_describe` instead.
184
+ `result.correct(...)` and `syn.correct([...])` (one family across results) return new results;
185
+ `to_markdown()` / `to_frame(pretty=True)` format it through `results/format.py`.
186
+
187
+ ### Pre-specifying a question
188
+
189
+ 1. **`study.protocol.add_question(q, status="primary")`** (`study/protocol.py`) stores `q.to_dict()` with its
190
+ status and the current time (`Registration`). Only names are checked, so it works before any value.
191
+ 2. **`study.save`** writes each registration to `questions/<safe title>.json`, the amendment log and the
192
+ first / last added times to `study.json` (`io/syn.py`); `load` restores them, `peek` lists them.
193
+ 3. **`study.protocol.questions[title]`** rebuilds the question with `study.question(spec)` on the current data
194
+ (the protocol is bound to its study by the `Study.protocol` setter).
195
+ 4. Every result is stamped by **`results/timing.timing(question)`**: `protocol.match` (same title and analysis)
196
+ gives the registration; the variables read are the resolved definitions; "before data" when the
197
+ registration precedes the earliest `first_added_at` among them.
198
+
199
+ ### Drawing a data view
200
+
201
+ 1. **`study.plot.violin("error", x="method", subset=...)`**: the `study.plot` property imports `plot/`
202
+ lazily and returns a `PlotAccessor`.
203
+ 2. **`_data.view_frame`** reads `study.to_df(var, with_=..., reduce=...)`, filters with `subset`, collapses to
204
+ one value per `unit` if asked, and records what is pooled (values, units, dimensions left).
205
+ 3. **`_data.summary_table`** computes what is drawn (centers, intervals, box statistics); colours come from
206
+ `style.colors` (position among all levels of the variable).
207
+ 4. **`_draw`** renders those numbers only; the view returns a `Plot` with `data`, `points` and `artists`.
208
+
209
+ ### Drawing a result
210
+
211
+ 1. **`r.plot()`** (`results/base.py`) imports `plot/results.plot_result`, which picks the view for the type and
212
+ draws on `r.question.study`; `study.plot.comparison(r)` etc. draw on that study.
213
+ 2. **`_check`** rebuilds the question from `r.question_spec` on the study and compares `data_key`: a mismatch
214
+ raises (out of date).
215
+ 3. The view draws the question's data (`question.data`, `pair_data`, `draws`, `curve`) through the same
216
+ `_data` / `_draw` helpers as data views, and the result's own numbers (verdicts, effect sizes oriented
217
+ with `vs()`); brackets, annotations, forest rows and cluster bars are in `Plot.data` / `artists`.
218
+
219
+ ## 4. Data model
220
+
221
+ ```mermaid
222
+ erDiagram
223
+ Study ||--|| StudyInfo : info
224
+ Study ||--|| Protocol : protocol
225
+ Study ||--|| UnitHierarchy : units
226
+ UnitHierarchy ||--|{ Level : levels
227
+ Level }o--o{ Level : "parents (DAG)"
228
+ Study ||--|| VariableDictionary : variables
229
+ VariableDictionary ||--o{ Variable : defines
230
+ Variable }o--|| Level : "attached to"
231
+ Variable ||--o{ Dim : "shape"
232
+ Variable |o--o{ Variable : "replicates_of"
233
+ Variable ||--o{ Value : "observed as"
234
+ Study ||--o{ Attachment : attachments
235
+ Protocol ||--o{ Registration : "pre-specified questions"
236
+ ```
237
+
238
+ A value's address is *(unit at the variable's level, a coordinate on each dimension)*. Unit attributes such as
239
+ group, age and sex are not a separate concept. `add_units` stores them as scalar variables at that level.
240
+
241
+ ## 5. Where do I change X?
242
+
243
+ - **Add a variable field** (e.g. a new metadata key) → `Variable` in `study/variables.py`. It must also
244
+ round-trip through `to_dict`/`from_dict`.
245
+ - **Change what counts as a valid value** → `Variable.validate` and the `_to_*` converters in
246
+ `study/variables.py`.
247
+ - **Change dtype or level inference** → `_infer_dtype` in `study/variables.py`, `Study._infer_level` in
248
+ `study/study.py`.
249
+ - **Change the level shorthand or hierarchy rules** → `UnitHierarchy.define` / `add_level` / `paths` in
250
+ `study/units.py`.
251
+ - **Add a view or manipulation** (`to_df`, `table`, `select`, …) → `study/study.py`.
252
+ - **Add a reducer** → `REDUCERS` and `reduce_dim` in `study/reduce.py` (and `LEVEL_REDUCERS` if it makes
253
+ sense for unordered units).
254
+ - **Change how levels are reduced or joined** → `Study._reduce_frame`, `_reduction_chain`, `_join` in
255
+ `study/study.py`.
256
+ - **Change replicate rules** → `Variable.__post_init__` and `_check_replicate` in `study/variables.py`;
257
+ dependents are guarded in `VariableDictionary.update` / `remove`.
258
+ - **Change the on-disk format** → `io/syn.py` (`_write_tree`, `load`). Bump `FORMAT_VERSION` when old
259
+ readers would misread the files.
260
+ - **Add a statistical test or estimator** → `engine/hypothesis.py` or `engine/effect_sizes.py`; an analytic
261
+ interval → `engine/intervals.py`. Export it in `engine/__init__.py`.
262
+ - **Change how bootstrap intervals or p-values are read from draws** → `engine/bootstrap.py`
263
+ (`bootstrap_interval` and `bootstrap_pvalue` must stay consistent with each other).
264
+ - **Add a study-level field** (ethics, funding, …) → `study/info.py` or `study/protocol.py`.
265
+ - **Add or change a toy study** → `datasets/toy.py` (export it in `datasets/__init__.py`). It must define
266
+ every variable explicitly, list its planted effects (with at least one null) in the docstring and in
267
+ `_planted(...)` entries, and get a recovery test in `tests/unit/test_datasets_toy.py`.
268
+ - **Add a question kind** → a `Question` subclass in `questions/` with its `kind`, `_role_names` and
269
+ `_check_roles`; resolution goes through `questions/resolve.py`; add an entry point in `study/study.py`.
270
+ - **Change how paired / independent is decided, or a guard rail** → `_classify_by` and the checks in
271
+ `resolve()` (`questions/resolve.py`); error wording uses between-/within-unit factor vocabulary.
272
+ - **Change what `data_key` depends on** → `_FIELDS` / `_DIM_FIELDS` in `questions/fingerprint.py` (bump
273
+ `VERSION` if old keys must stop matching).
274
+ - **Change a dimension's ordering rules** → `Dim.effective_scale` and `check_dim_coordinates`
275
+ (`study/variables.py`), the scale checks in `reduce_dim` (`study/reduce.py`).
276
+ - **Add an estimator** → an `Estimator` entry in `estimates/registry.py` (engine function per design,
277
+ analytic interval if any, scales, `bounded`, `flip`); the runner and `vs()` pick it up.
278
+ - **Change an estimator guard rail** → `_check_requirements` in `estimates/run.py`; wording shared with
279
+ tests (scales, serial correlation, `assume_independent`) in `estimates/requirements.py`.
280
+ - **Add a test** → an engine function (`engine/hypothesis.py`) and a `Test` entry in
281
+ `hypotheses/registry.py` (answers, designs, scales, binary, params, default effect sizes, `result`);
282
+ `compute_test` and the result type pick it up. A new kind of result needs a `_<kind>_rows` builder in
283
+ `hypotheses/run.py`, a class in `results/` registered in `results/run._RESULTS`, and its `pretty_*` /
284
+ notes in `results/format.py`. Give the test a statistic symbol and a name in `results/format.py`.
285
+ - **Change summary statistics** → `results/describe.py` (columns per scale in `_INTERVAL` / `_ORDINAL` /
286
+ `_BINARY`).
287
+ - **Change the cluster correction families** → `cluster_correction` in `hypotheses/run.py` (used by the runner
288
+ and `ClusterResult.correct`).
289
+ - **Change a test guard rail** → `_check_requirements` / `_check_offset` / `_effect_sizes` in
290
+ `hypotheses/run.py`.
291
+ - **Change how p values are corrected or pooled** → `engine/correction.py` (methods),
292
+ `PairwiseResult.correct` (one result), `results/correct.py` (across results).
293
+ - **Change pre-specified questions or amendments** → `Protocol.add_question` / `remove_question` / `match`
294
+ in `study/protocol.py`; their storage in `_write_tree` / `load` (`io/syn.py`); the timing rule in
295
+ `results/timing.py` (and `timing_note` in `results/format.py`).
296
+ - **Add or change a data view** → `plot/accessor.py` (arguments, layout), `plot/_data.py` (numbers),
297
+ `plot/_draw.py` (artists). Keep statistics out of `_draw.py`. Baselines: regenerate with
298
+ `pytest --mpl-generate-path=tests/unit/baseline -k image` and check the images.
299
+ - **Add or change a result view** → `plot/results.py` (and its thin method in `plot/accessor.py`, its
300
+ `result.plot()` mapping in `_VIEWS`); annotation text in `plot/_data.py` (`annotation_lines`).
301
+ - **Change colours or fonts** → `plot/style.py` (`colors`, `set_style`, `STYLE`).
302
+ - **Add a documentation page** → `docs/` and the `nav` of `mkdocs.yml`; a public name → its package's
303
+ `__all__` and a NumPy docstring (it then appears in `docs/reference/`); tutorials are in the site through the
304
+ `docs/tutorials` symlink, and links between them are rewritten by `docs/_hooks/notebook_links.py`.
305
+ - **Change formatted tables** → `results/format.py` (`format_p`, `format_number`, `pretty_pairwise`,
306
+ `pretty_estimate`, the notes); `Result.to_frame` / `to_markdown` in `results/base.py`.
307
+ - **Change what a result stores or how `.synr` is written** → `results/base.py` (`to_dict`, `save`,
308
+ `load_result`; bump `RESULT_FORMAT_VERSION` for incompatible changes).
309
+ - **Change how `vs()` reorients** → `EstimateResult.vs` and `_flip` in `results/estimate.py`,
310
+ `PairwiseResult.vs` in `results/pairwise.py` (also flips `alternative` and `offset`).
311
+ - **Change a public API used in a tutorial** → update the notebook in `tutorials/` in the same change.
312
+ Notebooks are committed without outputs; `tutorials/README.md` lists them in order.
313
+
314
+ ## 6. Key decisions
315
+
316
+ - **Definitions are separate from values.** A variable is defined once and observed many times, which
317
+ makes strict validation possible.
318
+ - **Validation is strict after the first values.** Inference makes quick work easy, and strictness
319
+ afterwards catches typos in ids and categories.
320
+ - **Within-unit factors are dimensions, between-unit factors are variables.** Analyses can then tell
321
+ paired from independent data without being told.
322
+ - **Repetitions are unit levels.** Trials, seeds and folds go in the unit hierarchy, not in dimensions,
323
+ so collapsing them is an explicit step.
324
+ - **The hierarchy is a DAG, not a tree.** This is needed for crossed designs (`trial < subject * stimulus`).
325
+ - **Ids are stored as given and made unique internally.** "Trial 1" can repeat under every subject.
326
+ - **Storage is Parquet + JSON.** Any Parquet reader (pandas, R, DuckDB) can open the data without
327
+ synaptome.
328
+ - **Saves are atomic, and only synaptome saves are overwritten.** A crash or a typo'd path can't
329
+ destroy data.
330
+ - **`engine/` works on arrays and does not depend on `Study`.** It is testable on its own and reusable
331
+ outside the study model. It needs no MNE: the cluster permutation is plain NumPy/SciPy.
332
+ - **A test's `offset` moves only the p-value.** Effect sizes always describe the raw difference;
333
+ `alternative` stays two-sided unless asked.
334
+ - **Reductions are explicit.** Views and questions never average repetitions silently: `table(level)`
335
+ refuses a variable with several values per unit until `reduce=` says how to collapse them.
336
+ - **Joins only go up the hierarchy.** Each row then gets exactly one value; one-to-many relations must be
337
+ reduced first.
338
+ - **Upstream resampling is a replicate variable, not a unit level.** Draws aren't independent units;
339
+ `replicates_of` links them to the variable they resample.
340
+ - **synaptome never processes data.** Values arrive already derived; provenance is documented, not run.
341
+ - **Questions read the design off the data model.** Nobody passes `paired=True`: where `by` lives (a
342
+ dimension, a variable at the unit's level, a variable at a crossed level) decides. Reductions are never
343
+ guessed, and each pair of a comparison keeps its own complete cases.
344
+ - **Questions use only the study's public API.** `resolve.py` builds on `to_df`, `units` and the reducers;
345
+ the `study.compare`-style entry points import `questions/` lazily, the only upward reference.
346
+ - **Estimates refuse what doesn't fit.** Scale, binary outcome, design and serial correlation are checked
347
+ before computing, and the error lists what fits: guard rails are a feature for users who aren't
348
+ statisticians. Bootstrap is seeded by default, so every result is reproducible.
349
+ - **Serial correlation is refused, with a recorded override.** An ordered unit (`unit="time"`) refuses tests
350
+ and intervals that assume independence, naming the effective sample size; `ttest_ess` is allowed, and
351
+ `assume_independent=True` is recorded in the result and its tables. synaptome can't check independence,
352
+ so the user states it.
353
+ - **Omnibus and pairwise tests are separate calls.** Nothing runs behind the user's back after a significant
354
+ omnibus test; normality tests are diagnostics, uncorrected by default.
355
+ - **Timing is recorded by synaptome, not declared.** "Before data" compares the protocol's own registration
356
+ time with the first time each variable read got values; amendments are logged and re-timed.
357
+ - **A result is drawn only on its own data.** Result views rebuild the question and refuse a changed
358
+ `data_key`; they draw the result's verdicts, never re-test.
359
+ - **Figures compute nothing they don't report.** Plain matplotlib (no seaborn); `_data.py` computes every
360
+ number drawn and `Plot.data` returns it. Data views pool and say so; questions guard the statistics.
361
+ - **Corrections make new results.** `result.correct` and `syn.correct([...])` (one family pooled across
362
+ results, e.g. per sensor type) never change a result in place; the family is recorded in
363
+ `method["correction"]`.
364
+ - **Results are values.** A result holds its question's spec and the `data_key` it read; nothing is cached
365
+ in the study. `study.verify(result)` re-asks the question and compares keys.
366
+ - **Toy studies carry their own truth.** Planted effects live in `study.info.extra["planted"]`, shaped like
367
+ the question that recovers them (`outcome`, `by`, `contrast`, `value`, optional `subset` / `reduce` /
368
+ `unit` / `along`), so they survive save/load and tests read them instead of hard-coding numbers.
369
+ - **Scale (2026-11, laptop).** `method_comparison(n_sources=7000)`, about 1.95 M values, the size of the
370
+ mindmap-bem manuscript: generating and adding 0.9 s, `to_df(reduce={"source": "median"})` 0.1 s, `save`
371
+ 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
372
+ batch, since each `add` merges with what is stored; append per subject or run, not per sample.
373
+
374
+ ## 7. Glossary
375
+
376
+ - **Level**: a kind of unit (`subject`, `session`, `trial`). Levels form a DAG through their parents.
377
+ - **Unit**: one member of a level, with an id and links to its parents. Always a statistical unit; the unit of
378
+ measurement of a variable or dimension is its `measurement_unit` (`"kg"`, `"ms"`).
379
+ - **Variable**: a defined quantity attached to one level, with a dtype, a scale and optional dimensions.
380
+ - **Dimension (`Dim`)**: an ordered or within-unit axis of a variable (time, channel, condition). It is
381
+ not a unit level.
382
+ - **Address**: (unit, coordinates). Exactly one value lives at each address.
383
+ - **Replicate variable**: resampled values of another variable (`replicates_of`), with one extra dimension
384
+ of kind `replicate` (bootstrap draw) or `jackknife` (left-out unit).
385
+ - **Reduction**: collapsing a dimension or a unit level to one value with a named reducer (`reduce=`).
386
+ - **Inferred definition**: a definition guessed from the first values and flagged with `InferenceNotice`.
387
+ - **`.syn`**: the storage layout, as a folder or an uncompressed zip.
388
+ - **Question**: what is compared on which data (`outcome`, `by`, `subset`, `reduce`, `unit`, ...); no numbers,
389
+ no test. **Design**: what a question resolves to (paired or independent, groups, pairs, n).
390
+ - **Between- / within-unit factor**: a factor constant within each unit (a variable at the unit's level) or
391
+ varying within it (a dimension, or a variable at a crossed level); gives independent / paired comparisons.
392
+ - **`data_key`**: the fingerprint of the data a question read.
393
+ - **Estimate / result**: an answer to "how large?" (`EstimateResult`), with `confidence` intervals; a result
394
+ is a plain value with its question, method, table and `data_key`, saved alone as a `.synr` file.
395
+ - **`vs()`**: a pair estimate or test reoriented around the reference so that positive means the reference is
396
+ better (a test's `alternative` and `offset` turn with it).
397
+ - **Test / `PairwiseResult`**: an answer to "is there a difference?", one row per pair with p, corrected p,
398
+ verdict and effect sizes. **Family**: the p values corrected together (a result's pairs, or several results
399
+ with `syn.correct`).
400
+ - **Omnibus test**: one test of all the groups at once ("do they differ at all?"). **Cluster**: neighbouring
401
+ coordinates whose t passes the cluster-forming threshold; its **mass** is the sum of their t.
402
+ - **Registration / amendment**: a question pre-specified in the protocol, with the time synaptome recorded;
403
+ a logged replacement or removal of one. **Timing**: before data / after data / not pre-specified / unknown.
404
+ - **Data view / `Plot`**: a figure of a variable's values (`study.plot.<view>`), and what it returns (axes,
405
+ numbers drawn, artists). **Pooled**: values of dimensions or levels not on the axes drawn together.
406
+ - **`assume_independent`**: the recorded statement that positions along an ordered unit are independent.
407
+ - **Dimension scale**: `Dim.scale`; numeric coordinates are interval by default, others nominal.
408
+ - **Toy study / planted effect**: a generated study from `synaptome.datasets`, and a true difference (or a
409
+ null, 0) built into it on purpose, recorded in `study.info.extra["planted"]`.
410
+
411
+ ## 8. Testing strategy
412
+
413
+ - Tests live in `tests/unit/test_<package>_<module>.py`, one file per module. Run them with `pytest`.
414
+ Warnings are errors (`filterwarnings = ["error"]` in `pyproject.toml`).
415
+ - Lint and format with `ruff check .` and `ruff format --check .`.
416
+ - CI (`.github/workflows/ci.yml`) runs lint, then the tests on Python 3.10–3.13 with coverage. It also
417
+ runs the tutorials (`tutorials/NN_topic.ipynb`) with `pytest --nbmake tutorials`. They double as
418
+ end-to-end checks of the public API. A `docs` job builds the site with `mkdocs build --strict` (tutorials
419
+ executed, griffe warnings on docstrings are errors); `.github/workflows/docs.yml` publishes it to GitHub
420
+ Pages on pushes to `main`.
421
+ - `tests/unit/test_public_api.py` checks that every public name and method has a docstring (the API
422
+ reference has no empty entry) and that `import synaptome` doesn't load Matplotlib.
423
+ - Figures: `Plot.data` is tested in the default run; six image baselines (`tests/unit/baseline/`) are compared
424
+ with `pytest --mpl`.
425
+
426
+ ## 9. Further reading
427
+
428
+ - `DESIGN.md`: the agreed model and API, and the dated decisions log (§14).
429
+ - `PLAN.md`: the build order. Steps 0–15 are done; 16 is the release.
430
+ - `tutorials/`: notebook 00 covers installation; 01–05 walk through the study, units, variables (including
431
+ replicate variables), values, views (including `reduce=`) and storage; 06 covers the engine on plain arrays;
432
+ 07 the toy studies; 08 questions; 09 estimates; 10 tests and corrections; 11 comparing along a dimension;
433
+ 12 pre-registration; 13 plotting.
434
+ - The documentation site (`docs/`): concept pages, the tutorials executed, the API reference; `README.md`,
435
+ `CHANGELOG.md`, `CONTRIBUTING.md`.
436
+
437
+ ---
438
+ <!-- architecture-skill metadata — keep at bottom; used by /architecture updates -->
439
+ <details><summary>Doc metadata</summary>
440
+
441
+ - project_type: library
442
+ - sections: [big-picture, components, main-flow, data-model, where-to-change, decisions, glossary, testing, further-reading]
443
+ - last_commit: 80cf5b19a216052d358167d615ee68374f6eaa0e
444
+ - last_updated: 2026-11-26
445
+ - project_notes: Feature-complete for v0.1 (steps 0–15); the release (PyPI) is step 16.
446
+ </details>
@@ -0,0 +1,42 @@
1
+ # Changelog
2
+
3
+ All notable changes to synaptome. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
4
+ versions follow [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.0] - 2026-11-27
9
+
10
+ First release. The package is distributed as `mindmap-synaptome` (part of the
11
+ mindmap collection) and imported as `synaptome`; `.syn` and `.synr` files keep their `synaptome` format tags.
12
+
13
+ ### Added
14
+
15
+ - **Study**: units in a hierarchy of levels, nested or crossed (`"site > subject"`, `"trial < subject *
16
+ stimulus"`); a data dictionary of variables with dtype, scale, dimensions, measurement unit and replicate
17
+ variables; inference from the first values, strict validation afterwards; values at one address each;
18
+ identity, protocol and attachments.
19
+ - **Views and manipulation**: `to_df` (joins up the hierarchy, named reductions), `table`, `describe`, `select`,
20
+ `drop`, `rename`, `copy`, `concat`.
21
+ - **Storage**: `.syn` files (a zip or folder of Parquet and JSON, format 2), `peek`, partial `load`, atomic saves.
22
+ - **Toy studies** (`synaptome.datasets`): eight seeded generators with planted effects, real and null.
23
+ - **Questions**: `compare`, `compare_along`, `distribution`; the design read from where factors live; complete
24
+ cases per pair; guard rails against pseudo-replication and unreduced data; `data_key` fingerprints;
25
+ `study.question`, `study.verify`.
26
+ - **Estimates**: per group, per pair and omnibus estimators with analytic or seeded bootstrap intervals, upstream
27
+ replicate draws, refusals naming what fits.
28
+ - **Tests**: Wilcoxon, paired t, t with the effective sample size, McNemar, Mann–Whitney, Student, Welch, bootstrap;
29
+ Friedman, repeated-measures ANOVA, Kruskal–Wallis, ANOVA; cluster permutation along a dimension; Shapiro–Wilk and
30
+ D'Agostino–Pearson; `alternative` and `offset`; default effect sizes; serial-correlation guard rail with a
31
+ recorded `assume_independent` override.
32
+ - **Results**: plain values with their question, settings, `data_key`, times and versions; `vs()`, `correct()`,
33
+ `syn.correct` across results, `differences()`, `draws()`, cluster `verdict()` and `curve()`; formatted tables
34
+ (`to_frame(pretty=True)`, `to_markdown()`); `.synr` files; `describe()`.
35
+ - **Pre-registration**: questions registered in the protocol, logged amendments, result timing ("before data",
36
+ "after data", "not pre-specified").
37
+ - **Plots**: data views (box, violin, bar, point, strip, line, scatter, distribution, histogram, ECDF,
38
+ Bland–Altman) that pool and say so; result views (comparison with brackets, differences, along with clusters,
39
+ forest of estimates, normality, omnibus) that refuse a stale result; `result.plot()`; stable colours.
40
+ - **Array statistics** (`synaptome.engine`): the tests, estimators, intervals, bootstrap, corrections, effective
41
+ sample size and cluster permutation on plain NumPy arrays.
42
+ - Fourteen tutorials and a documentation site.
@@ -0,0 +1,79 @@
1
+ # Contributing
2
+
3
+ Thank you for helping. mindmap-synaptome (imported as `synaptome`) is small and opinionated: read `DESIGN.md` (the model and API), `PLAN.md` (the
4
+ build order) and `ARCHITECTURE.md` (where things live) before a larger change, and open an issue first to discuss
5
+ it.
6
+
7
+ ## Setup
8
+
9
+ ```bash
10
+ git clone https://github.com/NinoHerve/mindmap-synaptome
11
+ cd mindmap-synaptome
12
+ uv sync --extra dev # add --extra docs to build the site
13
+ ```
14
+
15
+ ## Commands
16
+
17
+ ```bash
18
+ uv run pytest # unit tests (warnings are errors)
19
+ uv run pytest --nbmake tutorials # run every tutorial
20
+ uv run pytest --mpl tests/unit/test_plot_*.py # compare figures with the baselines
21
+ uvx ruff format . && uvx ruff check . # format + lint
22
+ uv run mkdocs serve # the documentation site, live
23
+ ```
24
+
25
+ All four checks (lint, tests, tutorials, `mkdocs build --strict`) run in CI on Python 3.10–3.13.
26
+
27
+ ## Code
28
+
29
+ - **Layers import downward only**: `engine` ← `study` / `io` ← `questions` ← `estimates` / `hypotheses` ←
30
+ `results` ← `plot`. The few upward references (`study.compare`, `study.plot`, `result.plot()`) import inside
31
+ the method.
32
+ - NumPy-style docstrings with `Parameters` / `Returns` for every public name, type hints,
33
+ `from __future__ import annotations`, lines up to 110 characters.
34
+ - Errors name the problem and the fix: `"Variable 'weight' has dimensions ['time'], not ['visit']."`.
35
+ - No caches and no stored results: results are values.
36
+ - Public names are exported from their package's `__init__.py` with `__all__`.
37
+ - New runtime dependencies only after discussion; optional extras are fine to propose.
38
+
39
+ ## Tests
40
+
41
+ - One file per module: `tests/unit/test_<package>_<module>.py`.
42
+ - For each feature: behaviour on a small hand-checkable example; reference values (SciPy, a published example,
43
+ an exact computation); each guard rail with `pytest.raises(..., match=...)`; edge cases (NaN, empty, one unit,
44
+ ties); round trips for anything saved.
45
+ - Use `synaptome.datasets` toy studies, and check that planted effects are found and null effects are not.
46
+ - Randomness is always seeded; the suite stays under a minute.
47
+ - Figures: `Plot.data` carries the numbers drawn; regenerate image baselines with
48
+ `uv run pytest --mpl-generate-path=tests/unit/baseline -k image` and look at them.
49
+
50
+ ## Tutorials
51
+
52
+ Notebooks in `tutorials/`, named `NN_topic.ipynb`, listed in `tutorials/README.md`, committed **without outputs**.
53
+ Each opens with what the reader will learn and needs to know, has short cells each introduced by a sentence or
54
+ two on *why*, closes with a pointer to the next tutorial, and runs in under 30 seconds. When an API used by a
55
+ tutorial changes, update the tutorial in the same change.
56
+
57
+ ## Documentation
58
+
59
+ Pages live in `docs/` (concepts) and are built with MkDocs Material; the API reference comes from the docstrings
60
+ and the tutorials are executed at build. Record non-obvious decisions in `DESIGN.md` §14 with the date, and keep
61
+ `ARCHITECTURE.md` current.
62
+
63
+ ## Pull requests
64
+
65
+ Keep a pull request to one topic, with tests, tutorial and docs updates, a green CI and an entry under
66
+ `[Unreleased]` in `CHANGELOG.md`.
67
+
68
+ ## Releasing
69
+
70
+ The version lives in one place, `__version__` in `src/synaptome/__init__.py` (the package build reads it from
71
+ there). To release:
72
+
73
+ 1. Set `__version__` to the new version (for example `0.1.0`) and turn `[Unreleased]` in `CHANGELOG.md` into
74
+ that version with the date; commit on `main`.
75
+ 2. Tag and push: `git tag v0.1.0 && git push origin v0.1.0`.
76
+
77
+ The `publish` workflow builds the package, refuses a tag that doesn't match `__version__`, tests the built
78
+ wheel, uploads to TestPyPI, then to PyPI. Running it by hand from the Actions tab stops after TestPyPI (a dry
79
+ run). Afterwards set `__version__` to the next development version (for example `0.2.0.dev0`).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nino Herve
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.