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

aggregate_response_data(df, *[, by_x, ...])

Per (strain, cell_type, x) compute centre + spread + n.

fetch_response_data(conn, *, stimulus_name)

JOIN stimulus_responses with v_recordings and filter.

plot_response_curves(data, *[, ...])

Two-panel response curve figure: one panel per cell type.

Classes

ResponseCurves([cell_types, by_x, error, ...])

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: object

Callable 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:
by_x: str = 'delta_target_c'
cell_types: tuple[str, ...] = ('CC', 'HC')
dpi: int = 200
error: Literal['ci', 'iqr', 'sem', 'none'] = 'ci'
figsize: tuple[float, float] = (10, 5)
plot(data, *, stimulus_name=None, title=None, **overrides)[source]
Parameters:
Return type:

Figure

save(fig, path, *, dpi=None, close=True)[source]

Save fig as PNG. SVG sibling is written automatically.

Parameters:
  • fig (Figure)

  • path (Path | str)

  • dpi (int | None)

  • close (bool)

Return type:

Path

strains: tuple[str, ...] | None = None
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 at confidence_level (default 0.95). Resampled n_bootstrap times (default 2000) from a seeded np.random.Generator.

  • q25, q75 — interquartile range (legacy error="iqr" mode).

  • mean, sem — for the parametric error="sem" mode.

  • shapiro_p — per-group Shapiro-Wilk p (NaN when n<3); used by the plot layer to gate error="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:

pandas.DataFrame

arista.viz.response_curves.fetch_response_data(conn, *, stimulus_name, cell_types=('CC', 'HC'), strains=None, min_frames_in_window=50)[source]

JOIN stimulus_responses with v_recordings and filter.

Parameters:
  • conn (Connection) – Open SQLite connection to a populated arista.db.

  • stimulus_name (str) – Canonical stimulus protocol name ("ascAmp", "descAmp", …).

  • cell_types (tuple[str, ...]) – Which cell types to include.

  • strains (tuple[str, ...] | None) – Optional whitelist of canonical strain names; None means “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:

pandas.DataFrame

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 passed stimulus_name becomes 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".

  • figsize (tuple[float, float]) – (width, height) inches.

  • title (str | None) – Figure suptitle. Auto-generated from stimulus_name when None.

  • 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