API

pyDANT.Preprocess

pyDANT.Preprocess.preprocess(user_settings)

Preprocess the data and save the features. Compute the ISI, autocorrelogram, and location of each unit and save the features to the output folder.

Arguments:
  • user_settings (dict): User settings

Outputs:
  • locations.npy: The location of each unit in the 3D space

  • amplitude.npy: The amplitude of each unit

  • peak_channels.npy: The peak channel of each unit

  • auto_corr.npy: The autocorrelogram of each unit

  • isi.npy: The ISI of each unit

  • peth.npy: The peri-event time histogram of each unit

  • waveforms_centered.npy: The centered waveforms of each unit

pyDANT.Preprocess.spikeInfo2npy(user_settings)

Convert the spikeInfo.mat file from MATLAB to numpy arrays that can be used in pyDANT.

Arguments:
  • user_settings (dict): User settings

Outputs:
  • waveform_all.npy: The waveform of each unit

  • session_index.npy: The session index of each unit

  • channel_locations.npy: The location of each channel

  • spike_times/: A folder that contains the spike times of each unit

  • spike_times/UnitA.npy: The spike times of unit A

  • peth.npy: The peri-event time histogram of each unit

pyDANT.ComputeWaveformFeatures

pyDANT.ComputeWaveformFeatures.computeWaveformFeatures(user_settings, waveform_all, motion)

Compute the corrected waveforms based on the motion of the probe. The corrected waveforms on the reference probe are computed using the Kriging interpolation method and saved to the output folder.

Arguments:
  • user_settings (dict): User settings

  • waveform_all (numpy.ndarray): The waveforms of all units (n_unit, n_channel, n_sample)

  • motion (Motion): The motion object containing the linear and constant parameters for correction

Outputs:
  • waveforms_corrected.npy: The corrected waveforms.

pyDANT.MotionEstimation

pyDANT.MotionEstimation.computeMotion(user_settings)

Compute the motion of the electrode and save the results. Compute the features of each unit and do clustering the find the matching units. Motion estimation is then performed to minimize the distance between the matching units.

Arguments:
  • user_settings (dict): User settings

Outputs:
  • motion.npy: The motion of the electrode

  • SimilarityForCorretion.npz (optional): The similarity information used for motion estimation

pyDANT.MotionEstimation.initializeMotion(user_settings, waveforms_all)

Initialize the motion of the electrode based on waveform shifts.

Arguments:
  • user_settings (dict): User settings

  • waveforms_all (np.ndarray): All waveforms

Returns:
  • Motion: Initialized motion object

pyDANT.MotionEstimation.motionEstimation(user_settings)

Estimate the motion of the electrode and save the results. Compute the features of each unit and do clustering the find the matching units. Motion estimation is then performed to minimize the distance between the matching units.

Arguments:
  • user_settings (dict): User settings

Outputs:
  • motion.npy: The motion of the electrode

  • SimilarityForCorretion.npz (optional): The similarity information used for motion estimation

pyDANT.IterativeClustering

pyDANT.IterativeClustering.computeAllSimilarityMatrix(user_settings, waveforms, feature_names)

Compute the similarity matrix of the units based on the similarity metrics.

Arguments:
  • user_settings (dict): User settings

  • waveforms (ndarray): The waveforms of the units (n_units, n_channels, n_samples)

  • feature_names (list): The names of the features to be computed. The options are ‘Waveform’, ‘ISI’, ‘AutoCorr’, and ‘PETH’.

Outputs:
  • similarity_matrix_all (ndarray): The similarity matrix of the units (n_units, n_units, n_features)

  • feature_names_all (list): The names of the features computed.

  • waveform_similarity_matrix.npy: The waveform similarity matrix of the units (n_units, n_units)

  • ISI_similarity_matrix.npy: The ISI similarity matrix of the units (n_units, n_units)

  • AutoCorr_similarity_matrix.npy: The autocorrelogram similarity matrix of the units (n_units, n_units)

  • PETH_similarity_matrix.npy: The PETH similarity matrix of the units (n_units, n_units)

pyDANT.IterativeClustering.finalClustering(user_settings)

Final clustering of the units based on the similarity metrics using HDBSCAN and LDA.

Arguments:
  • user_settings (dict): User settings

pyDANT.IterativeClustering.getNearbyPairs(max_distance, sessions, locations, motion=None)

Get the pairs of units that are within the max_distance.

Arguments:
  • max_distance (float): The maximum distance between the units.

  • sessions (ndarray): The session index of the units.

  • locations (ndarray): The locations of the units.

  • motion (ndarray): The motion of the probe.

Outputs:
  • idx_unit_pairs (ndarray): The pairs of units that are within the max_distance.

  • session_pairs (ndarray): The session index of the pairs of units.

pyDANT.IterativeClustering.iterativeClustering(user_settings, similarity_names, waveforms, motion=None)

Iterative clustering of the units based on the similarity metrics using HDBSCAN and LDA. The similarity metrics are computed firstly, and then HDBSCAN and LDA are performed alternatively to find the best clustering results. The clustering results are saved to the output folder.

Arguments:
  • user_settings (dict): User settings

  • similarity_names (list): The names of the similarity metrics to be computed. The options are ‘Waveform’, ‘ISI’, ‘AutoCorr’, and ‘PETH’.

Outputs:
  • SimilarityMatrix.npy: The similarity matrix of the units

  • SimilarityWeights.npy: The weights of the similarity metrics

  • SimilarityThreshold.npy: The threshold of the similarity metrics from LDA

  • ClusteringResults.npz: The clustering results of the units

  • DistanceMatrix.npy: The distance matrix used for HDBSCAN

  • waveform_similarity_matrix.npy: The waveform similarity matrix of the units

  • ISI_similarity_matrix.npy: The ISI similarity matrix of the units

  • AutoCorr_similarity_matrix.npy: The autocorrelogram similarity matrix of the units

  • PETH_similarity_matrix.npy: The PETH similarity matrix of the units

  • AllSimilarity.npz (optional): The similarity metrics of all units used for clustering

pyDANT.utils

class pyDANT.utils.Motion(num_sessions=None)

Class to handle motion estimation data. This class allows for saving and loading motion data, as well as retrieving motion values for specific sessions.

Attributes:
  • LinearScale: scaling factor for linear motion (default: 0.001)

  • Linear: linear motion parameters for each session (if num_sessions is provided)

  • Constant: constant motion parameters for each session (if num_sessions is provided)

Methods:
  • __init__(num_sessions=None): Initializes the Motion object.

  • save(output_folder): Saves the motion data to a file.

  • load(output_folder): Loads the motion data from a file.

  • get_motion(session, depth=None): Retrieves the motion for a specific session, optionally considering depth.

get_motion(session, depth=None)

Get the motion for a specific session.

Args:

session (int): The session number. depth (float, optional): The depth value. If None, only the constant motion is returned.

Returns:

float: The motion value for the specified session and depth.

static load(output_folder)

Load the motion data from a file.

Args:

output_folder (str): Path to the folder where the motion data is saved.

Returns:

Motion: An instance of the Motion class with loaded data.

save(output_folder)

Save the motion data to a file.

Args:

output_folder (str): Path to the folder where the motion data will be saved.

Returns:

None

pyDANT.utils.computeAutoCorr(spike_times, window, binwidth)

Compute the autocorrelation of spike times.

Refer to the elegant Python impletantation from phylib:

https://github.com/cortex-lab/phylib/blob/master/phylib/stats/ccg.py#L34

Arguments:
  • spike_times: 1D array of spike times

  • window: time window for autocorrelation (in ms, default: 300 ms)

  • binwidth: width of the bins for histogram (in ms, default: 1 ms)

Returns:
  • auto_corr: autocorrelation values

  • lag: lag values

pyDANT.utils.computeKernel2D(xp, yp, sig=20)

Compute the 2D kernel matrix for the given points xp and yp.

Arguments:
  • xp: 2D array of points (n_samples, 2)

  • yp: 2D array of points (n_samples, 2)

  • sig: standard deviation for the Gaussian kernel (default: 20)

Returns:
  • K: kernel matrix (n_samples_xp, n_samples_yp)

pyDANT.utils.corrcoef2(x, y)

Compute the Pearson correlation coefficient between two matrices x and y.

Arguments:
  • x: 2D array of shape (n_samples, n_features_x)

  • y: 2D array of shape (n_samples, n_features_y)

Returns:
  • r: Pearson correlation coefficient matrix of shape (n_features_x, n_features_y)

pyDANT.utils.graphEditNumber(matA, matB)

Compute the merge number of two graphs A and B and the number of same merges.

Arguments:
  • matA: connectivity matrix of graph A (n_nodes_A, n_nodes_A)

  • matB: connectivity matrix of graph B (n_nodes_B, n_nodes_B)

Returns:
  • nSame: number of same merges

  • nA: number of merges in graph A

  • nB: number of merges in graph B

pyDANT.utils.spikeLocation(waveforms_mean, channel_locations, n_nearest_channels=20, algorithm='monopolar_triangulation')

Spike location estimation using either center_of_mass or monopolar_triangulation

monopolar_triangulation: refer to Boussard, Julien, Erdem Varol, Hyun Dong Lee, Nishchal Dethe, and Liam Paninski. “Three-Dimensional Spike Localization and Improved Motion Correction for Neuropixels Recordings.” In Advances in Neural Information Processing Systems, 34:22095–105. Curran Associates, Inc., 2021. https://proceedings.neurips.cc/paper/2021/hash/b950ea26ca12daae142bd74dba4427c8-Abstract.html. > https://spikeinterface.readthedocs.io/en/stable/modules/postprocessing.html#spike-locations > https://github.com/SpikeInterface/spikeinterface/blob/main/src/spikeinterface/postprocessing/localization_tools.py#L334

Arguments:
  • waveforms_mean: mean waveforms (n_channels, n_samples)

  • channel_locations: 2D array of channel locations (n_channels, 2)

  • n_nearest_channels: number of nearest channels to consider for localization, default is 20

  • algorithm: ‘center_of_mass’ or ‘monopolar_triangulation’, default is ‘monopolar_triangulation’

returns:
  • x: x coordinate of the spike location

  • y: y coordinate of the spike location

  • z: z coordinate of the spike location

  • ptt: peak-to-trough value of the spike waveform

pyDANT.utils.waveformEstimation(waveform_mean, location, channel_locations, location_new)

Waveform estimation with Kriging interpolation.

Arguments:
  • waveform_mean: mean waveform (n_channels, n_samples)

  • location: original location of the spike (x, y), 1D array of length 2

  • channel_locations: 2D array of channel locations (n_channels, 2)

  • location_new: new location of the spike (x, y), 1D array of length 2

Returns:
  • waveform_out: estimated waveform at the new location (n_samples)