Skip to content

Connectivity: cicada_tools.connectivity

from cicada_analysis.cicada_tools.connectivity.<module> import <function>


connectivity.pairwise_cell_similarity (Pairwise similarity)

Figures (plot_similarity_matrix, plot_similarity_vs_distance): display.connectivity_plots (display page).

  • compute_similarity_matrix

compute_similarity_matrix(neuronal_data=None, correlation_axis=0, method=None, verbose=False) -> np.ndarray

Dispatches to one of the four pairwise-similarity methods below. method: "Pearson" | "Hamming" | "Jaccard" | "Cosine". correlation_axis=1 transposes input first.

Parameter Type Default Description
neuronal_data np.ndarray None Neuronal data
correlation_axis int 0 Correlation axis
method str None Similarity method
verbose bool False Verbose output

Returns: np.ndarray — Similarity matrix

  • build_pearson_adjacency_matrix

build_pearson_adjacency_matrix(neuronal_data, with_thresholds=True, correlation_threshold=0.1, p_value_threshold=0.05, verbose=False, data_id="", results_path=None) -> np.ndarray

Builds an (n_cells, n_cells) Pearson adjacency matrix — thresholded (loop + p-values) or a full np.corrcoef fast path when with_thresholds=False. Optionally saves to disk.

Parameter Type Default Description
neuronal_data np.ndarray Neuronal data
with_thresholds bool True Apply thresholds
correlation_threshold float 0.1 Correlation threshold
p_value_threshold float 0.05 P-value threshold
verbose bool False Verbose output
data_id str "" Data identifier
results_path str None Results path

Returns: np.ndarray — Adjacency matrix

  • get_pairwise_hamming_similarity

get_pairwise_hamming_similarity(neuronal_data) -> np.ndarray

Pairwise Hamming similarity (1 - hamming distance) for a binary (n_cells, n_frames) matrix.

Parameter Type Description
neuronal_data np.ndarray Binary neuronal data

Returns: np.ndarray — Hamming similarity matrix

  • get_pairwise_jaccard_similarity

get_pairwise_jaccard_similarity(neuronal_data) -> np.ndarray

Pairwise Jaccard similarity for a binary matrix.

Parameter Type Description
neuronal_data np.ndarray Binary neuronal data

Returns: np.ndarray — Jaccard similarity matrix

  • get_pairwise_cosine_similarity

get_pairwise_cosine_similarity(neuronal_data) -> np.ndarray

Pairwise cosine similarity matrix (row-normalized dot product, clipped to [-1, 1]).

Parameter Type Description
neuronal_data np.ndarray Neuronal data

Returns: np.ndarray — Cosine similarity matrix

  • similarity_pairs

similarity_pairs(matrix, cells, groups, distances=None) -> pd.DataFrame

One row per pair of cells of a similarity matrix, for each pair of cell groups of its two cells: a pair is labelled with its group when both cells are in it, else 'group 1 / group 2' (in the order of the groups), so a pair appears once per label that holds both cells. Cells not in the matrix are left out.

Parameter Type Default Description
matrix np.ndarray (n, n) similarity of the cells cells, in that order
cells list[int] Cell (row of the activity series) of each row of the matrix
groups dict {group name: cell indices}, in order
distances np.ndarray None Distances between all the cells of the series, indexed by cell (not by matrix row)

Returns: pd.DataFrame — columns cell_1, cell_2 (cell_1 < cell_2), cell_group, similarity, and distance when given


connectivity.connectivity_utils (Time-correlation / cross-correlograms)

  • estimated_autocorrelation

estimated_autocorrelation(x) -> np.ndarray

Normalized autocorrelation estimate of a 1-D signal.

Parameter Type Description
x np.ndarray 1-D signal

Returns: np.ndarray — Autocorrelation

  • compute_triggered_average_raster

compute_triggered_average_raster(raster, sce_centers, window_frames) -> (mean_response, time_frames)

Peri-SCE triggered average of a binary imaging raster around a list of SCE center frames.

Parameter Type Description
raster np.ndarray Binary raster
sce_centers list SCE center frames
window_frames int Window in frames

Returns: (mean_response, time_frames) — Mean response and time frames

Figures of the triggered averages (plot_christmas_tree_heatmap, plot_christmas_tree_crosscorr): display.connectivity_plots (display page).


connectivity.connectivity_utils (Spike-triggered population rate — stPR)

Figures (plot_stpr_scatter, plot_stpr_heatmap, plot_stpr_heatmap_grid): display.connectivity_plots (display page).

  • compute_stpr

compute_stpr(spike_times_list=None, bin_size_s=0.001, window_s=0.08, lp_cutoff_hz=20.0, spike_mat=None, t_start=None, t_stop=None) -> (stpr, time_axis, coupling, delay_s, valid)

Spike-triggered population rate per unit: low-passed cross-correlation of each unit's spikes with the mean-subtracted population rate (excluding itself). coupling = value at lag 0, delay_s = centre-of-mass lag of the curve rescaled to 0–1 (NaN for a flat curve).

Parameter Type Default Description
spike_times_list list None Spike times per unit
bin_size_s float 0.001 Bin size in seconds
window_s float 0.08 Window in seconds
lp_cutoff_hz float 20.0 Low-pass cutoff in Hz
spike_mat np.ndarray None Spike matrix
t_start, t_stop float None Time range of the recording (s) over which the spikes are binned and the mean rates taken; None: first / last spike given

Returns: (stpr, time_axis, coupling, delay_s, valid) — stPR data

  • compute_stpr_cross

compute_stpr_cross(source_spike_times, target_spike_times, bin_size_s=0.001, window_s=0.08, lp_cutoff_hz=20.0, t_start=None, t_stop=None) -> (stpr, time_axis, coupling, delay_s, valid)

Cross-area stPR: source units' spikes correlated against a disjoint target population's rate (no self-exclusion needed).

Parameter Type Default Description
source_spike_times list Source spike times
target_spike_times list Target spike times
bin_size_s float 0.001 Bin size in seconds
window_s float 0.08 Window in seconds
lp_cutoff_hz float 20.0 Low-pass cutoff in Hz
t_start, t_stop float None Time range of the recording (s), as in compute_stpr; None: first / last spike of the source and target

Returns: (stpr, time_axis, coupling, delay_s, valid) — Cross-area stPR data


connectivity.connectivity_utils (Monosynaptic connection detection)

Figure of a detected pair (plot_pair_ccg): display.connectivity_plots (display page).

  • bz_detect_connections

bz_detect_connections(spike_times_list, unit_ids, min_spikes=200, bin_size_ms=0.4, max_lag_ms=100.0, hollow_ms=10.0, sigma_ms=20.0, syn_window=(1.0, 4.0)) -> pd.DataFrame

Detects putative monosynaptic connections via cross-correlograms (English et al. 2017, Neuron). Returns a DataFrame with columns unit_pre, unit_post, connection_type, peak_latency_ms, transmission_probability, peak_bin_pvalue, n_significant_bins (empty if none found).

Parameter Type Default Description
spike_times_list list Spike times per unit
unit_ids list Unit IDs
min_spikes int 200 Minimum spikes per unit
bin_size_ms float 0.4 Bin size in ms
max_lag_ms float 100.0 Maximum lag in ms
hollow_ms float 10.0 Hollow window in ms
sigma_ms float 20.0 Sigma in ms
syn_window tuple (1.0, 4.0) Synaptic window in ms

Returns: pd.DataFrame — Connection detection results

  • hollow_gaussian_baseline

hollow_gaussian_baseline(counts, bin_size_ms, hollow_ms=10.0, sigma_ms=20.0) -> np.ndarray

Gaussian-smoothed CCG baseline with a hollow (zeroed) window around lag 0, used internally by the connection-detection functions above.

Parameter Type Default Description
counts np.ndarray CCG counts
bin_size_ms float Bin size in ms
hollow_ms float 10.0 Hollow window in ms
sigma_ms float 20.0 Sigma in ms

Returns: np.ndarray — Baseline

  • ccg_peak_significance

ccg_peak_significance(counts, baseline, lag_centers, syn_window=(1.0, 4.0)) -> dict

Poisson significance test (BH-corrected) for excitatory (upper-tail) and inhibitory (lower-tail) CCG peaks/troughs within syn_window.

Parameter Type Default Description
counts np.ndarray CCG counts
baseline np.ndarray Baseline values
lag_centers np.ndarray Lag centers
syn_window tuple (1.0, 4.0) Synaptic window in ms

Returns: dict — Significance test results