neuralib.imaging.spikes.cascade

Cascade

Cascade translates calcium imaging ΔF/F traces into spiking probabilities or discrete spikes

See also the source example from the authors

Example of usage

from neuralib.imaging.spikes.cascade import cascade_predict

# 2D dF/F array. Array[float, [nNeurons, nFrames]] or Array[float, nFrames]
dff = ...

# select your model, predict the spike probability from the dF/F (same shape)
spks = cascade_predict(dff, model_type='Global_EXC_30Hz_smoothing100ms')
typeddict neuralib.imaging.spikes.cascade.CascadeModelConfig[source]

typing.TypedDict.

Optional Keys:
  • model_name (str) – Name of the model

  • sampling_rate (int) – Sampling rate in Hz

  • training_datasets (list[str]) – Dataset of ground truth data (in folder ‘Ground_truth’)

  • placeholder_1 (int) – protect formatting

  • noise_levels (list[int]) – Noise levels for training (integers, normally 1-9)

  • placeholder_2 (int) – protect formatting

  • smoothing (float) – Standard deviation of Gaussian smoothing in time (sec)

  • causal_kernel (int) – Smoothing kernel is symmetric in time (0) or is causal (1)

  • windowsize (int) – Windowsize in timepoints

  • before_frac (float) – Fraction of timepoints before prediction point (0-1)

  • filter_sizes (list[int]) – Filter sizes for each convolutional layer

  • filter_numbers (list[int]) – Filter numbers for each convolutional layer

  • dense_expansion (int) – For dense layer

  • loss_function (str) – gradient-descent loss function

  • optimizer (str) – Adagrad

  • nr_of_epochs (int) – Number of training epochs per model

  • ensemble_size (int) – Number of models trained for one noise level

  • batch_size (int) – Batch size

  • training_finished (Literal['Yes', 'No', 'Running']) – Yes / No / Running

  • verbose (int) – level of status messages (0: minimal, 1: standard, 2: most, 3: all)

neuralib.imaging.spikes.cascade.cascade_predict(dff, model_type, *, threshold=0, padding=0, verbose=True, chunks_mode_limit=10, cache_dir=None)[source]

Spike prediction using Cascade pretrained model

Parameters:
  • dff (ndarray) – dF/F activity to be predicted. Array[float, [N, F]|F]

  • model_type (Literal['Global_EXC_1Hz_smoothing500ms', 'Global_EXC_1Hz_smoothing1000ms', 'Zebrafish_1Hz_smoothing1000ms', 'Global_EXC_2Hz_smoothing300ms', 'Global_EXC_2Hz_smoothing500ms', 'Global_EXC_2Hz_smoothing1000ms', 'Global_EXC_2.5Hz_smoothing400ms_high_noise', 'Global_EXC_3Hz_smoothing400ms', 'Global_EXC_3Hz_smoothing400ms_high_noise', 'Global_EXC_3Hz_smoothing400ms_causalkernel', 'Global_EXC_4.25Hz_smoothing300ms', 'Global_EXC_4.25Hz_smoothing300ms_high_noise', 'Global_EXC_4.25Hz_smoothing300ms_causalkernel', 'Global_EXC_5Hz_smoothing200ms', 'Global_EXC_5Hz_smoothing200ms_causalkernel', 'Global_EXC_6Hz_smoothing200ms', 'Global_EXC_6Hz_smoothing200ms_causalkernel', 'Global_EXC_7Hz_smoothing200ms', 'Global_EXC_7Hz_smoothing200ms_causalkernel', 'Global_EXC_7.5Hz_smoothing200ms_high_noise', 'Global_EXC_7.5Hz_smoothing200ms', 'Global_EXC_7.5Hz_smoothing200ms_causalkernel', 'OGB_zf_pDp_7.5Hz_smoothing200ms', 'OGB_zf_pDp_7.5Hz_smoothing200ms_causalkernel', 'Global_EXC_10Hz_smoothing50ms', 'Global_EXC_10Hz_smoothing50ms_causalkernel', 'Global_EXC_10Hz_smoothing100ms', 'Global_EXC_10Hz_smoothing100ms_causalkernel', 'Global_EXC_10Hz_smoothing200ms', 'Global_EXC_10Hz_smoothing200ms_causalkernel', 'Global_EXC_12.5Hz_smoothing100ms', 'Global_EXC_12.5Hz_smoothing100ms_causalkernel', 'Global_EXC_12.5Hz_smoothing200ms', 'Global_EXC_12.5Hz_smoothing200ms_causalkernel', 'Global_EXC_15Hz_smoothing50ms', 'Global_EXC_15Hz_smoothing50ms_causalkernel', 'Global_EXC_15Hz_smoothing100ms_high_noise', 'Global_EXC_15Hz_smoothing100ms', 'Global_EXC_15Hz_smoothing100ms_causalkernel', 'Global_EXC_15Hz_smoothing200ms', 'Global_EXC_15Hz_smoothing200ms_causalkernel', 'Global_INH_15Hz_smoothing100ms', 'Global_EXC_17.5Hz_smoothing100ms', 'Global_EXC_17.5Hz_smoothing100ms_causalkernel', 'Global_EXC_17.5Hz_smoothing200ms', 'Global_EXC_17.5Hz_smoothing200ms_causalkernel', 'Global_EXC_20Hz_smoothing100ms', 'Global_EXC_20Hz_smoothing100ms_causalkernel', 'Global_EXC_20Hz_smoothing200ms', 'Global_EXC_20Hz_smoothing200ms_causalkernel', 'Global_EXC_25Hz_smoothing100ms', 'Global_EXC_25Hz_smoothing100ms_causalkernel', 'Global_EXC_25Hz_smoothing50ms', 'Global_EXC_25Hz_smoothing50ms_causalkernel', 'Global_EXC_30Hz_smoothing25ms', 'Global_EXC_30Hz_smoothing25ms_causalkernel', 'Global_EXC_30Hz_smoothing50ms', 'Global_EXC_30Hz_smoothing50ms_high_noise', 'Global_EXC_30Hz_smoothing50ms_causalkernel', 'Global_EXC_30Hz_smoothing100ms', 'Global_EXC_30Hz_smoothing100ms_causalkernel', 'Global_EXC_30Hz_smoothing200ms', 'Global_EXC_30Hz_smoothing100ms_causalkernel_high_noise', 'Global_EXC_30Hz_smoothing100ms_high_noise', 'Global_EXC_30Hz_smoothing200ms_causalkernel_high_noise', 'Global_EXC_40Hz_smoothing25ms_causalkernel', 'Global_EXC_40Hz_smoothing25ms', 'Global_EXC_40Hz_smoothing25ms_high_noise', 'Global_EXC_40Hz_smoothing50ms', 'Global_EXC_40Hz_smoothing50ms_high_noise', 'Global_EXC_40Hz_smoothing50ms_causalkernel', 'Global_INH_30Hz_smoothing50ms', 'Global_INH_30Hz_smoothing100ms', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_1_frame', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_2_frames', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_4_frames', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_6_frames', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_8_frames', 'GCaMP6f_mouse_30Hz_smoothing200ms', 'Spinal_cord_excitatory_30Hz_smoothing50ms', 'Spinal_cord_inhibitory_30Hz_smoothing50ms', 'Spinal_cord_excitatory_3Hz_smoothing400ms_high_noise', 'Spinal_cord_inhibitory_3Hz_smoothing400ms_high_noise', 'Spinal_cord_excitatory_2.5Hz_smoothing400ms', 'Spinal_cord_inhibitory_2.5Hz_smoothing400ms', 'GC8_EXC_5Hz_smoothing400ms_high_noise', 'GC8_EXC_5Hz_smoothing800ms_high_noise', 'GC8_EXC_7.5Hz_smoothing100ms_high_noise', 'GC8_EXC_7.5Hz_smoothing200ms_high_noise', 'GC8_EXC_10Hz_smoothing150ms_high_noise', 'GC8_EXC_10Hz_smoothing75ms_high_noise', 'GC8_EXC_15Hz_smoothing100ms_high_noise', 'GC8_EXC_15Hz_smoothing50ms_high_noise', 'GC8_EXC_30Hz_smoothing25ms_high_noise', 'GC8_EXC_30Hz_smoothing50ms_high_noise', 'GC8_EXC_40Hz_smoothing15ms_high_noise', 'GC8_EXC_40Hz_smoothing30ms_high_noise']) – MODEL_TYPE

  • threshold (int | bool) – Allowed values: 0, 1 or False. 0: All negative values are set to 0. 1 or True: Threshold signal to set every signal which is smaller than the expected signal size of an action potential to zero (with dilated mask) False: No thresholding. The result can contain negative values as well

  • padding (float) – Value which is inserted for datapoints, where no prediction can be made (because of window around timepoint of prediction). Default value: np.nan, another recommended value would be 0 which circumvents some problems with following analysis.

  • verbose (bool) – Verbose of model information

  • chunks_mode_limit (float) – Decrease the number if memory issue dealing with large input arrays.

  • cache_dir (str | Path | bytes | BinaryIO | BufferedIOBase | BufferedReader | None) – Cache directory for saving the model. If None, then used default under ~/.cache/neuralib

Returns:

Spiking probability as predicted by the model. Array[float, [N, F]|F]

Return type:

ndarray

class neuralib.imaging.spikes.cascade.CascadeSpikePrediction[source]
__init__(dff, model_type, *, threshold=0, padding=0, verbose=True, chunks_mode_limit=10, cache_dir=None)[source]
Parameters:
  • dff (ndarray) – dF/F activity to be predicted. Array[float, [N, F]|F]

  • model_type (Literal['Global_EXC_1Hz_smoothing500ms', 'Global_EXC_1Hz_smoothing1000ms', 'Zebrafish_1Hz_smoothing1000ms', 'Global_EXC_2Hz_smoothing300ms', 'Global_EXC_2Hz_smoothing500ms', 'Global_EXC_2Hz_smoothing1000ms', 'Global_EXC_2.5Hz_smoothing400ms_high_noise', 'Global_EXC_3Hz_smoothing400ms', 'Global_EXC_3Hz_smoothing400ms_high_noise', 'Global_EXC_3Hz_smoothing400ms_causalkernel', 'Global_EXC_4.25Hz_smoothing300ms', 'Global_EXC_4.25Hz_smoothing300ms_high_noise', 'Global_EXC_4.25Hz_smoothing300ms_causalkernel', 'Global_EXC_5Hz_smoothing200ms', 'Global_EXC_5Hz_smoothing200ms_causalkernel', 'Global_EXC_6Hz_smoothing200ms', 'Global_EXC_6Hz_smoothing200ms_causalkernel', 'Global_EXC_7Hz_smoothing200ms', 'Global_EXC_7Hz_smoothing200ms_causalkernel', 'Global_EXC_7.5Hz_smoothing200ms_high_noise', 'Global_EXC_7.5Hz_smoothing200ms', 'Global_EXC_7.5Hz_smoothing200ms_causalkernel', 'OGB_zf_pDp_7.5Hz_smoothing200ms', 'OGB_zf_pDp_7.5Hz_smoothing200ms_causalkernel', 'Global_EXC_10Hz_smoothing50ms', 'Global_EXC_10Hz_smoothing50ms_causalkernel', 'Global_EXC_10Hz_smoothing100ms', 'Global_EXC_10Hz_smoothing100ms_causalkernel', 'Global_EXC_10Hz_smoothing200ms', 'Global_EXC_10Hz_smoothing200ms_causalkernel', 'Global_EXC_12.5Hz_smoothing100ms', 'Global_EXC_12.5Hz_smoothing100ms_causalkernel', 'Global_EXC_12.5Hz_smoothing200ms', 'Global_EXC_12.5Hz_smoothing200ms_causalkernel', 'Global_EXC_15Hz_smoothing50ms', 'Global_EXC_15Hz_smoothing50ms_causalkernel', 'Global_EXC_15Hz_smoothing100ms_high_noise', 'Global_EXC_15Hz_smoothing100ms', 'Global_EXC_15Hz_smoothing100ms_causalkernel', 'Global_EXC_15Hz_smoothing200ms', 'Global_EXC_15Hz_smoothing200ms_causalkernel', 'Global_INH_15Hz_smoothing100ms', 'Global_EXC_17.5Hz_smoothing100ms', 'Global_EXC_17.5Hz_smoothing100ms_causalkernel', 'Global_EXC_17.5Hz_smoothing200ms', 'Global_EXC_17.5Hz_smoothing200ms_causalkernel', 'Global_EXC_20Hz_smoothing100ms', 'Global_EXC_20Hz_smoothing100ms_causalkernel', 'Global_EXC_20Hz_smoothing200ms', 'Global_EXC_20Hz_smoothing200ms_causalkernel', 'Global_EXC_25Hz_smoothing100ms', 'Global_EXC_25Hz_smoothing100ms_causalkernel', 'Global_EXC_25Hz_smoothing50ms', 'Global_EXC_25Hz_smoothing50ms_causalkernel', 'Global_EXC_30Hz_smoothing25ms', 'Global_EXC_30Hz_smoothing25ms_causalkernel', 'Global_EXC_30Hz_smoothing50ms', 'Global_EXC_30Hz_smoothing50ms_high_noise', 'Global_EXC_30Hz_smoothing50ms_causalkernel', 'Global_EXC_30Hz_smoothing100ms', 'Global_EXC_30Hz_smoothing100ms_causalkernel', 'Global_EXC_30Hz_smoothing200ms', 'Global_EXC_30Hz_smoothing100ms_causalkernel_high_noise', 'Global_EXC_30Hz_smoothing100ms_high_noise', 'Global_EXC_30Hz_smoothing200ms_causalkernel_high_noise', 'Global_EXC_40Hz_smoothing25ms_causalkernel', 'Global_EXC_40Hz_smoothing25ms', 'Global_EXC_40Hz_smoothing25ms_high_noise', 'Global_EXC_40Hz_smoothing50ms', 'Global_EXC_40Hz_smoothing50ms_high_noise', 'Global_EXC_40Hz_smoothing50ms_causalkernel', 'Global_INH_30Hz_smoothing50ms', 'Global_INH_30Hz_smoothing100ms', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_1_frame', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_2_frames', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_4_frames', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_6_frames', 'Global_EXC_30Hz_smoothing50ms_asymmetric_window_8_frames', 'GCaMP6f_mouse_30Hz_smoothing200ms', 'Spinal_cord_excitatory_30Hz_smoothing50ms', 'Spinal_cord_inhibitory_30Hz_smoothing50ms', 'Spinal_cord_excitatory_3Hz_smoothing400ms_high_noise', 'Spinal_cord_inhibitory_3Hz_smoothing400ms_high_noise', 'Spinal_cord_excitatory_2.5Hz_smoothing400ms', 'Spinal_cord_inhibitory_2.5Hz_smoothing400ms', 'GC8_EXC_5Hz_smoothing400ms_high_noise', 'GC8_EXC_5Hz_smoothing800ms_high_noise', 'GC8_EXC_7.5Hz_smoothing100ms_high_noise', 'GC8_EXC_7.5Hz_smoothing200ms_high_noise', 'GC8_EXC_10Hz_smoothing150ms_high_noise', 'GC8_EXC_10Hz_smoothing75ms_high_noise', 'GC8_EXC_15Hz_smoothing100ms_high_noise', 'GC8_EXC_15Hz_smoothing50ms_high_noise', 'GC8_EXC_30Hz_smoothing25ms_high_noise', 'GC8_EXC_30Hz_smoothing50ms_high_noise', 'GC8_EXC_40Hz_smoothing15ms_high_noise', 'GC8_EXC_40Hz_smoothing30ms_high_noise']) – MODEL_TYPE

  • threshold (int | bool) – Allowed values: 0, 1 or False. 0: All negative values are set to 0. 1 or True: Threshold signal to set every signal which is smaller than the expected signal size of an action potential to zero (with dilated mask) False: No thresholding. The result can contain negative values as well

  • padding (float) – Value which is inserted for datapoints, where no prediction can be made (because of window around timepoint of prediction). Default value: np.nan, another recommended value would be 0 which circumvents some problems with following analysis.

  • verbose (bool) – Verbose of model information

  • chunks_mode_limit (float) – Decrease the number if memory issue dealing with large input arrays.

  • cache_dir (str | Path | bytes | BinaryIO | BufferedIOBase | BufferedReader | None) – Cache directory for saving the model. If None, then used default under ~/.cache/neuralib

property available_model_yaml: Path

All models link/info yaml

get_available_models()[source]

Get all the available in available_model_yaml

Return type:

list[Literal[‘Global_EXC_1Hz_smoothing500ms’, ‘Global_EXC_1Hz_smoothing1000ms’, ‘Zebrafish_1Hz_smoothing1000ms’, ‘Global_EXC_2Hz_smoothing300ms’, ‘Global_EXC_2Hz_smoothing500ms’, ‘Global_EXC_2Hz_smoothing1000ms’, ‘Global_EXC_2.5Hz_smoothing400ms_high_noise’, ‘Global_EXC_3Hz_smoothing400ms’, ‘Global_EXC_3Hz_smoothing400ms_high_noise’, ‘Global_EXC_3Hz_smoothing400ms_causalkernel’, ‘Global_EXC_4.25Hz_smoothing300ms’, ‘Global_EXC_4.25Hz_smoothing300ms_high_noise’, ‘Global_EXC_4.25Hz_smoothing300ms_causalkernel’, ‘Global_EXC_5Hz_smoothing200ms’, ‘Global_EXC_5Hz_smoothing200ms_causalkernel’, ‘Global_EXC_6Hz_smoothing200ms’, ‘Global_EXC_6Hz_smoothing200ms_causalkernel’, ‘Global_EXC_7Hz_smoothing200ms’, ‘Global_EXC_7Hz_smoothing200ms_causalkernel’, ‘Global_EXC_7.5Hz_smoothing200ms_high_noise’, ‘Global_EXC_7.5Hz_smoothing200ms’, ‘Global_EXC_7.5Hz_smoothing200ms_causalkernel’, ‘OGB_zf_pDp_7.5Hz_smoothing200ms’, ‘OGB_zf_pDp_7.5Hz_smoothing200ms_causalkernel’, ‘Global_EXC_10Hz_smoothing50ms’, ‘Global_EXC_10Hz_smoothing50ms_causalkernel’, ‘Global_EXC_10Hz_smoothing100ms’, ‘Global_EXC_10Hz_smoothing100ms_causalkernel’, ‘Global_EXC_10Hz_smoothing200ms’, ‘Global_EXC_10Hz_smoothing200ms_causalkernel’, ‘Global_EXC_12.5Hz_smoothing100ms’, ‘Global_EXC_12.5Hz_smoothing100ms_causalkernel’, ‘Global_EXC_12.5Hz_smoothing200ms’, ‘Global_EXC_12.5Hz_smoothing200ms_causalkernel’, ‘Global_EXC_15Hz_smoothing50ms’, ‘Global_EXC_15Hz_smoothing50ms_causalkernel’, ‘Global_EXC_15Hz_smoothing100ms_high_noise’, ‘Global_EXC_15Hz_smoothing100ms’, ‘Global_EXC_15Hz_smoothing100ms_causalkernel’, ‘Global_EXC_15Hz_smoothing200ms’, ‘Global_EXC_15Hz_smoothing200ms_causalkernel’, ‘Global_INH_15Hz_smoothing100ms’, ‘Global_EXC_17.5Hz_smoothing100ms’, ‘Global_EXC_17.5Hz_smoothing100ms_causalkernel’, ‘Global_EXC_17.5Hz_smoothing200ms’, ‘Global_EXC_17.5Hz_smoothing200ms_causalkernel’, ‘Global_EXC_20Hz_smoothing100ms’, ‘Global_EXC_20Hz_smoothing100ms_causalkernel’, ‘Global_EXC_20Hz_smoothing200ms’, ‘Global_EXC_20Hz_smoothing200ms_causalkernel’, ‘Global_EXC_25Hz_smoothing100ms’, ‘Global_EXC_25Hz_smoothing100ms_causalkernel’, ‘Global_EXC_25Hz_smoothing50ms’, ‘Global_EXC_25Hz_smoothing50ms_causalkernel’, ‘Global_EXC_30Hz_smoothing25ms’, ‘Global_EXC_30Hz_smoothing25ms_causalkernel’, ‘Global_EXC_30Hz_smoothing50ms’, ‘Global_EXC_30Hz_smoothing50ms_high_noise’, ‘Global_EXC_30Hz_smoothing50ms_causalkernel’, ‘Global_EXC_30Hz_smoothing100ms’, ‘Global_EXC_30Hz_smoothing100ms_causalkernel’, ‘Global_EXC_30Hz_smoothing200ms’, ‘Global_EXC_30Hz_smoothing100ms_causalkernel_high_noise’, ‘Global_EXC_30Hz_smoothing100ms_high_noise’, ‘Global_EXC_30Hz_smoothing200ms_causalkernel_high_noise’, ‘Global_EXC_40Hz_smoothing25ms_causalkernel’, ‘Global_EXC_40Hz_smoothing25ms’, ‘Global_EXC_40Hz_smoothing25ms_high_noise’, ‘Global_EXC_40Hz_smoothing50ms’, ‘Global_EXC_40Hz_smoothing50ms_high_noise’, ‘Global_EXC_40Hz_smoothing50ms_causalkernel’, ‘Global_INH_30Hz_smoothing50ms’, ‘Global_INH_30Hz_smoothing100ms’, ‘Global_EXC_30Hz_smoothing50ms_asymmetric_window_1_frame’, ‘Global_EXC_30Hz_smoothing50ms_asymmetric_window_2_frames’, ‘Global_EXC_30Hz_smoothing50ms_asymmetric_window_4_frames’, ‘Global_EXC_30Hz_smoothing50ms_asymmetric_window_6_frames’, ‘Global_EXC_30Hz_smoothing50ms_asymmetric_window_8_frames’, ‘GCaMP6f_mouse_30Hz_smoothing200ms’, ‘Spinal_cord_excitatory_30Hz_smoothing50ms’, ‘Spinal_cord_inhibitory_30Hz_smoothing50ms’, ‘Spinal_cord_excitatory_3Hz_smoothing400ms_high_noise’, ‘Spinal_cord_inhibitory_3Hz_smoothing400ms_high_noise’, ‘Spinal_cord_excitatory_2.5Hz_smoothing400ms’, ‘Spinal_cord_inhibitory_2.5Hz_smoothing400ms’, ‘GC8_EXC_5Hz_smoothing400ms_high_noise’, ‘GC8_EXC_5Hz_smoothing800ms_high_noise’, ‘GC8_EXC_7.5Hz_smoothing100ms_high_noise’, ‘GC8_EXC_7.5Hz_smoothing200ms_high_noise’, ‘GC8_EXC_10Hz_smoothing150ms_high_noise’, ‘GC8_EXC_10Hz_smoothing75ms_high_noise’, ‘GC8_EXC_15Hz_smoothing100ms_high_noise’, ‘GC8_EXC_15Hz_smoothing50ms_high_noise’, ‘GC8_EXC_30Hz_smoothing25ms_high_noise’, ‘GC8_EXC_30Hz_smoothing50ms_high_noise’, ‘GC8_EXC_40Hz_smoothing15ms_high_noise’, ‘GC8_EXC_40Hz_smoothing30ms_high_noise’]]

Link of specified model

property model_dir: Path

Directory of specified model

property config_file

Config filepath of specified model

get_config()[source]

ModelConfig of specified model

Return type:

CascadeModelConfig

run_spike_prediction()[source]

Spike prediction

Returns:

Spiking probability as predicted by the model. Array[float, [N, F]|F]

Return type:

ndarray