Skip to content

Commit 0840fc6

Browse files
authored
Merge branch 'main' into add-tetrodes-doc
2 parents 5534a7e + 705d194 commit 0840fc6

78 files changed

Lines changed: 2233 additions & 819 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,16 @@ spikeinterface.preprocessing
176176
.. autofunction:: clip
177177
.. autofunction:: common_reference
178178
.. autofunction:: correct_lsb
179+
.. autofunction:: compute_motion
179180
.. autofunction:: correct_motion
180181
.. autofunction:: get_motion_presets
181182
.. autofunction:: get_motion_parameters_preset
182183
.. autofunction:: load_motion_info
183184
.. autofunction:: save_motion_info
184185
.. autofunction:: depth_order
185186
.. autofunction:: detect_bad_channels
187+
.. autofunction:: detect_and_interpolate_bad_channels
188+
.. autofunction:: detect_and_remove_bad_channels
186189
.. autofunction:: directional_derivative
187190
.. autofunction:: filter
188191
.. autofunction:: gaussian_filter

doc/how_to/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ Guides on how to solve specific, short problems in SpikeInterface. Learn how to.
1818
auto_curation_training
1919
auto_curation_prediction
2020
physical_units
21+
unsigned_to_signed
2122
customize_a_plot
2223
../tutorials/forhowto/plot_1_working_with_tetrodes

doc/how_to/physical_units.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _physical_units:
2+
13
Working with physical units in SpikeInterface recordings
24
========================================================
35

doc/how_to/unsigned_to_signed.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
Unsigned to Signed Data types
2+
=============================
3+
4+
As of version 0.103.0 SpikeInterface has changed one of its defaults for interacting with
5+
:code:`Recording` objects. We no longer autocast unsigned dtypes to signed implicitly. This
6+
means that some users of SpikeInterface will need to add one additional line of code to their scripts
7+
to explicitly handle this conversion.
8+
9+
10+
Why this matters?
11+
-----------------
12+
13+
For those that want a deeper understanding of dtypes `NumPy provides a great explanation <https://numpy.org/doc/stable/reference/arrays.dtypes.html>`_.
14+
For our purposes it is important to know that many pieces of recording equipment opt to store their electrophysiological data as unsigned integers
15+
(e.g., Intan, Maxwell Biosystems, 3Brain Biocam).
16+
Similarly to signed integers, in order to convert to real units these file formats only need to store a :code:`gain`
17+
and an :code:`offset`. Our :code:`RecordingExtractor`'s maintain the dtype that the file format utilizes, which means that some of our
18+
:code:`RecordingExtractor`'s will have unsigned dtypes.
19+
20+
The problem with using unsigned dtypes is that many types of functions (including the ones we use from :code:`SciPy`) perform poorly with unsigned integers.
21+
This is made worse by the fact that these failures are silent (i.e. no error is triggered but the operation leads to nonsensical data). So the
22+
solution required is to convernt unsigned integers into signed integers. Previously we did this under the hood, automatically for users that had
23+
a :code:`Recording` object with an unsigned dtype.
24+
25+
We decided, however, that implicitly performing this action was not the best course of action, since:
26+
27+
1) *explicit* is always better than *implicit*
28+
2) some functions would *magically* change the dtype of the :code:`Recording` object, which can cause confusion
29+
30+
So from version 0.103.0, users will now explicitly have to perform this transformation of their data. This will help users better understand how they are
31+
processing their data during an analysis pipeline as well as better understand the provenance of their pipeline.
32+
33+
34+
Using :code:`unsigned_to_signed`
35+
--------------------------------
36+
37+
For users that receive an error because their :code:`Recording` is unsigned, their is one additional step that must be done:
38+
39+
.. code:: python
40+
41+
import spikeinterface.extractors as se
42+
import spikeinterface.preprocessing as spre
43+
44+
# Intan is an example of unsigned data
45+
recording = se.read_intan('path/to/my/file.rhd', stream_id='0')
46+
# to get a signed version of our Recording we use the following function
47+
recording_signed = spre.unsigned_to_signed(recording)
48+
# we can now apply any preprocessing functions like normal, e.g.
49+
recording_filtered = spre.bandpass_filter(recording_signed)
50+
51+
52+
Now with the signed dtype of the :code:`Recording` one can use a SpikeInterface pipeline as usual.
53+
54+
55+
If you are curious if your :code:`Recording` is unsigned you can simply check the repr or use :code:`get_dtype()`
56+
57+
.. code:: python
58+
59+
# the repr automatically displays the dtype
60+
print(recording)
61+
# use method on the Recording object
62+
print(recording.get_dtype())
63+
64+
In either case, if the dtype displayed has a :code:`u` at the beginning (e.g. :code:`uint16`) then your recording is
65+
unsigned. If it doesn't have the :code:`u` (e.g. :code:`int16`) then it is signed and would not need this preprocessing step.
66+
67+
68+
Bit depth
69+
---------
70+
71+
One final important piece of information for some users is the concept of bit depth, which is the number of bits used to
72+
sample the data. The :code:`bit_depth` argument that can be fed into the :code:`unsigned_to_signed` function.
73+
This should be used in cases where the ADC bit depth does not match the bit depth of the data type (e.g., if the data is
74+
stored as :code:`uint16` but the ADC is 12 bits).
75+
Let's make a concrete example: the Biocam acquisition system from 3Brain uses a 12-bit ADC and stores the data as
76+
:code:`uint16`. This means that the data is stored in a 16-bit unsigned integer format, but the actual data
77+
only covers a 12-bit range. Therefore, that the "zero" of the data is not at 0, nor at half of the :code:`uint16` range (i.e. 2^15),
78+
but rather at 2048 (i.e., 2^12).
79+
In this case, setting the :code:`bit_depth` argument to 12 will allow the :code:`unsigned_to_signed` function to
80+
correctly convert the unsigned data to signed data and offset the data to be centered around 0, by subtracting 2048
81+
while converting the data from unsigned to signed.
82+
83+
.. code:: python
84+
85+
recording_unsigned = se.read_biocam('path/to/my/file.brw')
86+
# we can now convert to signed with the correct bit depth
87+
recording_signed = spre.unsigned_to_signed(recording_unsigned, bit_depth=12)
88+
89+
90+
Additional Notes
91+
----------------
92+
93+
1) Some sorters make use of SpikeInterface preprocessing either
94+
within their wrappers or within their own code base. So remember to use the "signed" version of
95+
your recording for the rest of your pipeline.
96+
97+
2) Using :code:`unsigned_to_signed` in versions less than 0.103.0 does not hurt your scripts. This
98+
option was available previously along with the implicit option. Adding this into scripts with old
99+
versions of SpikeInterface will still work and will "future-proof" your scripts for when you
100+
update to a version greater than or equal to 0.103.0.
101+
102+
3) For additional information on units and scaling in SpikeInterface see :ref:`physical_units`.

doc/modules/sorters.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ Here is the list of external sorters accessible using the run_sorter wrapper:
469469
* **Klusta** :code:`run_sorter(sorter_name='klusta')`
470470
* **Mountainsort4** :code:`run_sorter(sorter_name='mountainsort4')`
471471
* **Mountainsort5** :code:`run_sorter(sorter_name='mountainsort5')`
472+
* **RT-Sort** :code:`run_sorter(sorter_name='rt-sort')`
472473
* **SpyKING Circus** :code:`run_sorter(sorter_name='spykingcircus')`
473474
* **Tridesclous** :code:`run_sorter(sorter_name='tridesclous')`
474475
* **Wave clus** :code:`run_sorter(sorter_name='waveclus')`

doc/references.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ please include the appropriate citation for the :code:`sorter_name` parameter yo
4343
- :code:`herdingspikes` [Muthmann]_ [Hilgen]_
4444
- :code:`kilosort` [Pachitariu]_
4545
- :code:`mountainsort` [Chung]_
46+
- :code:`rt-sort` [van_der_Molen]_
4647
- :code:`spykingcircus` [Yger]_
4748
- :code:`wavclus` [Chaure]_
4849
- :code:`yass` [Lee]_
@@ -154,6 +155,8 @@ References
154155
155156
.. [UMS] `UltraMegaSort2000 - Spike sorting and quality metrics for extracellular spike data. 2011. <https://github.com/danamics/UMS2K>`_
156157
158+
.. [van_der_Molen] `RT-Sort: An action potential propagation-based algorithm for real time spike detection and sorting with millisecond latencies. 2024. <https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0312438>`_
159+
157160
.. [Varol] `Decentralized Motion Inference and Registration of Neuropixel Data. 2021. <https://ieeexplore.ieee.org/document/9414145>`_
158161
159162
.. [Watters] `MEDiCINe: Motion Correction for Neural Electrophysiology Recordings. 2025. <https://www.eneuro.org/content/12/3/ENEURO.0529-24.2025>`_

installation_tips/README.md

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,105 @@
11
## Installation tips
22

3-
If you are not (yet) an expert in Python installations (conda vs pip, mananging environements, etc.),
4-
here we propose a simple recipe to install `spikeinterface` and several sorters inside an anaconda
5-
environment for windows/mac users.
6-
7-
This environment will install:
8-
* spikeinterface full option
3+
If you are not (yet) an expert in Python installations, the first major hurdle is choosing the installation procedure.
4+
5+
Some key concepts you need to know before starting:
6+
* Python itself can be distributed and installed many, many ways.
7+
* Python itself does not contain many features for scientific computing, so you need to install "packages". For example
8+
numpy, scipy, matplotlib, spikeinterface, ... These are all examples of Python packages that aid in scientific computation.
9+
* All of these packages have their own dependencies which requires figuring out which versions of the dependencies work for
10+
the combination of packages you as the user want to use.
11+
* Packages can be distributed and installed in several ways (pip, conda, uv, mamba, ...) and luckily these methods of installation
12+
typically take care of solving the dependencies for you!
13+
* Installing many packages at once is challenging (because of their dependency graphs) so you need to do it in an "isolated environment" to not destroy any previous installation. You need to see an "environment" as a sub-installation in a dedicated folder.
14+
15+
Choosing the installer + an environment manager + a package installer is a nightmare for beginners.
16+
17+
The main options are:
18+
* use "uv", a new, fast and simple package manager. We recommend this for beginners on every operating system.
19+
* use "anaconda" (or its flavors-mamba, miniconda), which does everything. Used to be very popular but theses days it is becoming
20+
harder to use because it is slow by default and has relatively strict licensing on the default channel (not always free anymore).
21+
You need to play with "community channels" to make it free again, which is complicated for beginners.
22+
This way is better for users in organizations that have specific licensing agrees with anaconda already in place.
23+
* use Python from the system or Python.org + venv + pip: good and simple idea for Linux users, but does require familiarity with
24+
the Python ecosystem (so good for intermediate users).
25+
26+
Here we propose a step by step recipe for beginners based on [**"uv"**](https://github.com/astral-sh/uv).
27+
We used to recommend installing with anaconda. It will be kept here for a while but we do not recommend it anymore.
28+
29+
30+
This recipe will install:
31+
* spikeinterface `full` option
932
* spikeinterface-gui
10-
* phy
11-
* tridesclous
33+
* kilosort4
1234

13-
Kilosort, Ironclust and HDSort are MATLAB based and need to be installed from source.
35+
into our uv venv environment.
1436

15-
### Quick installation
1637

17-
Steps:
38+
### Quick installation using "uv" (recommended)
1839

19-
1. Download anaconda individual edition [here](https://www.anaconda.com/download)
20-
2. Run the installer. Check the box “Add anaconda3 to my Path environment variable”. It makes life easier for beginners.
21-
3. Download with right click + save the file corresponding to your OS, and put it in "Documents" folder
22-
* [`full_spikeinterface_environment_windows.yml`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/full_spikeinterface_environment_windows.yml)
23-
* [`full_spikeinterface_environment_mac.yml`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/full_spikeinterface_environment_mac.yml)
24-
4. Then open the "Anaconda Command Prompt" (if Windows, search in your applications) or the Terminal (for Mac users)
25-
5. If not in the "Documents" folder type `cd Documents`
26-
6. Then run this depending on your OS:
27-
* `conda env create --file full_spikeinterface_environment_windows.yml`
28-
* `conda env create --file full_spikeinterface_environment_mac.yml`
40+
1. On macOS and Linux. Open a terminal and do
41+
`curl -LsSf https://astral.sh/uv/install.sh | sh`
42+
2. On Windows. Open an instance of the Powershell (Windows has many options this is the recommended one from uv)
43+
`powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"`
44+
3. Exit the session and log in again.
45+
4. Download with right click and save this file in your "Documents" folder:
46+
* [`beginner_requirements_stable.txt`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/beginner_requirements_stable.txt) for stable release
47+
5. Open terminal or powershell and run:
48+
6. `uv venv si_env --python 3.12`
49+
7. Activate your virtual environment by running:
50+
- For Mac/Linux: `source si_env/bin/activate` (you should see `(si_env)` in your terminal)
51+
- For Windows: `si_env\Scripts\activate`
52+
8. Run `uv pip install -r Documents/beginner_requirements_stable.txt`
2953

3054

31-
Done! Before running a spikeinterface script you will need to "select" this "environment" with `conda activate si_env`.
55+
## Installing before release (from source)
3256

33-
Note for **linux** users : this conda recipe should work but we recommend strongly to use **pip + virtualenv**.
57+
Some tools in the spikeinteface ecosystem are getting regular bug fixes (spikeinterface, spikeinterface-gui, probeinterface, neo).
58+
We are making releases 2 to 4 times a year. In between releases if you want to install from source you can use the `beginner_requirements_rolling.txt` file to create the environment instead of the `beginner_requirements_stable.txt` file. This will install the packages of the ecosystem from source.
59+
This is a good way to test if a patch fixes your issue.
3460

3561

3662
### Check the installation
3763

38-
3964
If you want to test the spikeinterface install you can:
4065

4166
1. Download with right click + save the file [`check_your_install.py`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/check_your_install.py)
4267
and put it into the "Documents" folder
43-
44-
2. Open the Anaconda Command Prompt (Windows) or Terminal (Mac)
45-
3. If not in your "Documents" folder type `cd Documents`
46-
4. Run this:
47-
```
48-
conda activate si_env
49-
python check_your_install.py
50-
```
51-
5. If a windows user to clean-up you will also need to right click + save [`cleanup_for_windows.py`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/cleanup_for_windows.py)
52-
Then transfer `cleanup_for_windows.py` into your "Documents" folder. Finally run :
68+
2. Open the CMD Prompt (Windows)[^1] or Terminal (Mac/Linux)
69+
3. Activate your si_env : `source si_env/bin/activate` (Max/Linux), `si_env\Scripts\activate` (Windows)
70+
4. Go to your "Documents" folder with `cd Documents` or the place where you downloaded the `check_your_install.py`
71+
5. Run `python check_your_install.py`
72+
6. If you are a Windows user, you should also right click + save [`cleanup_for_windows.py`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/cleanup_for_windows.py). Then transfer `cleanup_for_windows.py` into your "Documents" folder and finally run:
5373
```
5474
python cleanup_for_windows.py
5575
```
5676

57-
This script tests the following:
77+
This script tests the following steps:
5878
* importing spikeinterface
59-
* running tridesclous
60-
* running spyking-circus (not on mac)
61-
* running herdingspikes (not on windows)
79+
* running tridesclous2
80+
* running kilosort4
6281
* opening the spikeinterface-gui
63-
* exporting to Phy
6482

6583

66-
## Installing before release
84+
### Legacy installation using Anaconda (not recommended anymore)
85+
86+
Steps:
87+
88+
1. Download Anaconda individual edition [here](https://www.anaconda.com/download)
89+
2. Run the installer. Check the box “Add anaconda3 to my Path environment variable”. It makes life easier for beginners.
90+
3. Download with right click + save the environment YAML file ([`beginner_conda_env_stable.yml`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/beginner_conda_env_stable.yml)) and put it in "Documents" folder
91+
4. Then open the "Anaconda Command Prompt" (if Windows, search in your applications) or the Terminal (for Mac users)
92+
5. If not in the "Documents" folder type `cd Documents`
93+
6. Run this command to create the environment:
94+
```bash
95+
conda env create --file beginner_conda_env_stable.yml
96+
```
97+
98+
Done! Before running a spikeinterface script you will need to "select" this "environment" with `conda activate si_env`.
99+
100+
Note for **Linux** users: this conda recipe should work but we recommend strongly to use **pip + virtualenv**.
101+
102+
67103

68-
Some tools in the spikeinteface ecosystem are getting regular bug fixes (spikeinterface, spikeinterface-gui, probeinterface, python-neo, sortingview).
69-
We are making releases 2 to 4 times a year. In between releases if you want to install from source you can use the `full_spikeinterface_environment_rolling_updates.yml` file to create the environment. This will install the packages of the ecosystem from source.
70-
This is a good way to test if patch fix your issue.
104+
[^1]: Although uv installation instructions are for the Powershell, our sorter scripts are for the CMD Prompt. After the initial installation with Powershell, any session that will have sorting requires the CMD Prompt. If you do not
105+
plan to spike sort in a session either shell could be used.

installation_tips/full_spikeinterface_environment_linux_dandi.yml renamed to installation_tips/beginner_conda_env_stable.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
- defaults
55
dependencies:
6-
- python=3.11
6+
- python=3.12
77
- pip
88
- numpy
99
- scipy
@@ -13,7 +13,7 @@ dependencies:
1313
- h5py
1414
- pandas
1515
- xarray
16-
- zarr
16+
- zarr<3
1717
- scikit-learn
1818
- hdbscan
1919
- networkx
@@ -30,8 +30,6 @@ dependencies:
3030
- libxcb
3131
- pip:
3232
- ephyviewer
33-
- MEArec
3433
- spikeinterface[full,widgets]
3534
- spikeinterface-gui
36-
- tridesclous
37-
# - phy==2.0b5
35+
- kilosort>4.0.30
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
https://github.com/NeuralEnsemble/python-neo/archive/master.zip
2+
https://github.com/SpikeInterface/probeinterface/archive/main.zip
3+
https://github.com/SpikeInterface/spikeinterface/archive/main.zip[full,widgets]
4+
https://github.com/SpikeInterface/spikeinterface-gui/archive/main.zip
5+
jupyterlab
6+
PySide6<6.8
7+
hdbscan
8+
pyqtgraph
9+
ephyviewer
10+
kilosort>4.0.30
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spikeinterface[full,widgets]
2+
jupyterlab
3+
PySide6<6.8
4+
hdbscan
5+
pyqtgraph
6+
ephyviewer
7+
spikeinterface-gui
8+
kilosort>4.0.30

0 commit comments

Comments
 (0)