No project description provided
Project description
pyKilomatch
This project is a Python implementation of Kilomatch, converted from the original MATLAB code.
Installation
- It is recommended to install the pyKilomatch package using Anaconda:
conda create -n pyKilomatch python=3.11
conda activate pyKilomatch
pip install pyKilomatch
How to use it
Prepare the data
- Your data should be organized in a folder with the following structure:
data_folder
├── channel_locations.npy
├── waveform_all.npy
├── session_index.npy
├── peth.npy (optional)
└── spike_times/
├── Unit0.npy
├── Unit1.npy
├── Unit2.npy
└── ...
└── UnitN.npy
-
The data files should adhere to the following formats:
session_index.npy: An array of lengthn_unitindicating the session for each unit. Session indices should start from 1 and be continuous without gaps.waveform_all.npy: Ann_unitxn_channelxn_sampletensor containing the mean waveform of each unit in μV. All units must share the same set of channels.channel_locations.npy: Ann_channelx 2 double array specifying the (x, y) coordinates (in μm) of each channel. The y-coordinate typically represents the depth.peth.npy: (Optional but recommended) Ann_unitxn_pointdouble array containing the peri-event time histogram for each unit.spike_times/UnitX.npy: An array of spike times (in milliseconds) for unitX. The filenames should follow the patternUnitX.npy, whereXis the unit index starting from 0 and incrementing continuously without gaps.
-
Specify the path to your data in the
settings.jsonfile. -
Edit the
settings.jsonfile to set thepath_to_dataandoutput_folder. -
Adjust other parameters within
settings.jsonto match your specific data characteristics.
Running the Code
- After configuring the
settings.jsonfile and ensuring the path to it is correctly specified inmainKilomatch.py, execute the following commands in your terminal:
conda activate pyKilomatch
python mainKilomatch.py
About the output
- All temporary files, results, and generated figures will be saved in the
output_folderdefined in yoursettings.jsonfile. - The
output_folderwill contain the following result files:auto_corr.npy: Ann_unitxn_pointdouble array containing the auto-correlation of each unit.isi.npy: Ann_unitxn_pointdouble array containing the inter-spike interval (ISI) of each unit.peth.npy: Ann_unitxn_pointdouble array containing the peri-event time histogram (PETH) of each unit.waveforms.npy: Ann_unitxn_nearest_channelxn_sampletensor of the mean waveform for each unit (in μV) before motion correction.waveforms_corrected.npy: Ann_unitxn_nearest_channelxn_sampletensor of the mean waveform for each unit (in μV) after motion correction.waveform_channels.npy: Ann_unitxn_nearest_channelinteger array indicating the channel index for each unit's waveform.locations.npy: Ann_unitx 3 double array containing the estimated x, y, and z coordinates of each unit.IdxCluster.npy: Ann_unitx 1 integer array assigning a cluster index to each unit. Units not assigned to any cluster are marked with-1.ClusterMatrix.npy: Ann_unitxn_unitlogical matrix representing cluster assignments.ClusterMatrix(i, j) = 1indicates that unitiand unitjbelong to the same cluster.MatchedPairs.npy: Ann_pairsx 2 integer matrix listing the unit indices for each pair of units within the same cluster.SimilarityWeights.npy: Ann_featuresx 1 double array containing the weights of the similarity metrics computed by the IHDBSCAN algorithm.SimilarityThreshold.npy: A 1 x 1 double value representing the threshold used to identify good matches in theGoodMatchesMatrixduring the auto-curation process.SimilarityMatrix.npy: Ann_unitxn_unitdouble matrix representing the weighted sum of similarities between each pair of units.motion.npy: An_sessionx 1 double array indicating the estimated electrode positions for each session.ClusteringResults.npz: A compressed file containing the clustering results after motion correction.CurationResults.npz: A compressed file containing the curation results after motion correction.Output.npz: A compressed file containing the final results of the Kilomatch analysis.
Notes
- pyKilomatch is a conversion from MATLAB and is currently undergoing testing. Please report any bugs or issues you encounter.
- For recordings using multi-shank probes, it is recommended to analyze each shank independently. The current Python version of Kilomatch is not yet designed to handle multi-shank data simultaneously.
- Be careful that the waveforms included in this analysis should not be whitened as Kilosort does. Do not use the waveforms extracted from
temp_wh.datdirectly. Do not usewhitening_mat_inv.npyorwhitening_mat.npyin Kilosort2.5 / Kilosort3 because they are not what Kilosort used to whiten the data (https://github.com/cortex-lab/phy/issues/1040)! - Please analyze data from different brain regions like cortex and striatum individually since they might have different drifts and neuronal properties.
- Please raise an issue if you meet any bugs or have any questions. We are looking forward to your feedback!
References
HDBSCAN
HDBSCAN - Hierarchical Density-Based Spatial Clustering of Applications with Noise. Performs DBSCAN over varying epsilon values and integrates the result to find a clustering that gives the best stability over epsilon. This allows HDBSCAN to find clusters of varying densities (unlike DBSCAN), and be more robust to parameter selection.Campello, R.J.G.B., Moulavi, D., Sander, J. (2013). Density-Based Clustering Based on Hierarchical Density Estimates. In: Pei, J., Tseng, V.S., Cao, L., Motoda, H., Xu, G. (eds) Advances in Knowledge Discovery and Data Mining. PAKDD 2013. Lecture Notes in Computer Science(), vol 7819. Springer, Berlin, Heidelberg. Density-Based Clustering Based on Hierarchical Density Estimates
L. McInnes and J. Healy, (2017). Accelerated Hierarchical Density Based Clustering. In: IEEE International Conference on Data Mining Workshops (ICDMW), 2017, pp. 33-42. Accelerated Hierarchical Density Based Clustering
Kilosort
Fast spike sorting with drift correctionPachitariu, Marius, Shashwat Sridhar, Jacob Pennington, and Carsen Stringer. “Spike Sorting with Kilosort4.” Nature Methods 21, no. 5 (May 2024): 914–21. https://doi.org/10.1038/s41592-024-02232-7.
DREDge
Robust online multiband drift estimation in electrophysiology dataWindolf, Charlie, Han Yu, Angelique C. Paulk, Domokos Meszéna, William Muñoz, Julien Boussard, Richard Hardstone, et al. “DREDge: Robust Motion Correction for High-Density Extracellular Recordings across Species.” Nature Methods, March 6, 2025. https://doi.org/10.1038/s41592-025-02614-5.
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pykilomatch-0.0.5.tar.gz.
File metadata
- Download URL: pykilomatch-0.0.5.tar.gz
- Upload date:
- Size: 31.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
803bf10960189f7b570246799f0e887b61dbc928e105c53177cb40ec042b751b
|
|
| MD5 |
e50ad0da49ea68b948a01f90c13fe741
|
|
| BLAKE2b-256 |
36108ab33802396caa7dee8be8c4de387414980cbfbb32e93c945227f9d1e25d
|
Provenance
The following attestation bundles were made for pykilomatch-0.0.5.tar.gz:
Publisher:
python-publish.yml on jiumao2/pyKilomatch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pykilomatch-0.0.5.tar.gz -
Subject digest:
803bf10960189f7b570246799f0e887b61dbc928e105c53177cb40ec042b751b - Sigstore transparency entry: 204179425
- Sigstore integration time:
-
Permalink:
jiumao2/pyKilomatch@20951e427076f5c22c732c4be4363e908891b46d -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/jiumao2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@20951e427076f5c22c732c4be4363e908891b46d -
Trigger Event:
release
-
Statement type:
File details
Details for the file pykilomatch-0.0.5-py3-none-any.whl.
File metadata
- Download URL: pykilomatch-0.0.5-py3-none-any.whl
- Upload date:
- Size: 32.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f26bfc9db5b1834cfdd7431326b1f0443c78e3479c91a9307f83cf87f28b4efa
|
|
| MD5 |
3e6bab2addf15e0676ef66553496f472
|
|
| BLAKE2b-256 |
00b81305debd39e71ab320904ef261634db92d303bda82bb26c375bbac22f2cd
|
Provenance
The following attestation bundles were made for pykilomatch-0.0.5-py3-none-any.whl:
Publisher:
python-publish.yml on jiumao2/pyKilomatch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pykilomatch-0.0.5-py3-none-any.whl -
Subject digest:
f26bfc9db5b1834cfdd7431326b1f0443c78e3479c91a9307f83cf87f28b4efa - Sigstore transparency entry: 204179428
- Sigstore integration time:
-
Permalink:
jiumao2/pyKilomatch@20951e427076f5c22c732c4be4363e908891b46d -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/jiumao2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@20951e427076f5c22c732c4be4363e908891b46d -
Trigger Event:
release
-
Statement type: