arista.processing

Post-ingest computation on samples already in the DB.

class arista.processing.AdaptationFit(tau_s, amplitude, asymptote, r_squared, fit_window_start_s, fit_window_end_s, n_points)[source]

Bases: object

One exponential-decay fit, destined for adaptation_fits.

Parameters:
amplitude: float
asymptote: float
fit_window_end_s: float
fit_window_start_s: float
n_points: int
r_squared: float
tau_s: float
class arista.processing.ProcessingStats(inserted_responses=0, inserted_adaptations=0, skipped_already_done=0, failed_adaptations=0)[source]

Bases: object

Tally for one process_all run.

Parameters:
  • inserted_responses (int)

  • inserted_adaptations (int)

  • skipped_already_done (int)

  • failed_adaptations (int)

as_dict()[source]
Return type:

dict[str, int]

failed_adaptations: int = 0
inserted_adaptations: int = 0
inserted_responses: int = 0
skipped_already_done: int = 0
class arista.processing.RecordingGain(slope, intercept, r_squared, n_points)[source]

Bases: object

One linear-gain fit for a single recording.

Parameters:
intercept: float
n_points: int
r_squared: float
slope: float
class arista.processing.SigmoidFit(bottom, top, midpoint_c, slope, r_squared, n_points)[source]

Bases: object

One 4PL sigmoid fit.

Parameters:
bottom: float
midpoint_c: float
n_points: int
r_squared: float
slope: float
top: float
class arista.processing.StimulusResponseRow(step_index, target_temp_c, delta_target_c, observed_temp_median, dfbf_response_median, n_frames_in_window)[source]

Bases: object

One row destined for the stimulus_responses table.

Parameters:
  • step_index (int)

  • target_temp_c (float)

  • delta_target_c (float)

  • observed_temp_median (float)

  • dfbf_response_median (float)

  • n_frames_in_window (int)

delta_target_c: float
dfbf_response_median: float
n_frames_in_window: int
observed_temp_median: float
step_index: int
target_temp_c: float
arista.processing.compute_gains_table(response_df, *, min_steps=3, group_keys=('recording_id', 'strain_name', 'cell_type', 'hemisphere'))[source]

Per-recording gains across an already-fetched response frame.

Parameters:
  • response_df (pandas.DataFrame) – Output of arista.viz.response_curves.fetch_response_data() — one row per (recording, step) with all v_recordings metadata joined in.

  • min_steps (int) – Drop recordings with fewer than this many valid steps (default 3 — needed for a meaningful linear fit).

  • group_keys (tuple[str, ...]) – Columns that uniquely identify one recording’s row group. Must include recording_id.

Returns:

DataFrame with one row per recording carrying the group keys plus slope, intercept, r_squared, n_points.

Return type:

pandas.DataFrame

arista.processing.compute_recording_gain(steps_df)[source]

Linear fit slope of ΔF/F vs Δ target temperature.

Parameters:

steps_df (pandas.DataFrame) – One recording’s rows from stimulus_responses, with delta_target_c and dfbf_response_median columns.

Returns:

RecordingGain. slope and r_squared are NaN when fewer than 2 finite points are available or when every x-value is identical (no spread to fit through).

Return type:

RecordingGain

arista.processing.compute_stimulus_responses(samples_df, stimulus_protocol_name, *, window_c=0.5)[source]

Median ΔF/F per step for a thermal-step recording.

Parameters:
Returns:

One StimulusResponseRow per step that yielded at least one in-window frame. Empty list for stimuli without a target_sequence (mechanical Bending, the open-ended HotAdapt / ColdAdapt, Laurin’s step / long pilots) — those protocols don’t have a finite discrete step structure to median over.

Return type:

list[StimulusResponseRow]

arista.processing.fit_adaptation(samples_df, *, fit_start_s=75.0, fit_end_s=None, min_points=30)[source]

Fit a·exp(-b·t) + c and return τ + R² + asymptote.

Parameters:
  • samples_df (pandas.DataFrame) – One recording’s samples (same columns as for compute_stimulus_responses()).

  • fit_start_s (float) – Where to start the fit window. Default arista.constants.ADAPTATION_FIT_START_S (75 s, the end of the canonical pre-stimulus baseline).

  • fit_end_s (float | None) – End of the fit window. None uses the recording’s last time stamp.

  • min_points (int) – Refuse to fit on fewer than this many in-window samples — 30 is enough to constrain three parameters with confidence.

Returns:

AdaptationFit on success, None if the curve_fit fails to converge, if too few points lie in the window, or if the fitted decay rate is non-positive (degenerate / no decay captured by a · exp(-b·t) with this parameterisation).

Return type:

AdaptationFit | None

arista.processing.fit_sigmoid(deltas, responses, *, max_iterations=5000)[source]

Fit a 4PL to pooled (Δtarget, ΔF/F) points.

Parameters:
  • deltas (np.ndarray | pd.Series) – x-values (Δ target temperature in °C).

  • responses (np.ndarray | pd.Series) – y-values (median ΔF/F per step).

  • max_iterations (int) – curve_fit maxfev ceiling.

Returns:

SigmoidFit on convergence, None when the data is too sparse (<4 points), perfectly flat, or when curve_fit raises.

Return type:

SigmoidFit | None

arista.processing.fit_sigmoids_by_group(response_df, *, group_keys=('strain_name', 'cell_type'), min_points=4)[source]

Run fit_sigmoid() over each group in a response frame.

Parameters:
Returns:

DataFrame with one row per group carrying bottom, top, midpoint_c, slope, r_squared, n_points plus the group key columns. Groups whose fit failed are omitted.

Return type:

pandas.DataFrame

arista.processing.four_pl(x, bottom, top, midpoint, slope)[source]

Four-parameter logistic.

bottom and top are the left/right asymptotes, midpoint is the x-value at the curve’s inflection, and slope is the curve’s slope at the midpoint (units: 1/°C).

Parameters:
Return type:

numpy.ndarray

arista.processing.process_all(conn, *, progress=None, reprocess=False)[source]

Compute aggregates for every recording missing them.

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

  • progress (bool | None) – tqdm visibility (None = auto-detect TTY, True = force on, False = force off).

  • reprocess (bool) – If True drop existing aggregates before recomputing. Useful after fixing the response formula.

Returns:

ProcessingStats with counts of inserted / already-done / failed-adaptation recordings.

Return type:

ProcessingStats

Modules

adaptation

Fit a·exp(-t/τ) + c to the post-onset segment of an adaptation trace.

gain

Linear-fit gain per recording across the stimulus-response steps.

orchestrator

Batch driver that fills stimulus_responses and adaptation_fits.

sigmoid

Four-parameter logistic (4PL) fit of ΔF/F vs Δ target temperature.

stimulus_response

Compute the per-step median response for a thermal-step recording.