Writing Custom Analysis Plugins for Synaptipy
This guide explains how to add custom analysis functions and signal
preprocessors to Synaptipy without modifying any Synaptipy source code.
Write a single Python file, save it in ~/.synaptipy/plugins/, and load it into
the GUI Analyser and headless batch engine.
Table of Contents
1. Overview - How the Plugin System Works
Synaptipy has a central AnalysisRegistry class that maps named analysis
and preprocessing functions to the GUI and batch engine. Register a function by
decorating it with @AnalysisRegistry.register(...) (or
@AnalysisRegistry.register_processor(...) for signal preprocessors). The
decorator stores the callable together with its UI parameter definitions, plot
overlays, protocol declarations, and display label.
At startup (or during an in-process hot-reload), Synaptipy:
Loads all built-in analyses and preprocessors from
src/synaptipy/core/analysis/and snapshots their keys as the immutable core registry set.Scans
~/.synaptipy/plugins/for personal, downloaded, or third-party plugins when Enable Custom Plugins is active in Edit > Preferences (Extensions group on the General tab). Example plugins can be installed on demand via Help > Download Example Plugins…; source checkouts and desktop bundles may also exposeexamples/plugins/directly. When a file with the same stem exists in both locations, the user copy in~/.synaptipy/plugins/takes precedence and logs a warning.Prompts for one-time user confirmation per SHA-256 content fingerprint before executing new or modified code from
~/.synaptipy/plugins/.Builds the Analyser GUI. After the five immutable core pillar tabs, every registered custom analysis automatically receives a
MetadataDrivenAnalysisTabcontaining parameter widgets, an optional Run button, a results table, and interactive plot overlays.
┌──────────────────────────────────────────────────────────┐
│ ~/.synaptipy/plugins/synaptic_charge.py │
│ │
│ @AnalysisRegistry.register( │
│ name="synaptic_charge", │
│ label="Synaptic Charge (AUC)", │
│ ui_params=[...], │
│ plots=[...] │
│ ) │
│ def run_auc(data, time, sampling_rate, **kwargs): │
│ ... │
│ return {"Charge_pC": -1.23, │
│ "Baseline_pA": -42.0, │
│ "_int_x": win_t, "_int_y": win_d} │
└──────────────────────────────────────────────────────────┘
│
v startup / hot-reload -> PluginManager.load_plugins()
┌──────────────────────────────────────────────────────────┐
│ AnalysisRegistry │
│ ├── passive_properties (core pillar 1) │
│ ├── single_spike (core pillar 2) │
│ ├── firing_dynamics (core pillar 3) │
│ ├── synaptic_events (core pillar 4) │
│ ├── evoked_responses (core pillar 5) │
│ └── synaptic_charge <-- YOUR PLUGIN │
└──────────────────────────────────────────────────────────┘
│
v GUI build -> auto-generated MetadataDrivenAnalysisTab
┌──────────────────────────────────────────────────────────┐
│ Analyser Tab: ... | Synaptic Events | Evoked Responses │
│ | Synaptic Charge (AUC) <-- │
│ ┌────────────────────────────────────────────┐ │
│ │ Search Window Start (s): [0.0000 ] │ │
│ │ Search Window End (s): [0.1000 ] │ │
│ │ Local Baseline (ms): [10.0 ] │ │
│ │ ────────────────────────────────────── │ │
│ │ Results: Charge_pC = -1.23 │ │
│ └────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────┘
No GUI code is required. The ui_params list generates the parameter
controls, and the plots list renders the trace overlays from declarative
metadata.
Scientific Input Declarations
Plugins can declare the recording context required for their output to be scientifically valid:
@AnalysisRegistry.register(
name="my_evoked_metric",
requires_secondary_channel={
"param_name": "ttl_data",
"label": "TTL / Stimulus Channel:",
},
protocol_requirements={
"families": ("optogenetic", "single_stim"),
"requires_stimulus_timing": True,
},
supported_channel_units=("pA",),
)
def run_my_evoked_metric(data, time, sampling_rate, **kwargs):
...
requires_secondary_channel must be a dictionary, not True. The GUI builds a
secondary channel selector from that dictionary. In a batch pipeline JSON, set
the top-level secondary_channel field to the target channel ID or native
channel name. supported_channel_units prevents a unit-specific plugin (such as
a picocoulomb charge integral) from executing on an incompatible channel.
2. Getting Started - Your First Plugin in 5 Minutes
Copy the starter template into your user plugin folder:
# macOS / Linux mkdir -p ~/.synaptipy/plugins cp src/synaptipy/templates/plugin_template.py ~/.synaptipy/plugins/my_analysis.py # Windows (PowerShell) New-Item -ItemType Directory -Force "$HOME\.synaptipy\plugins" Copy-Item src\synaptipy\templates\plugin_template.py ~\.synaptipy\plugins\my_analysis.py
Note: User plugin directory paths by platform:
Platform
Path
macOS / Linux
~/.synaptipy/plugins/Windows
C:\Users\<YourUsername>\.synaptipy\plugins\(or%USERPROFILE%\.synaptipy\pluginsin File Explorer)Open
my_analysis.pyin a text editor.Set a unique
name=and displaylabel=, configureui_paramsandplots, and implement your pure NumPy calculation.Load the plugin in Synaptipy:
If Synaptipy is closed, launch
synaptipy; plugins in~/.synaptipy/plugins/are discovered automatically at startup when Enable Custom Plugins is checked.If Synaptipy is already running, open Edit > Preferences (or Synaptipy > Preferences on macOS), toggle Enable Custom Plugins off and back on in the Extensions section, and click Apply or OK to hot-reload plugins in-process without restarting the application.
3. The Plugin File - Anatomy of a Custom Analysis
Every analysis plugin separates pure mathematical logic from registry metadata in two layers:
3.1 Part 1: Pure Analysis Logic
Write a standard Python function with explicit typed arguments. Do not import
GUI libraries (PySide6, PyQt6, pyqtgraph, or matplotlib.pyplot).
from typing import Any, Dict
import numpy as np
def calculate_area_under_curve(
data: np.ndarray,
time: np.ndarray,
sampling_rate: float,
baseline_start: float,
baseline_end: float,
window_start: float,
window_end: float,
) -> Dict[str, Any]:
"""Integrate baseline-subtracted current trace to obtain synaptic charge (pC)."""
if data.size == 0:
return {"error": "Empty data array"}
bl0 = int(np.searchsorted(time, baseline_start, side="left"))
bl1 = int(np.searchsorted(time, baseline_end, side="right"))
baseline = float(np.mean(data[bl0:bl1])) if bl1 > bl0 else 0.0
wi0 = int(np.searchsorted(time, window_start, side="left"))
wi1 = int(np.searchsorted(time, window_end, side="right"))
win_t = time[wi0:wi1]
win_d = data[wi0:wi1] - baseline
if win_t.size < 2:
return {"error": "Integration window too narrow (need >= 2 samples)"}
charge_pc = float(np.trapezoid(win_d, win_t))
return {
"Charge_pC": round(charge_pc, 6),
"Baseline_pA": round(baseline, 4),
"_int_x": win_t,
"_int_y": data[wi0:wi1],
"_base": baseline,
}
Rules for the pure logic function:
Accept explicit, typed arguments rather than unvalidated
**kwargs.Use NumPy vectorization (
np.trapezoid,np.searchsorted, boolean masks) rather than Python loops over sample arrays. Note thatnp.trapzwas removed in NumPy 2.0; always usenp.trapezoid.Handle empty arrays, degenerate windows, and near-zero denominators (using an epsilon guard such as
abs(denom) < 1e-9returningnp.nan) gracefully.Never import GUI packages.
3.2 Part 2: Registry Wrapper
Decorate a thin wrapper function with @AnalysisRegistry.register(...). The
wrapper extracts UI parameters from **kwargs, calls the pure logic function,
and returns a flat metrics dictionary.
from synaptipy.core.analysis.registry import AnalysisRegistry
@AnalysisRegistry.register(
name="synaptic_charge_basic", # unique internal identifier
label="Synaptic Charge (Basic)", # sub-tab label in the Analyser
expects_list=False, # True only for multi-trial statistics
supported_channel_units=("pA",),
ui_params=[...], # parameter widgets (see Section 4)
plots=[...], # plot overlays (see Section 5)
)
def run_auc_wrapper(
data: np.ndarray,
time: np.ndarray,
sampling_rate: float,
**kwargs: Any,
) -> Dict[str, Any]:
"""Registry wrapper for synaptic charge integration."""
return calculate_area_under_curve(
data=data,
time=time,
sampling_rate=sampling_rate,
baseline_start=float(kwargs.get("baseline_start", 0.0)),
baseline_end=float(kwargs.get("baseline_end", 0.05)),
window_start=float(kwargs.get("window_start", 0.05)),
window_end=float(kwargs.get("window_end", 0.3)),
)
The wrapper signature is fixed:
def wrapper(data: np.ndarray, time: np.ndarray, sampling_rate: float, **kwargs: Any) -> Dict[str, Any]:
...
Parameter |
Type |
Description |
|---|---|---|
|
|
1-D voltage or current trace for the selected sweep or average |
|
|
1-D time vector in seconds matching |
|
|
Sampling frequency in Hz |
|
|
Current |
3.3 Return Dict Conventions
Plugin wrappers should return a flat metrics dictionary (Dict[str, Any]).
AnalysisRegistry.execute(...) serves as the single normalization boundary: it
converts the returned dictionary into a canonical AnalysisResult object
(schema version 1) consumed by the GUI results table, plot manager, batch
engine, and CSV/NWB exporters.
return {
"My_Metric": 42.0,
"Baseline_pA": -55.2,
# Private keys prefixed with '_' feed plot overlays and are hidden from tables/CSV:
"_overlay_x": win_time,
"_overlay_y": win_data,
}
Key / Value Pattern |
Behaviour |
|---|---|
Public scalar keys ( |
Displayed in the GUI results table and exported as columns in wide/tidy CSVs. |
Private keys prefixed with |
Stored for plot overlays ( |
|
Displays the error message in the GUI status/results area instead of metric rows. |
Numeric scalars ( |
Formatted numerically ( |
Legacy nested dict ( |
Still accepted for backward compatibility; |
Note: Custom plugins vs. core pillar modules. Custom plugin wrappers return a flat
dictthatAnalysisRegistry.executewraps intosynaptipy.core.analysis.contracts.AnalysisResult. By contrast, the pure-logic functions inside Synaptipy’s five built-in pillar modules (passive_properties,single_spike,firing_dynamics,synaptic_events,evoked_responses) return typed dataclasses fromsynaptipy.core.results(RinResult,SingleSpikeResult,BurstResult, etc.). When calling a core logic function directly in Python rather than throughAnalysisRegistry.execute, read dataclass attributes (for exampleresult.rin_steady_state_mohm) rather than dictionary keys.
3.4 The expects_list Parameter
The expects_list keyword argument in @AnalysisRegistry.register(...)
controls how BatchAnalysisEngine and multi-trial scopes pass sweep data to
your wrapper:
Value |
|
When to use |
|---|---|---|
|
Single 1-D |
Single-trace metrics (charge transfer, EPSP AUC, tau, peak amplitude) |
|
Python |
Trial-to-trial variability metrics (optogenetic latency jitter, failure rate across sweeps) |
When the batch pipeline scope is "all_trials" and expects_list=False, the
batch engine computes the time-aligned average across eligible sweeps before
invoking your wrapper, preventing sweep-length mismatch errors on recordings
with truncated final sweeps.
# Multi-trial plugin (trial-to-trial latency jitter)
@AnalysisRegistry.register(
name="latency_jitter",
label="Latency Jitter",
expects_list=True, # wrapper receives list[np.ndarray]
ui_params=[...],
)
def run_jitter(data, time, sampling_rate, **kwargs):
latencies_ms = [find_first_spike_latency_ms(d, t) for d, t in zip(data, time)]
return {"Jitter_ms": float(np.nanstd(latencies_ms))}
# Single-trace plugin (default)
@AnalysisRegistry.register(
name="synaptic_charge",
label="Synaptic Charge (AUC)",
expects_list=False, # wrapper receives 1-D np.ndarray
ui_params=[...],
)
def run_charge(data, time, sampling_rate, **kwargs):
return calculate_synaptic_charge(data, time, sampling_rate, **kwargs)
3.5 Registering Custom Signal Preprocessors
In addition to analysis tabs, plugins can register custom signal
preprocessors using @AnalysisRegistry.register_processor(name, ...) (an
alias for @AnalysisRegistry.register(name, type="preprocessing", ...)).
Unlike analysis wrappers, a preprocessor returns a modified 1-D np.ndarray
signal trace of the same shape and units as data. AnalysisRegistry.execute
leaves type="preprocessing" outputs as raw np.ndarray arrays rather than
wrapping them in AnalysisResult, allowing preprocessors to be chained ahead of
analyses in BatchAnalysisEngine and synaptipy-batch pipeline JSON files
alongside the 7 built-in preprocessors (baseline_subtraction, lowpass_filter,
highpass_filter, bandpass_filter, notch_filter, comb_filter, and
detrend_filter).
import numpy as np
from scipy.ndimage import median_filter
from synaptipy.core.analysis.registry import AnalysisRegistry
@AnalysisRegistry.register_processor("median_despike", label="Median Despike Filter")
def run_median_despike_processor(
data: np.ndarray,
time: np.ndarray,
sampling_rate: float,
**kwargs,
) -> np.ndarray:
"""Suppress isolated single-sample hardware glitches with a short median window."""
if data is None or data.size == 0:
return data
kernel_samples = max(3, int(kwargs.get("kernel_samples", 5)))
if kernel_samples % 2 == 0:
kernel_samples += 1
return median_filter(np.asarray(data, dtype=float), size=kernel_samples)
Inspect all available preprocessors with:
from synaptipy.core.analysis.registry import AnalysisRegistry
print(AnalysisRegistry.list_preprocessing())
4. Defining GUI Parameters (ui_params)
The ui_params list in @AnalysisRegistry.register(...) defines the parameter
widgets generated in your Analyser tab. Each entry is a dictionary describing
one control.
4.1 float Parameter
Creates a double-precision spin box (QDoubleSpinBox).
{
"name": "threshold", # keyword argument passed to your wrapper
"label": "Threshold (mV):", # label text shown in the GUI
"type": "float",
"default": -20.0, # initial value (default: 0.0)
"min": -200.0, # minimum allowed (default: -1e9)
"max": 200.0, # maximum allowed (default: 1e9)
"decimals": 2, # decimal places (default: 4)
"step": 0.5, # step increment (optional)
}
4.2 int Parameter
Creates an integer spin box (QSpinBox).
{
"name": "min_spikes",
"label": "Min Spikes:",
"type": "int",
"default": 3,
"min": 1,
"max": 10000,
}
4.3 choice / combo Parameter
Creates a drop-down selector (QComboBox).
{
"name": "direction",
"label": "Detection Direction:",
"type": "choice", # "combo" is also accepted
"choices": ["negative", "positive", "both"],
"default": "negative",
}
Note: Both
"choices"and"options"are accepted for listing combo-box items.
4.4 bool Parameter
Creates a check box (QCheckBox).
{
"name": "auto_detect",
"label": "Auto-Detect Baseline",
"type": "bool",
"default": False,
}
4.5 string Parameter
Creates a text entry field (QLineEdit) for free-form strings or identifiers.
{
"name": "cell_label",
"label": "Cell Label:",
"type": "string", # aliases: "str", "path"
"default": "",
"placeholder": "e.g. CA1 pyramidal",
"tooltip": "Optional label stored in the results table.",
}
4.8 Common Optional Fields
These optional keys apply to any ui_params entry:
Field |
Type |
Description |
|---|---|---|
|
|
Hover tooltip explaining the parameter’s scientific role. |
|
|
When |
|
|
Shows or hides the widget dynamically based on another parameter or clamp context. |
|
|
Re-defaults the parameter automatically for |
4.9 Conditional Visibility (visible_when)
Show or hide a parameter widget based on the active value of a sibling widget:
ui_params=[
{
"name": "event_type",
"type": "choice",
"choices": ["Spikes", "EPSCs"],
"label": "Event Type:",
"default": "Spikes",
},
{
"name": "spike_threshold",
"type": "float",
"default": -20.0,
"label": "Spike Threshold (mV):",
"visible_when": {"param": "event_type", "value": "Spikes"},
},
{
"name": "epsc_threshold",
"type": "float",
"default": -5.0,
"label": "EPSC Threshold (pA):",
"visible_when": {"param": "event_type", "value": "EPSCs"},
},
]
Clamp-mode context rules are also supported:
{
"name": "step_current_pa",
"type": "float",
"default": -20.0,
"label": "Injected Current (pA):",
"visible_when": {"context": "clamp_mode", "value": "current_clamp"},
}
5. Defining Plot Overlays (plots)
The plots list in @AnalysisRegistry.register(...) declares visual overlays
drawn on the trace canvas after analysis runs.
5.1 hlines - Horizontal Lines
Draws horizontal InfiniteLine items at y-coordinates read from result metrics.
{"type": "hlines", "data": ["Baseline_pA"], "color": "b", "styles": ["dash"]}
{"type": "hlines", "data": ["mean", "mean_plus_sd", "mean_minus_sd"],
"color": "b", "styles": ["solid", "dash", "dash"]}
Field |
Description |
|---|---|
|
List of result-dict keys (each finite scalar value draws one horizontal line). |
|
Line colour string or hex code (default |
|
List of |
5.2 vlines - Vertical Lines
Draws vertical InfiniteLine items at x-positions (seconds).
{"type": "vlines", "data": "_stimulus_times", "color": "c"}
Field |
Description |
|---|---|
|
Result-dict key holding a scalar or 1-D array of x-positions (seconds). |
|
Line colour. When omitted, uses the global H/V Lines pen from View > Plot Customization…. |
5.3 markers - Scatter Points
Draws ScatterPlotItem markers at (x, y) coordinates read from result arrays.
{"type": "markers", "x": "_peak_t", "y": "_peak_v", "color": "r", "symbol": "star"}
Field |
Description |
|---|---|
|
Result-dict keys holding equal-length 1-D coordinate arrays. |
|
Marker fill colour. When omitted, uses the global Scatter Points style from View > Plot Customization…. |
|
|
5.4 interactive_region - Draggable Region
Creates a vertical LinearRegionItem bidirectionally synced with two float
parameter spinboxes.
{"type": "interactive_region", "data": ["window_start", "window_end"], "color": "blue"}
"data" must be a 2-element list of ui_params "name" strings (not result
keys). Note that MetadataDrivenAnalysisTab renders a single custom
interactive_region entry from plots=[...] (unless your parameters use the
built-in paired names baseline_start/baseline_end and
response_start/response_end, which are auto-registered as dual regions).
5.5 threshold_line - Draggable Threshold
Creates a draggable horizontal line synced to a float parameter spinbox.
{"type": "threshold_line", "param": "threshold"}
5.6 overlay_fit - Curve Overlay
Plots a fitted curve (such as an exponential decay) over the raw trace.
{
"type": "overlay_fit",
"x": "_fit_time",
"y": "_fit_values",
"color": "r",
"width": 2,
"label": "Exponential Fit",
}
5.7 popup_xy - Popup Scatter/Line Plot
Opens an interactive secondary plot window (for I-V or F-I relationships) when requested in the Analyser tab.
{
"type": "popup_xy",
"title": "F-I Curve",
"x": "current_steps_pa",
"y": "firing_rates_hz",
"x_label": "Current (pA)",
"y_label": "Firing Rate (Hz)",
}
Optionally supply "slope_key" and "intercept_key" to overlay a linear
regression line.
5.8 brackets - Burst/Event Brackets
Draws horizontal bracket bars above detected burst groups.
{"type": "brackets", "data": "bursts", "color": "r"}
"data" must reference a list of spike-time arrays (one array per burst).
5.9 event_markers - Interactive Event Points
Renders curatable event markers supporting click-to-remove and Ctrl+click-to-add.
{"type": "event_markers"}
Reads event_indices from the analysis result automatically.
5.10 trace - Base Trace with Overlay
Plots the base trace with optional detected spike or event markers.
{"type": "trace", "show_spikes": True}
5.11 fill_between - Shaded Region Between Two Curves
Draws a translucent FillBetweenItem between a primary curve (y1) and a
baseline array or scalar (y2), suitable for visualizing integrated synaptic
charge or area under the curve.
{
"type": "fill_between",
"x": "_int_x", # shared time array key
"y1": "_int_y", # primary curve array key
"y2": "_baseline", # baseline array or scalar key (default: 0.0)
"brush": (0, 150, 255, 100), # RGBA fill tuple
}
y2 may point to a 1-D array matching y1, a scalar float (expanded to a
constant horizontal baseline), or be omitted (0.0). Return the referenced
arrays as _-prefixed keys in your flat result dictionary:
return {
"Charge_pC": round(charge_pc, 6),
"Baseline_pA": round(baseline_val, 4),
"_int_x": int_x,
"_int_y": int_y_abs,
"_baseline": baseline_arr,
}
5.12 trace_overlay - Highlight a Region on the Raw Trace
Draws a semi-transparent coloured segment directly over the plotted trace between
start_time and end_time (in seconds).
{
"type": "trace_overlay",
"start_time": "_baseline_start_s",
"end_time": "_baseline_end_s",
"color": "#00cfff",
"width": 3,
"opacity": 60,
}
Field |
Type |
Description |
|---|---|---|
|
|
Result key or literal float(s) giving the window start time(s) in seconds. Pass equal-length sequences for multi-pulse windows. |
|
|
Result key or literal float(s) giving the window end time(s) in seconds. |
|
|
Hex or named colour. Falls back to the Trace Overlay tab in View > Plot Customization… when omitted. |
|
|
Pen width in pixels (default |
|
|
Opacity percentage |
5.13 event_fit_overlay - Overlay Fitted Event Decay Curves
Plots fitted curves (for example mono- or bi-exponential synaptic decays) across one or more detected events. Supports either a single 1-D array pair or a list of 1-D arrays (one array per event).
{
"type": "event_fit_overlay",
"times_key": "_event_fit_times",
"values_key": "_event_fit_values",
"color": "#ff9900",
"width": 2,
"opacity": 80,
}
Field |
Type |
Description |
|---|---|---|
|
|
Result key holding a 1-D time array or list of per-event time arrays. |
|
|
Result key holding a 1-D fitted-value array or list of per-event arrays. |
|
|
Hex or named colour. Falls back to Event Fit Overlay in View > Plot Customization… when omitted. |
|
|
Pen width in pixels (default |
|
|
Opacity percentage |
Example flat return dictionary for a multi-pulse decay fit:
return {
"decay_tau_ms_p1": tau_p1,
"decay_tau_ms_p2": tau_p2,
"_event_fit_times": [t_arr_p1, t_arr_p2],
"_event_fit_values": [v_arr_p1, v_arr_p2],
}
6. Where to Put Your Plugin File
Note: Ensure Enable Custom Plugins is checked under Edit > Preferences (or Synaptipy > Preferences on macOS) in the Extensions section on the General tab. This setting is enabled by default. Toggling Enable Custom Plugins off and back on (and clicking Apply or OK) hot-reloads
~/.synaptipy/plugins/in-process without restarting Synaptipy.
Option A: Downloadable and Bundled Example Plugins
Synaptipy provides four annotated example plugins covering single-sweep
current/voltage AUC integration, multi-trial TTL latency jitter, deep-learning
event detection, and SpikeInterface spike detection. Install them into
~/.synaptipy/plugins/ via Help > Download Example Plugins… (source
checkouts also include them under examples/plugins/).
Included Example Plugins
File |
Label in GUI |
Purpose |
|---|---|---|
|
Synaptic Charge (AUC) |
Integrates baseline-subtracted postsynaptic currents ( |
|
Opto Latency Jitter |
Detects evoked spikes or subthreshold EPSP/EPSC peaks per TTL pulse across sweeps ( |
|
miniML Events |
Runs deep-learning synaptic event detection via miniML ( |
|
Spike Detection (SpikeInterface) |
Wraps traces in a |
To activate or customize an example plugin:
Select Help > Download Example Plugins… to copy the four files into
~/.synaptipy/plugins/.Edit any downloaded file in
~/.synaptipy/plugins/(changingname=andlabel=if creating a new variant).Toggle Enable Custom Plugins in Edit > Preferences (Extensions group) to hot-reload changed plugin code in-process, and confirm the security prompt when your modified file fingerprint is detected.
Option B: User Plugin Directory (Recommended for Personal and Lab Plugins)
Platform |
Full path |
|---|---|
macOS / Linux |
|
Windows |
|
Requires zero edits to the Synaptipy repository or installation.
Discovered automatically at startup and by
synaptipy-batchCLI runs.Preserved across package upgrades.
Takes precedence over any bundled example sharing the same filename stem.
Option C: Repository Contributions (examples/plugins/ vs. Core Pillars)
If you are contributing an analysis back to the Synaptipy repository, follow the immutable 5-Pillar UI Architecture rule:
Standalone or specialized analyses: Contribute the file under
examples/plugins/<your_plugin>.pywith accompanying tests inexamples/tests/. Never add a sixth top-level tab or custom GUI tab subclass for domain-specific metrics.Core sub-analyses within an existing pillar: Only metrics that belong directly inside one of the five canonical pillars (
passive_properties.py,single_spike.py,firing_dynamics.py,synaptic_events.py, orevoked_responses.py) are added tosrc/synaptipy/core/analysis/(see Section 7).
7. For Core Contributors - 5-Pillar Architecture Rules
Synaptipy’s core Analyser UI is locked to exactly five pillar tabs:
Passive Properties(src/synaptipy/core/analysis/passive_properties.py)Single Spike Kinetics(src/synaptipy/core/analysis/single_spike.py)Firing Dynamics(src/synaptipy/core/analysis/firing_dynamics.py)Synaptic Events(src/synaptipy/core/analysis/synaptic_events.py)Evoked Responses(src/synaptipy/core/analysis/evoked_responses.py)
When adding a new built-in leaf routine to one of these five pillars:
Step |
File |
Action |
|---|---|---|
1 |
|
Define or reuse a typed |
2 |
|
Implement the pure vectorized logic function returning that dataclass, plus the |
3 |
|
Register the routine’s |
4 |
|
Add the new registry |
5 |
|
Add deterministic |
Important: Core analyses are loaded because
src/synaptipy/core/analysis/__init__.pyimports all five pillar modules andpreprocessing.py. Never add standalone top-level GUI tabs insrc/synaptipy/application/gui/analysis_tabs/; any metric outside the five pillars must be contributed as a plugin inexamples/plugins/.
8. Testing Your Plugin
Unit-Testing the Pure Logic Function
Because Part 1 is pure Python and NumPy, test it directly with pytest without
initializing Qt:
import numpy as np
from my_analysis import calculate_area_under_curve
def test_auc_basic():
fs = 10000.0
t = np.arange(0.0, 0.5, 1.0 / fs)
data = np.zeros_like(t)
data[(t >= 0.1) & (t < 0.3)] = -100.0 # -100 pA rectangular step for 0.2 s
result = calculate_area_under_curve(
data,
t,
fs,
baseline_start=0.0,
baseline_end=0.05,
window_start=0.1,
window_end=0.3,
)
# Expected charge: -100 pA * 0.2 s = -20 pC
assert abs(result["Charge_pC"] - (-20.0)) < 0.05
assert result["Baseline_pA"] == 0.0
def test_auc_error_on_narrow_window():
fs = 1000.0
t = np.array([0.0, 0.001])
data = np.array([0.0, -1.0])
result = calculate_area_under_curve(
data,
t,
fs,
baseline_start=0.0,
baseline_end=0.001,
window_start=0.5,
window_end=0.6,
)
assert "error" in result
Integration-Testing the Registry Execution Boundary
Verify registration and canonical AnalysisResult normalization through
AnalysisRegistry.execute:
import numpy as np
from synaptipy.application.plugin_manager import PluginManager
from synaptipy.core.analysis.registry import AnalysisRegistry
def test_synaptic_charge_registered():
PluginManager.load_plugins()
meta = AnalysisRegistry.get_metadata("synaptic_charge")
assert "ui_params" in meta
assert meta.get("label") == "Synaptic Charge (AUC)"
fs = 10000.0
t = np.arange(0.0, 0.2, 1.0 / fs)
trace = np.zeros_like(t)
trace[(t >= 0.02) & (t <= 0.06)] = -50.0
res = AnalysisRegistry.execute(
"synaptic_charge",
trace,
t,
fs,
window_start=0.01,
window_end=0.10,
)
assert "Charge_pC" in res.metrics
Validating the Starter Template
The repository test suite validates src/synaptipy/templates/plugin_template.py:
conda run -n synaptipy python -m pytest tests/core/test_plugin_template.py -v
9. Full Annotated Example - Synaptic Charge Transfer
This complete example measures synaptic charge (\(Q\), in picocoulombs)
delivered during a postsynaptic current by subtracting a local pre-window
baseline, locating the event peak, bounding the deflection at its zero
crossings, and integrating with np.trapezoid:
For current \(I(t)\) in \(\text{pA}\) and time \(t\) in seconds, the integral has units of \(\text{pA}\cdot\text{s} = \text{pC}\).
Save this file as ~/.synaptipy/plugins/synaptic_charge.py (aligned with
examples/plugins/synaptic_charge.py):
"""
Custom Synaptipy Plugin: Synaptic Charge (AUC) with Local Baseline Correction.
Place in ~/.synaptipy/plugins/ and toggle Enable Custom Plugins in
Edit > Preferences (Extensions) to hot-reload in-process without restarting.
"""
import logging
from typing import Any, Dict
import numpy as np
from synaptipy.core.analysis.registry import AnalysisRegistry
log = logging.getLogger(__name__)
# ── Part 1: Pure analysis logic ────────────────────────────────────
def _find_zero_crossing_left(baseline_subtracted: np.ndarray, peak_idx: int) -> int:
"""Step backward from peak_idx until the trace crosses baseline (zero)."""
if peak_idx <= 0 or baseline_subtracted.size == 0:
return 0
peak_sign = np.sign(baseline_subtracted[peak_idx])
if peak_sign == 0:
return peak_idx
crossed = np.where(np.sign(baseline_subtracted[:peak_idx]) != peak_sign)[0]
return int(crossed[-1] + 1) if crossed.size > 0 else 0
def _find_zero_crossing_right(baseline_subtracted: np.ndarray, peak_idx: int) -> int:
"""Step forward from peak_idx until the trace crosses baseline (zero)."""
n = baseline_subtracted.size
if peak_idx >= n - 1 or n == 0:
return max(0, n - 1)
peak_sign = np.sign(baseline_subtracted[peak_idx])
if peak_sign == 0:
return peak_idx
crossed = np.where(np.sign(baseline_subtracted[peak_idx + 1 :]) != peak_sign)[0]
return int(peak_idx + crossed[0]) if crossed.size > 0 else n - 1
def calculate_synaptic_charge(
data: np.ndarray,
time: np.ndarray,
sampling_rate: float,
window_start: float,
window_end: float,
baseline_method: str = "Pre-Window",
detection_method: str = "Absolute Peak",
local_baseline_window_ms: float = 10.0,
) -> Dict[str, Any]:
"""Compute synaptic charge (pC) via zero-crossing trapezoidal integration."""
if data.size == 0:
return {"error": "Empty data array"}
if window_start >= window_end:
return {"error": "window_start must be less than window_end"}
# 1. Baseline estimation (local pre-window tracks slow holding-current drift)
if baseline_method == "Pre-Window":
local_win_s = max(1e-4, local_baseline_window_ms / 1000.0)
pre_start = max(float(time[0]), window_start - local_win_s)
pre_mask = (time >= pre_start) & (time < window_start)
pre_slice = data[pre_mask]
baseline_val = float(np.mean(pre_slice)) if pre_slice.size > 0 else float(np.mean(data))
else:
baseline_val = float(np.mean(data))
# 2. Extract search window
win_i0 = max(0, min(int(np.searchsorted(time, window_start, side="left")), len(data) - 1))
win_i1 = max(win_i0 + 1, min(int(np.searchsorted(time, window_end, side="right")), len(data)))
win_time = time[win_i0:win_i1]
win_data = data[win_i0:win_i1]
if win_time.size < 2:
return {"error": "Search window too narrow (need >= 2 samples)"}
# 3. Locate peak and zero-crossing integration bounds
win_bs = win_data - baseline_val
peak_idx_rel = (
int(np.argmin(win_bs))
if detection_method == "Negative Peak"
else int(np.argmax(np.abs(win_bs)))
)
peak_t = float(win_time[peak_idx_rel])
peak_v_abs = float(win_data[peak_idx_rel])
peak_v_bs = float(win_bs[peak_idx_rel])
left_idx = _find_zero_crossing_left(win_bs, peak_idx_rel)
right_idx = _find_zero_crossing_right(win_bs, peak_idx_rel)
if right_idx <= left_idx:
right_idx = min(left_idx + 1, len(win_bs) - 1)
int_x = win_time[left_idx : right_idx + 1]
int_y_bs = win_bs[left_idx : right_idx + 1]
int_y_abs = win_data[left_idx : right_idx + 1]
baseline_arr = np.full(len(int_x), baseline_val)
if int_x.size < 2:
return {"error": "Integration region too narrow after zero-crossing search"}
# 4. Trapezoidal integration (NumPy >= 2.0 compatible: pA * s = pC)
charge_pc = float(np.trapezoid(int_y_bs, int_x))
return {
"Charge_pC": round(charge_pc, 6),
"Peak_Amp": round(peak_v_abs, 4),
"Peak_Amp_Baseline_Subtracted": round(peak_v_bs, 4),
"Baseline_pA": round(baseline_val, 4),
"Integration_Start_s": round(float(int_x[0]), 6),
"Integration_End_s": round(float(int_x[-1]), 6),
# Private overlay arrays (hidden from results table and CSV export)
"_int_x": int_x,
"_int_y": int_y_abs,
"_baseline": baseline_arr,
"_peak_t": np.array([peak_t]),
"_peak_v": np.array([peak_v_abs]),
}
# ── Part 2: Registry wrapper ───────────────────────────────────────
@AnalysisRegistry.register(
name="synaptic_charge",
label="Synaptic Charge (AUC)",
expects_list=False,
supported_channel_units=("pA", "nA", "uA", "A", "mV", "V", "uV"),
ui_params=[
{
"name": "baseline_method",
"label": "Baseline Method:",
"type": "choice",
"choices": ["Pre-Window", "Global"],
"default": "Pre-Window",
"tooltip": "Pre-Window averages a short window before window_start; Global uses trace mean.",
},
{
"name": "detection_method",
"label": "Detection Method:",
"type": "choice",
"choices": ["Absolute Peak", "Negative Peak", "Positive Peak"],
"default": "Absolute Peak",
},
{
"name": "window_start",
"label": "Search Window Start (s):",
"type": "float",
"default": 0.02,
"min": 0.0,
"max": 1e9,
"decimals": 4,
},
{
"name": "window_end",
"label": "Search Window End (s):",
"type": "float",
"default": 0.25,
"min": 0.0,
"max": 1e9,
"decimals": 4,
},
{
"name": "local_baseline_window_ms",
"label": "Local Baseline Window (ms):",
"type": "float",
"default": 10.0,
"min": 0.5,
"max": 500.0,
"decimals": 1,
"visible_when": {"param": "baseline_method", "value": "Pre-Window"},
},
],
plots=[
{
"type": "interactive_region",
"data": ["window_start", "window_end"],
"color": "blue",
},
{
"type": "fill_between",
"x": "_int_x",
"y1": "_int_y",
"y2": "_baseline",
},
{
"type": "markers",
"x": "_peak_t",
"y": "_peak_v",
"color": "r",
"symbol": "star",
"size": 13,
},
{
"type": "hlines",
"data": ["_baseline_level"],
"color": "b",
"styles": ["dash"],
},
],
)
def run_synaptic_charge_wrapper(
data: np.ndarray,
time: np.ndarray,
sampling_rate: float,
**kwargs: Any,
) -> Dict[str, Any]:
"""Registry wrapper for synaptic charge / postsynaptic AUC analysis."""
return calculate_synaptic_charge(
data=data,
time=time,
sampling_rate=sampling_rate,
window_start=float(kwargs.get("window_start", 0.0)),
window_end=float(kwargs.get("window_end", 0.1)),
baseline_method=str(kwargs.get("baseline_method", "Pre-Window")),
detection_method=str(kwargs.get("detection_method", "Absolute Peak")),
local_baseline_window_ms=float(kwargs.get("local_baseline_window_ms", 10.0)),
channel_units=str(kwargs.get("channel_units", "pA") or "pA"),
)
Key design points demonstrated above:
NumPy 2.0 compatibility: Uses
np.trapezoid(int_y_bs, int_x)rather than the removednp.trapzfunction.Unit-aware voltage-clamp and current-clamp support: Declares
supported_channel_units=("pA", "nA", "uA", "A", "mV", "V", "uV")and readschannel_units(injected automatically byMetadataDrivenAnalysisTab) so current channels reportCharge_pC(nAscaled by1000x) while voltage channels reportAUC (mV*ms)andAUC (mV*s).Single interactive search window and customizable AUC fill: Declares one
interactive_regionbound to["window_start", "window_end"], paired withfill_between(omitting"brush"so it inherits AUC Fill from View > Plot Customization…), a peakstarmarker, and a dashedhlinesoverlay reading"data": ["_baseline_level"]in raw trace Y-units.Canonical return dictionary: Returns scalar metrics alongside
_-prefixed overlay arrays;AnalysisRegistry.executenormalizes the output intoAnalysisResult(schema v1).
10. Plot Overlay Styling and Customization
Synaptipy centralizes plot appearance in PlotCustomizationManager
(src/synaptipy/shared/plot_customization.py), which users configure from
View > Plot Customization…. When the user clicks Apply or OK in
that dialog, PlotCustomizationSignals.preferences_updated fires and open plot
canvases refresh their pens and brushes immediately.
How Plugin Overlays Resolve Colours and Styles
Plugin wrappers never receive GUI theme objects in **kwargs and must never
import PySide6 or pyqtgraph. Instead, MetadataDrivenAnalysisTab styles
your plugin’s overlays declaratively from the plots=[...] metadata list:
Explicit per-overlay keys in
plots=[...]: When an overlay dictionary specifies"color","brush","width","opacity","styles", or"symbol",MetadataDrivenAnalysisTabapplies those explicit values.Global user preferences fallback: Omit
"color"on supported overlay types (markers,vlines,trace_overlay, andevent_fit_overlay) to inherit the user’s active settings from View > Plot Customization… viaget_plot_customization_manager():
PlotCustomizationDialog Tab |
Internal Key |
Helper Function / Fallback Used by GUI |
|---|---|---|
Average |
|
|
Single Trial |
|
|
Grid |
|
|
Scatter Points |
|
|
Selection Windows |
|
|
AUC Fill |
|
|
H/V Lines |
|
|
Trace Overlay |
|
|
Event Fit Overlay |
|
|
Example plots=[...] declaration that inherits user-configured colours from
View > Plot Customization… while overriding specific line styles where
needed:
plots=[
# Omitting "color" inherits the user's Scatter Points colour preference
{"type": "markers", "x": "_peak_times", "y": "_peak_values", "symbol": "o"},
# Omitting "color" inherits the user's H/V Lines pen preference
{"type": "vlines", "data": "_stimulus_times"},
# Omitting "color" inherits the user's Trace Overlay colour/width/opacity
{"type": "trace_overlay", "start_time": "_win_start", "end_time": "_win_end"},
# Explicit colour and style for a reference baseline line
{"type": "hlines", "data": ["Baseline_pA"], "color": "#0072b2", "styles": ["dash"]},
]
Querying Plot Preferences in Application-Layer GUI Code
Core contributors maintaining custom GUI widgets under
src/synaptipy/application/gui/ can query pens from
get_plot_customization_manager() and connect to live preference updates via
get_plot_customization_signals():
from synaptipy.shared.plot_customization import (
get_plot_customization_manager,
get_plot_customization_signals,
)
mgr = get_plot_customization_manager()
avg_pen = mgr.get_average_pen()
signals = get_plot_customization_signals()
signals.preferences_updated.connect(my_canvas_widget.refresh_pens)
11. SpikeInterface Integration Plugin
Synaptipy includes an optional plugin integrating
SpikeInterface extracellular
spike detection into the Analyser workflow (examples/plugins/spike_interface_integration.py,
tab label Spike Detection (SpikeInterface)). Because SpikeInterface is an
optional dependency, it is not included in pyproject.toml or
requirements.txt; install it when needed with pip install spikeinterface.
What the Plugin Does
Select an extracellular recording channel in the Analyser tab.
The plugin wraps the 1-D NumPy sweep in a
spikeinterface.core.NumpyRecording, applies a bandpass filter (default 300-6000 Hz), and executesdetect_peakswith theby_channelmethod (no external spike-sorter binary required).Detected spikes are rendered as:
Dashed vertical lines at each spike timestamp.
Scatter markers at the filtered peak amplitude.
Summary metrics are reported in the Results table:
Spike_Count,Noise_Estimate,Threshold, andMean_Firing_Rate_Hz.
Before Running

Setting run_button=True in @AnalysisRegistry.register(...) adds an explicit
Run Analysis button so the bandpass and peak-detection pipeline runs on
demand rather than on every spinbox keystroke.
After Running - Detected Spikes

Installation
conda activate synaptipy
pip install spikeinterface
# Copy from a source checkout (or use Help > Download Example Plugins... in the GUI):
cp examples/plugins/spike_interface_integration.py ~/.synaptipy/plugins/
Key Parameters
Parameter |
Default |
Description |
|---|---|---|
|
|
Lower bandpass cutoff ( |
|
|
Upper bandpass cutoff (auto-clamps below Nyquist with a warning on lower-rate recordings; snaps markers to raw AP peaks when |
|
|
Detection threshold as a multiple of the MAD noise estimate |
|
|
Spike polarity ( |
|
|
Refractory lockout window preventing duplicate peak triggers |
Running Example Plugin Tests
Tests for the optional example plugins reside in examples/tests/ (outside CI’s
default tests/ collection path) and can be executed directly:
conda run -n synaptipy python -m pytest examples/tests/ -v
12. Deep Learning and Third-Party Integrations (miniML)
Synaptipy’s plugin system isolates optional machine-learning frameworks from the
core distribution. External libraries such as
miniML can be integrated in a local
environment without modifying Synaptipy source files or adding heavy ML packages
to pyproject.toml, requirements.txt, or environment.yml.
Important:
miniML,tensorflow,tf_keras,keras,ruptures, and other third-party ML packages must never be added to Synaptipy’s core dependency manifests.
4-Step Setup Workflow
Clone miniML outside the Synaptipy repository:
git clone https://github.com/delvendahl/miniML.git ~/miniML
miniML is distributed as source modules rather than a PyPI wheel; the plugin appends
miniML/core/tosys.pathlazily when analysis runs.Install compatible ML dependencies in your
synaptipyenvironment:conda activate synaptipy pip install "tensorflow>=2.17" tf_keras h5py scikit-learn ruptures==1.1.10
Warning: Do not run
pip install -r ~/miniML/requirements.txt. Upstream miniML pinsnumpy==1.23.5andpandas==1.5.3, which conflict with Synaptipy’snumpy>=2.0requirement (np.trapezoid).TensorFlow 2.16+ defaults to Keras 3, whereas pre-trained miniML
.h5models use the Keras 2 serialization format;tf_kerassupplies the required compatibility layer.Install and hot-reload the plugin:
# macOS / Linux cp examples/plugins/miniml_integration.py ~/.synaptipy/plugins/ # Windows (PowerShell) Copy-Item examples\plugins\miniml_integration.py ~\.synaptipy\plugins\
Or choose Help > Download Example Plugins… inside Synaptipy. If the application is already open, toggle Enable Custom Plugins off and back on in Edit > Preferences (Extensions group) to load miniML Events in-process without restarting.
Select model paths in the GUI:
Open a voltage-clamp (
pA) or current-clamp (mV) recording, switch to Analyser, and select the miniML Events tab (Direction defaults automatically to"negative"in voltage-clamp and"positive"in current-clamp).Click Browse… beside miniML core/ Path and select either
~/miniML/core/or the cloned~/miniMLrepository root (standard clones under~/PycharmProjects/miniML/coreor~/miniML/coreare auto-detected).Click Browse… beside Model Path (.h5) and select a trained model (for example
~/miniML/models/GC_lstm_model.h5for mEPSCs or~/miniML/models/transfer_learning/GC_mEPSP/lstm_transfer.h5for mEPSPs).Configure Prediction Threshold and Direction, then click Run Analysis. Validated paths are persisted in
QSettingsacross sessions.
miniML Integration Screenshots

Because examples/plugins/miniml_integration.py defers tensorflow and
miniML imports until Run Analysis is clicked, the tab loads cleanly even on
machines without TensorFlow installed.

Once paths are configured, Run Analysis executes inference and overlays detected synaptic events on the trace:

Installation Warning
Do not run pip install miniML (which installs an unrelated package from PyPI),
and do not clone miniML inside the Synaptipy git working tree.
Template Highlights (examples/plugins/miniml_integration.py)
Lazy
sys.pathimport: ImportsminiMLinside the execution function rather than at module top level so startup time is unaffected.dirpathandfilepathBrowse widgets: Generates native folder and file pickers fromui_paramsmetadata.run_button=True: Prevents expensive neural-network inference from triggering automatically on parameter edits.Private overlay arrays: Returns
_event_timesand_event_peaksfor plot markers while exposing scalar summary metrics (Event_Count,Frequency_Hz,Model_Used) in the results table.
miniML API Notes (Common Pitfalls)
miniML splits configuration across EventDetection.__init__() and
detect_events(). Passing post-processing arguments to __init__() raises
TypeError.
EventDetection.__init__() Parameters
detector = EventDetection(
data=trace,
event_direction=direction, # "negative" or "positive"
model_path=active_model,
model_threshold=threshold,
batch_size=batch_size,
window_size=window_size,
)
detect_events() Parameters and Evaluated Statistics
detect_kwargs = {
"eval": True,
"rel_prom_cutoff": rel_prom_cutoff, # default 0.25
}
if convolve_win > 0:
detect_kwargs["convolve_win"] = convolve_win
if gradient_convolve_win > 0:
detect_kwargs["gradient_convolve_win"] = gradient_convolve_win
detector.detect_events(**detect_kwargs)
Note: Leaving
convolve_win=0andgradient_convolve_win=0(the GUI defaults) omits those overrides so upstreamminiMLuses its sampling-rate-adaptivefilter_factorwindow automatically.
Peak Locations vs. Baseline-Subtracted Event Amplitudes
When detect_events(eval=True) runs, miniML populates both
detector.event_peak_locations (sample indices of evaluated event peaks) and
detector.event_stats (amplitudes, risetimes, halfdecays). Always report
detector.event_stats.amplitudes for scalar amplitude metrics (so holding
current or resting membrane potential DC offsets are subtracted), while reading
data[peak_indices] for _event_peaks so scatter markers sit directly on the
plotted trace.
Adapting the Pattern to Other Inference Libraries
Component |
Adaptation |
|---|---|
Lazy import helper |
Import PyTorch, ONNX Runtime, or custom packages inside the analysis call rather than at module import time |
|
Expose |
|
Require explicit click before running heavy model inference |
|
Bind returned |
13. Troubleshooting
Symptom |
Cause |
Fix |
|---|---|---|
Plugin tab does not appear |
Syntax or import error in plugin file |
Inspect |
Plugin tab does not appear |
Custom plugins disabled or security prompt declined |
Open Edit > Preferences (Extensions group), verify Enable Custom Plugins is checked, toggle it off and on to trigger hot-reload, and click OK on the plugin security confirmation dialog. |
Plugin tab does not appear |
File saved in the wrong folder |
Verify |
Plugin tab does not appear |
Missing |
Decorate the wrapper function with |
|
Plugin calls |
Replace |
|
Optional third-party package is not installed |
Activate the |
Plugin registered with |
Plugin |
Choose a unique |
Parameter widget missing |
Unsupported |
Use one of |
Browse button not shown |
Parameter uses |
Change |
|
Used |
Specify |
Second |
Only one custom |
Use a single |
Private array appears in Results table |
Key does not start with an underscore |
Prefix overlay-only array keys with |