Skip to content

Commit bf869d1

Browse files
authored
Merge pull request #1059 from int-brain-lab/np24
move the probe registration to a public scope for iblrig use
2 parents 227c20d + cebe592 commit bf869d1

File tree

6 files changed

+59
-93
lines changed

6 files changed

+59
-93
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9+
## [3.4.2] UNRELEASED
10+
11+
### Fixed
12+
- public method to create insertions in `ibllib.ephys.spikes`
13+
-
14+
### Added
15+
- CI now uses ruff instead of flake8 to enforce linting
916

1017
## [3.4.1] 2025-07-02
1118

@@ -14,7 +21,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1421
- SpikeSortingLoader takes into account revisions
1522
- There is a specific test for `spikeinterface` CI in our integration tests
1623

17-
1824
## Release Note 3.4.0
1925

2026
### features

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ See https://docs.internationalbrainlab.org/09_contribution.html
2727
We use Semantic Versioning.
2828

2929
Before committing to your branch:
30-
- check formating `flake8`
30+
- check formating `ruff check`
3131
- run tests `python -m unittest discover`
3232

3333
Pull request to `develop` or `main`.

gitflow_checklist.md

Lines changed: 0 additions & 68 deletions
This file was deleted.

ibllib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import warnings
44
import os
55

6-
__version__ = '3.4.1'
6+
__version__ = '3.4.2'
77
warnings.filterwarnings('always', category=DeprecationWarning, module='ibllib')
88

99
# if this becomes a full-blown library we should let the logging configuration to the discretion of the dev

ibllib/ephys/spikes.py

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import json
44
import shutil
55
import tarfile
6+
from typing import Tuple
67

78
import numpy as np
89
from one.alf.path import get_session_path
910
import spikeglx
11+
from one.api import ONE
1012

1113
from iblutil.util import Bunch
1214
import phylib.io.alf
@@ -17,6 +19,51 @@
1719
_logger = logging.getLogger(__name__)
1820

1921

22+
def create_insertion(one: ONE, md: dict, label: str, eid: str) -> Tuple[dict, dict]:
23+
"""
24+
Create or update a probe insertion in Alyx and return description and the alyx rest record.
25+
26+
This function checks if a probe insertion with the given label already exists for the
27+
specified session. If it doesn't exist, it creates a new one. If it does, it updates
28+
the existing record. It also prepares a dictionary with essential probe details.
29+
30+
Parameters
31+
----------
32+
one : one.api.ONE
33+
An instance of the ONE API to interact with Alyx.
34+
md : dict
35+
A Bunch object containing metadata from a spikeglx meta file, including
36+
'neuropixelVersion', 'serial', and 'fileName'.
37+
label : str
38+
The label for the probe insertion (e.g., 'probe00').
39+
eid : str
40+
The unique experiment ID (UUID) for the session.
41+
42+
Returns
43+
-------
44+
tuple
45+
A tuple containing:
46+
- description (dict): A dictionary with probe details for metadata file,
47+
containing keys 'label', 'model', 'serial', 'raw_file_name'.
48+
- insertion (dict): The Alyx record for the created or updated probe insertion.
49+
"""
50+
# create json description
51+
description = {'label': label, 'model': md['neuropixelVersion'], 'serial': int(md['serial']),
52+
'raw_file_name': md['fileName']}
53+
54+
# create or update probe insertion on alyx
55+
alyx_insertion = {'session': eid, 'model': md['neuropixelVersion'], 'serial': md['serial'], 'name': label}
56+
pi = one.alyx.rest('insertions', 'list', session=eid, name=label)
57+
if len(pi) == 0:
58+
qc_dict = {'qc': 'NOT_SET', 'extended_qc': {}}
59+
alyx_insertion.update({'json': qc_dict})
60+
insertion = one.alyx.rest('insertions', 'create', data=alyx_insertion)
61+
else:
62+
insertion = one.alyx.rest('insertions', 'partial_update', data=alyx_insertion, id=pi[0]['id'])
63+
64+
return description, insertion
65+
66+
2067
def probes_description(ses_path, one):
2168
"""
2269
Aggregate probes information into ALF files
@@ -36,24 +83,6 @@ def probes_description(ses_path, one):
3683
return
3784

3885
subdirs, labels, efiles_sorted = zip(*sorted(ap_meta_files))
39-
40-
def _create_insertion(md, label, eid):
41-
42-
# create json description
43-
description = {'label': label, 'model': md.neuropixelVersion, 'serial': int(md.serial), 'raw_file_name': md.fileName}
44-
45-
# create or update probe insertion on alyx
46-
alyx_insertion = {'session': eid, 'model': md.neuropixelVersion, 'serial': md.serial, 'name': label}
47-
pi = one.alyx.rest('insertions', 'list', session=eid, name=label)
48-
if len(pi) == 0:
49-
qc_dict = {'qc': 'NOT_SET', 'extended_qc': {}}
50-
alyx_insertion.update({'json': qc_dict})
51-
insertion = one.alyx.rest('insertions', 'create', data=alyx_insertion)
52-
else:
53-
insertion = one.alyx.rest('insertions', 'partial_update', data=alyx_insertion, id=pi[0]['id'])
54-
55-
return description, insertion
56-
5786
# Ouputs the probes description file
5887
probe_description = []
5988
alyx_insertions = []
@@ -66,16 +95,16 @@ def _create_insertion(md, label, eid):
6695
nshanks = np.unique(geometry['shank'])
6796
for shank in nshanks:
6897
label_ext = f'{label}{chr(97 + int(shank))}'
69-
description, insertion = _create_insertion(md, label_ext, eid)
98+
description, insertion = create_insertion(one, md, label_ext, eid)
7099
probe_description.append(description)
71100
alyx_insertions.append(insertion)
72101
# NP2.4 meta that has already been split
73102
else:
74-
description, insertion = _create_insertion(md, label, eid)
103+
description, insertion = create_insertion(one, md, label, eid)
75104
probe_description.append(description)
76105
alyx_insertions.append(insertion)
77106
else:
78-
description, insertion = _create_insertion(md, label, eid)
107+
description, insertion = create_insertion(one, md, label, eid)
79108
probe_description.append(description)
80109
alyx_insertions.append(insertion)
81110

ibllib/pipes/local_server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import subprocess
1212
import sys
1313
import traceback
14-
import importlib
1514
import importlib.metadata
1615

1716
from one.api import ONE

0 commit comments

Comments
 (0)