Skip to content

Sequences detection: cicada_tools.sequences

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

Sequence detection from calcium imaging data (Villette et al. 2015). Not re-exported at package level: import from the submodule:

from cicada_analysis.cicada_tools.sequences.malvache.utils_malvache_sequences import step1_pca_off_memory

sequences.malvache.utils_malvache_sequences (PCA-based sequence detection)

Used by the cicada_seq_malvache_analysis plugin:

  • step1_pca_off_memory

step1_pca_off_memory(data, n_pc_max) -> (data_centralized, pc_time_course)

PCA on the lag-1 temporal covariance matrix, matrix-free (ARPACK): avoids forming the full n_times × n_times covariance matrix.

Parameter Type Description
data np.ndarray Input data
n_pc_max int Maximum number of PCs

Returns: (data_centralized, pc_time_course)

  • covnorm_vectorized

covnorm_vectorized(A, b, lags) -> np.ndarray

Normalized cross-covariance between each row of A and b, for lags -lags to +lags.

Parameter Type Description
A np.ndarray Signal matrix
b np.ndarray Target signal
lags int Number of lags

Returns: np.ndarray — Vectorized cross-covariance

  • centralize_data

centralize_data(data) -> np.ndarray

Double-centers a (cells × times) matrix.

Parameter Type Description
data np.ndarray Input matrix

Returns: np.ndarray — Centered matrix

  • convert_position_to_distance

convert_position_to_distance(positions, loop_length) -> (total_traveled_distance, n_laps)

Converts a circular-track position trace into cumulative distance traveled.

Parameter Type Description
positions np.ndarray Position trace
loop_length float Loop length

Returns: (total_traveled_distance, n_laps)

  • normalize_array_0_255

normalize_array_0_255(img_array) -> np.ndarray

Min-max rescaling to 0-255, cast to uint8 (truncated, not rounded), e.g. to save a matrix as an image. A constant array is only cast to uint8, not rescaled.

Parameter Type Description
img_array np.ndarray Values to rescale

Returns: np.ndarray — uint8, same shape