Skip to content

Commit d5f6317

Browse files
committed
Merge branch 'main' into support_python_3.13
2 parents c935f6b + cabe66e commit d5f6317

132 files changed

Lines changed: 5281 additions & 1035 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.
Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
11
name: Install packages
22
description: This action installs the package and its dependencies for testing
33

4-
inputs:
5-
python-version:
6-
description: 'Python version to set up'
7-
required: false
8-
os:
9-
description: 'Operating system to set up'
10-
required: false
11-
124
runs:
135
using: "composite"
146
steps:
157
- name: Install dependencies
168
run: |
17-
sudo apt install git
189
git config --global user.email "CI@example.com"
1910
git config --global user.name "CI Almighty"
20-
python -m venv ${{ github.workspace }}/test_env # Environment used in the caching step
21-
python -m pip install -U pip # Official recommended way
22-
source ${{ github.workspace }}/test_env/bin/activate
2311
pip install tabulate # This produces summaries at the end
2412
pip install -e .[test,extractors,streaming_extractors,test_extractors,full]
2513
shell: bash
26-
- name: Force installation of latest dev from key-packages when running dev (not release)
27-
run: |
28-
source ${{ github.workspace }}/test_env/bin/activate
29-
spikeinterface_is_dev_version=$(python -c "import spikeinterface; print(spikeinterface.DEV_MODE)")
30-
if [ $spikeinterface_is_dev_version = "True" ]; then
31-
echo "Running spikeinterface dev version"
32-
pip install --no-cache-dir git+https://github.com/NeuralEnsemble/python-neo
33-
pip install --no-cache-dir git+https://github.com/SpikeInterface/probeinterface
34-
fi
35-
echo "Running tests for release, using pyproject.toml versions of neo and probeinterface"
14+
- name: Install git-annex
3615
shell: bash
37-
- name: git-annex install
3816
run: |
17+
pip install datalad-installer
3918
wget https://downloads.kitenet.net/git-annex/linux/current/git-annex-standalone-amd64.tar.gz
4019
mkdir /home/runner/work/installation
4120
mv git-annex-standalone-amd64.tar.gz /home/runner/work/installation/
@@ -44,4 +23,14 @@ runs:
4423
tar xvzf git-annex-standalone-amd64.tar.gz
4524
echo "$(pwd)/git-annex.linux" >> $GITHUB_PATH
4625
cd $workdir
26+
git config --global filter.annex.process "git-annex filter-process" # recommended for efficiency
27+
- name: Force installation of latest dev from key-packages when running dev (not release)
28+
run: |
29+
spikeinterface_is_dev_version=$(python -c "import spikeinterface; print(spikeinterface.DEV_MODE)")
30+
if [ $spikeinterface_is_dev_version = "True" ]; then
31+
echo "Running spikeinterface dev version"
32+
pip install --no-cache-dir git+https://github.com/NeuralEnsemble/python-neo
33+
pip install --no-cache-dir git+https://github.com/SpikeInterface/probeinterface
34+
fi
35+
echo "Running tests for release, using pyproject.toml versions of neo and probeinterface"
4736
shell: bash

.github/workflows/all-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
echo "$file was changed"
4848
done
4949
50-
- name: Set testing environment # This decides which tests are run and whether to install especial dependencies
50+
- name: Set testing environment # This decides which tests are run and whether to install special dependencies
5151
shell: bash
5252
run: |
5353
changed_files="${{ steps.changed-files.outputs.all_changed_files }}"

.github/workflows/full-test-with-codecov.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
env:
4646
HDF5_PLUGIN_PATH: ${{ github.workspace }}/hdf5_plugin_path_maxwell
4747
run: |
48-
source ${{ github.workspace }}/test_env/bin/activate
4948
pytest -m "not sorters_external" --cov=./ --cov-report xml:./coverage.xml -vv -ra --durations=0 | tee report_full.txt; test ${PIPESTATUS[0]} -eq 0 || exit 1
5049
echo "# Timing profile of full tests" >> $GITHUB_STEP_SUMMARY
5150
python ./.github/scripts/build_job_summary.py report_full.txt >> $GITHUB_STEP_SUMMARY

doc/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ spikeinterface.curation
346346
.. autofunction:: remove_redundant_units
347347
.. autofunction:: remove_duplicated_spikes
348348
.. autofunction:: remove_excess_spikes
349+
.. autofunction:: load_model
350+
.. autofunction:: auto_label_units
351+
.. autofunction:: train_model
349352

350353
Deprecated
351354
~~~~~~~~~~

doc/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,15 @@
119119

120120
# for sphinx gallery plugin
121121
sphinx_gallery_conf = {
122-
'only_warn_on_example_error': True,
122+
# This is the default but including here explicitly. Should build all docs and fail on gallery failures only.
123+
# other option would be abort_on_example_error, but this fails on first failure. So we decided against this.
124+
'only_warn_on_example_error': False,
123125
'examples_dirs': ['../examples/tutorials'],
124126
'gallery_dirs': ['tutorials' ], # path where to save gallery generated examples
125127
'subsection_order': ExplicitOrder([
126128
'../examples/tutorials/core',
127129
'../examples/tutorials/extractors',
130+
'../examples/tutorials/curation',
128131
'../examples/tutorials/qualitymetrics',
129132
'../examples/tutorials/comparison',
130133
'../examples/tutorials/widgets',

doc/development/development.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,25 @@ We use Sphinx to build the documentation. To build the documentation locally, yo
213213
214214
This will build the documentation in the :code:`doc/_build/html` folder. You can open the :code:`index.html` file in your browser to see the documentation.
215215

216+
Adding new documentation
217+
------------------------
218+
219+
Documentation can be added as a
220+
`sphinx-gallery <https://sphinx-gallery.github.io/stable/index.html>`_
221+
python file ('tutorials')
222+
or a
223+
`sphinx rst <https://sphinx-tutorial.readthedocs.io/step-1/>`_
224+
file (all other sections).
225+
226+
To add a new tutorial, add your ``.py`` file to ``spikeinterface/examples``.
227+
Then, update the ``spikeinterface/doc/tutorials_custom_index.rst`` file
228+
to make a new card linking to the page and an optional image. See
229+
``tutorials_custom_index.rst`` header for more information.
230+
231+
For other sections, write your documentation in ``.rst`` format and add
232+
the page to the appropriate ``index.rst`` file found in the relevant
233+
folder (e.g. ``how_to/index.rst``).
234+
216235
How to run code coverage locally
217236
--------------------------------
218237
To run code coverage locally, you can use the following command:

doc/get_started/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ compute quality metrics (some quality metrics require certain extensions
673673
'min_spikes': 0,
674674
'window_size_s': 1},
675675
'snr': {'peak_mode': 'extremum', 'peak_sign': 'neg'},
676-
'synchrony': {'synchrony_sizes': (2, 4, 8)}}
676+
'synchrony': {}
677677
678678
679679
Since the recording is very short, let’s change some parameters to
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
How to use a trained model to predict the curation labels
2+
=========================================================
3+
4+
For a more detailed guide to using trained models, `read our tutorial here
5+
<https://spikeinterface.readthedocs.io/en/latest/tutorials/curation/plot_1_automated_curation.html>`_).
6+
7+
There is a Collection of models for automated curation available on the
8+
`SpikeInterface HuggingFace page <https://huggingface.co/SpikeInterface>`_.
9+
10+
We'll apply the model ``toy_tetrode_model`` from ``SpikeInterface`` on a SortingAnalyzer
11+
called ``sorting_analyzer``. We assume that the quality and template metrics have
12+
already been computed.
13+
14+
We need to pass the ``sorting_analyzer``, the ``repo_id`` (which is just the part of the
15+
repo's URL after huggingface.co/) and that we trust the model.
16+
17+
.. code::
18+
19+
from spikeinterface.curation import auto_label_units
20+
21+
labels_and_probabilities = auto_label_units(
22+
sorting_analyzer = sorting_analyzer,
23+
repo_id = "SpikeInterface/toy_tetrode_model",
24+
trust_model = True
25+
)
26+
27+
If you have a local directory containing the model in a ``skops`` file you can use this to
28+
create the labels:
29+
30+
.. code::
31+
32+
labels_and_probabilities = si.auto_label_units(
33+
sorting_analyzer = sorting_analyzer,
34+
model_folder = "my_folder_with_a_model_in_it",
35+
)
36+
37+
The returned labels are a dictionary of model's predictions and it's confidence. These
38+
are also saved as a property of your ``sorting_analyzer`` and can be accessed like so:
39+
40+
.. code::
41+
42+
labels = sorting_analyzer.sorting.get_property("classifier_label")
43+
probabilities = sorting_analyzer.sorting.get_property("classifier_probability")
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
How to train a model to predict curation labels
2+
===============================================
3+
4+
A full tutorial for model-based curation can be found `here <https://spikeinterface.readthedocs.io/en/latest/tutorials/curation/plot_2_train_a_model.html>`_.
5+
6+
Here, we assume that you have:
7+
8+
* Two SortingAnalyzers called ``analyzer_1`` and
9+
``analyzer_2``, and have calculated some template and quality metrics for both
10+
* Manually curated labels for the units in each analyzer, in lists called
11+
``analyzer_1_labels`` and ``analyzer_2_labels``. If you have used phy, the lists can
12+
be accessed using ``curated_labels = analyzer.sorting.get_property("quality")``.
13+
14+
With these objects calculated, you can train a model as follows
15+
16+
.. code::
17+
18+
from spikeinterface.curation import train_model
19+
20+
analyzer_list = [analyzer_1, analyzer_2]
21+
labels_list = [analyzer_1_labels, analyzer_2_labels]
22+
output_folder = "/path/to/output_folder"
23+
24+
trainer = train_model(
25+
mode="analyzers",
26+
labels=labels_list,
27+
analyzers=analyzer_list,
28+
output_folder=output_folder,
29+
metric_names=None, # Set if you want to use a subset of metrics, defaults to all calculated quality and template metrics
30+
imputation_strategies=None, # Default is all available imputation strategies
31+
scaling_techniques=None, # Default is all available scaling techniques
32+
classifiers=None, # Defaults to Random Forest classifier only - we usually find this gives the best results, but a range of classifiers is available
33+
seed=None, # Set a seed for reproducibility
34+
)
35+
36+
37+
The trainer tries several models and chooses the most accurate one. This model and
38+
some metadata are stored in the ``output_folder``, which can later be loaded using the
39+
``load_model`` function (`more details <https://spikeinterface.readthedocs.io/en/latest/tutorials/curation/plot_1_automated_curation.html#download-a-pretrained-model>`_).
40+
We can also access the model, which is an sklearn ``Pipeline``, from the trainer object
41+
42+
.. code::
43+
44+
best_model = trainer.best_pipeline
45+
46+
47+
The training function can also be run in “csv” mode, if you prefer to
48+
store metrics in as .csv files. If the target labels are stored as a column in
49+
the file, you can point to these with the ``target_label`` parameter
50+
51+
.. code::
52+
53+
trainer = train_model(
54+
mode="csv",
55+
metrics_paths = ["/path/to/csv_file_1", "/path/to/csv_file_2"],
56+
target_label = "my_label",
57+
output_folder=output_folder,
58+
)

doc/how_to/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ Guides on how to solve specific, short problems in SpikeInterface. Learn how to.
1515
load_your_data_into_sorting
1616
benchmark_with_hybrid_recordings
1717
drift_with_lfp
18+
auto_curation_training
19+
auto_curation_prediction

0 commit comments

Comments
 (0)