arista.viz.response_curves
Reproduce Kossen 2019 Fig 19 / 22-23: response curves per strain × cell-type.
One panel per cell type (CC / HC, optionally WC). Within each panel
one line per strain, x-axis is delta_target_c (step target minus
22 °C baseline) or absolute target_temp_c, y-axis is the per-step
median ΔF/F across recordings of that strain × cell_type.
Error band is median ± 95% bootstrap CI of the median by default —
non-parametric, no assumption of normality. The fallback error="iqr"
mode plots median + interquartile range. The parametric error="sem"
mode (mean ± SEM) runs a Shapiro-Wilk normality test per x-value and
silently downgrades to the CI band with a warning if any group rejects
normality at α = 0.05. This matches Bart’s standing rule: median-based
summaries by default, parametric only after normality is checked.
Colours come from arista.constants.STRAIN_COLOURS. The class
ResponseCurves carries default styling for batch reuse; the
free function plot_response_curves() is the primary one-off API.
Functions
|
Per (strain, cell_type, x) compute centre + spread + n. |
|
JOIN |
|
Two-panel response curve figure: one panel per cell type. |
Classes
|
Callable wrapper holding default styling. |
- class arista.viz.response_curves.ResponseCurves(cell_types=('CC', 'HC'), by_x='delta_target_c', error='ci', figsize=(10, 5), dpi=200, strains=None)[source]
Bases:
objectCallable wrapper holding default styling.
Useful when rendering many figures (one per stimulus protocol) with consistent kwargs:
plotter = ResponseCurves(figsize=(12, 5)) for stim in ("ascAmp", "descAmp"): fig = plotter(conn, stimulus_name=stim) plotter.save(fig, output_dir / f"resp_{stim}.png")
- Parameters:
- plot(data, *, stimulus_name=None, title=None, **overrides)[source]
- Parameters:
data (pd.DataFrame | sqlite3.Connection)
stimulus_name (str | None)
title (str | None)
- Return type:
Figure
- arista.viz.response_curves.aggregate_response_data(df, *, by_x='delta_target_c', n_bootstrap=2000, confidence_level=0.95, rng_seed=42)[source]
Per (strain, cell_type, x) compute centre + spread + n.
The output carries enough columns to render any of the four supported error bands (
ci/iqr/sem/none) without re-aggregating:median, ci_low, ci_high— non-parametric default. CI is the percentile bootstrap CI of the median atconfidence_level(default 0.95). Resampledn_bootstraptimes (default 2000) from a seedednp.random.Generator.q25, q75— interquartile range (legacyerror="iqr"mode).mean, sem— for the parametricerror="sem"mode.shapiro_p— per-group Shapiro-Wilk p (NaN when n<3); used by the plot layer to gateerror="sem".n— recordings contributing to this (strain, cell_type, x) bucket.
- Parameters:
df (pandas.DataFrame) – Output of
fetch_response_data().by_x (str) –
"delta_target_c"(default, Kossen-style relative amplitude) or"target_temp_c"(absolute temperature).n_bootstrap (int) – Number of bootstrap resamples for the median CI.
confidence_level (float) – CI coverage (default 0.95).
rng_seed (int) – Seed for the bootstrap RNG (reproducibility).
- Return type:
- arista.viz.response_curves.fetch_response_data(conn, *, stimulus_name, cell_types=('CC', 'HC'), strains=None, min_frames_in_window=50)[source]
JOIN
stimulus_responseswithv_recordingsand filter.- Parameters:
conn (Connection) – Open SQLite connection to a populated
arista.db.stimulus_name (str) – Canonical stimulus protocol name (
"ascAmp","descAmp", …).strains (tuple[str, ...] | None) – Optional whitelist of canonical strain names;
Nonemeans “every strain that has matching responses”.min_frames_in_window (int) – Drop rows that medianed over fewer than this many frames — filters Alex’s protocol-mismatch cases where the sensor barely touched a step’s target window.
- Returns:
DataFrame with one row per (recording, step).
- Return type:
- arista.viz.response_curves.plot_response_curves(data, *, stimulus_name=None, strains=None, cell_types=('CC', 'HC'), by_x='delta_target_c', error='ci', figsize=(10, 5), title=None, shapiro_alpha=0.05)[source]
Two-panel response curve figure: one panel per cell type.
- Parameters:
data (pd.DataFrame | sqlite3.Connection) – Either an already-fetched DataFrame (output of
fetch_response_data()) or a live SQLite connection. When a connection is passedstimulus_namebecomes mandatory.stimulus_name (str | None) – Stimulus protocol name (when fetching from DB).
strains (tuple[str, ...] | None) – Optional strain whitelist.
cell_types (tuple[str, ...]) – Cell types to plot, one panel per.
by_x (str) –
"delta_target_c"(Kossen’s relative-amplitude axis, default) or"target_temp_c"(absolute).error (ErrorBand) – Error band mode.
"ci"(default, median + 95% bootstrap CI of the median),"iqr"(median + IQR),"sem"(mean + SEM, gated by per-x Shapiro-Wilk; falls back to"ci"with a warning on non-normality), or"none".title (str | None) – Figure suptitle. Auto-generated from
stimulus_namewhenNone.shapiro_alpha (float) – Normality rejection threshold for the
"sem"mode (default 0.05).
- Returns:
matplotlib.figure.Figure. The caller owns I/O.- Return type:
Figure