Refactor and Publication Rules
This document is the standing contract for refactoring Synaptipy before a methods publication or release. It answers three questions reviewers and future contributors should not have to infer from code history: where code belongs, what behavior must remain stable, and what evidence is required before merging.
Layer Boundaries
src/synaptipy/core/
Core contains the scientific model and numerical behavior.
Keep it GUI-free: no
PySide6,pyqtgraph, widgets, dialogs, clipboard, or application window imports.Put analysis algorithms in
core/analysis/and register public analyses with@AnalysisRegistry.register.Put reusable signal operations in
signal_processor.pyorprocessing_pipeline.pywhen they are not tied to a single analysis module.Return explicit metrics and flags rather than raising for biologically invalid traces. Invalid fits should produce
NaNplus a reason/quality flag where the surrounding API already supports one.Preserve deterministic behavior. Random data belongs only in tests or examples and must use a fixed generator seed.
src/synaptipy/infrastructure/
Infrastructure owns external formats and serialization.
File reading belongs in
infrastructure/file_readers/.CSV/NWB/Prism export belongs in
infrastructure/exporters/.Do not put electrophysiology algorithms here. Convert external data into
Recording/Channelobjects, then call core code.Exported tabular outputs must preserve provenance: source file, channel, trial, analysis name, parameters, software version, and timestamp.
NWB exports must remain schema-valid and should prefer standard icephys containers before custom processing tables.
src/synaptipy/application/
Application owns user workflows.
GUI widgets, dialogs, Qt workers, controllers, plugin loading, preferences, and sessions stay here.
GUI code may call core and infrastructure code; core and infrastructure must not call GUI code.
Long operations must run off the UI thread.
Interactive parameters must map to the same dictionary shape used by
BatchAnalysisEngine, so GUI and headless runs stay equivalent.Headless reviewer/reproduction workflows belong in
application/cli/, not in GUI classes.
paper/, validation/, examples/, and docs/
paper/contains reproducibility scripts, data manifests, generated paper figures, and paper-specific environment files.validation/contains independent checks and reports for algorithmic accuracy.examples/contains user-facing demonstrations and small fixture recordings.docs/contains source documentation. Generated docs stay out of commits.
Expected Behavior That Must Not Regress
pip install -e ".[dev]"exposessynaptipyandsynaptipy-batch.python -m synaptipy --versionprints the package version.synaptipy-batch run --pipeline PIPELINE.json --output results.csv FILE...writes a CSV and companion provenance JSON without importing GUI widgets.BatchAnalysisEnginemust accept the same pipeline dictionaries used by the GUI.Batch rows must remain traceable to file, channel, trial, scope, analysis, and sampling rate.
CSV and NWB exports must not silently drop source/provenance metadata.
Paper reproduction must have a lightweight
--check-onlypath that validates scripts and manifests without requiring AllenSDK downloads.Paper table generation must be manifest-driven, not hidden in hardcoded IDs.
Refactor Rules
Keep behavior changes separate from mechanical moves when possible.
If an algorithm changes, update the algorithmic definition, golden tests, and paper/validation outputs in the same pull request.
If a public metric key changes, either preserve the old key as an alias or document the breaking change in
CHANGELOG.md.If a dependency pin changes, document why and run the CI matrix or the closest available local subset.
Do not add new generated outputs unless they are intentionally publication artifacts.
Do not add hidden data selection criteria in scripts. Put them in a manifest.
Prefer narrow helpers over broad abstractions unless two or more modules need the same behavior.
Every reviewer-facing script should support
--help; expensive scripts should also support--check-onlyor a tiny smoke mode.
Merge Checklist
Formatting:
black src/ tests/andisort src/ tests/Static checks:
flake8 src/ tests/Core tests:
python -m pytest tests/core tests/infrastructureGUI-sensitive tests: run with
QT_QPA_PLATFORM=offscreenorxvfb-runPaper smoke check:
python paper/scripts/paper_figures/generate_paper_figures.py --check-only
python paper/scripts/generate_paper_tables.py --check-only
Reproduction evidence: attach or commit updated provenance JSON when paper tables/figures are regenerated intentionally.