Skip to content

Commit 7c14384

Browse files
committed
Merge branch 'release/2.21.0'
2 parents 2f85e3c + 0523718 commit 7c14384

Some content is hidden

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

58 files changed

+2984
-1274
lines changed

brainbox/behavior/training.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from one.api import ONE
2+
from one.alf.exceptions import ALFObjectNotFound
23
import datetime
34
import re
45
import numpy as np
@@ -131,7 +132,10 @@ def get_sessions(subj, date=None, one=None):
131132
sess_dates = []
132133
if len(sessions) < 3:
133134
for n, _ in enumerate(sessions):
134-
trials_ = one.load_object(sessions[n]['url'].split('/')[-1], 'trials')
135+
try:
136+
trials_ = one.load_object(sessions[n]['url'].split('/')[-1], 'trials')
137+
except ALFObjectNotFound:
138+
trials_ = None
135139

136140
if trials_:
137141
task_protocol.append(re.search('tasks_(.*)Choice',
@@ -142,7 +146,11 @@ def get_sessions(subj, date=None, one=None):
142146
else:
143147
n = 0
144148
while len(trials) < 3:
145-
trials_ = one.load_object(sessions[n]['url'].split('/')[-1], 'trials')
149+
print(sessions[n]['url'].split('/')[-1])
150+
try:
151+
trials_ = one.load_object(sessions[n]['url'].split('/')[-1], 'trials')
152+
except ALFObjectNotFound:
153+
trials_ = None
146154

147155
if trials_:
148156
task_protocol.append(re.search('tasks_(.*)Choice',

brainbox/io/one.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,28 @@ def load_wheel_reaction_times(eid, one=None):
706706
return firstMove_times - trials['goCue_times']
707707

708708

709+
def load_iti(trials):
710+
"""
711+
The inter-trial interval (ITI) time for each trial, defined as the period of open-loop grey
712+
screen commencing at stimulus off and lasting until the quiescent period at the start of the
713+
following trial. Note that the ITI for the first trial is the time between the first trial
714+
and the next, therefore the last value is NaN.
715+
716+
Parameters
717+
----------
718+
trials : one.alf.io.AlfBunch
719+
An ALF trials object containing the keys {'intervals', 'stimOff_times'}.
720+
721+
Returns
722+
-------
723+
np.array
724+
An array of inter-trial intervals, the last value being NaN.
725+
"""
726+
if not {'intervals', 'stimOff_times'} <= trials.keys():
727+
raise ValueError('trials must contain keys {"intervals", "stimOff_times"}')
728+
return np.r_[(np.roll(trials['intervals'][:, 0], -1) - trials['stimOff_times'])[:-1], np.nan]
729+
730+
709731
def load_channels_from_insertion(ins, depths=None, one=None, ba=None):
710732

711733
PROV_2_VAL = {

brainbox/io/spikeglx.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def __init__(self, pid, one, typ='ap', cache_folder=None, remove_cached=False):
132132
self.chunks['chunk_bounds'] = np.array(self.chunks['chunk_bounds'])
133133
super(Streamer, self).__init__(meta_file, ignore_warnings=True)
134134

135-
def read(self, nsel=slice(0, 10000), csel=slice(None), sync=True):
135+
def read(self, nsel=slice(0, 10000), csel=slice(None), sync=True, volts=True):
136136
"""
137137
overload the read function by downloading the necessary chunks
138138
"""
@@ -142,7 +142,11 @@ def read(self, nsel=slice(0, 10000), csel=slice(None), sync=True):
142142
_logger.debug(f'Streamer: caching sample {n0}, (t={n0 / self.fs})')
143143
self.cache_folder.mkdir(exist_ok=True, parents=True)
144144
sr = self._download_raw_partial(first_chunk=first_chunk, last_chunk=last_chunk)
145-
data = sr[nsel.start - n0: nsel.stop - n0, csel]
145+
if not volts:
146+
data = np.copy(sr._raw[nsel.start - n0:nsel.stop - n0, csel])
147+
else:
148+
data = sr[nsel.start - n0: nsel.stop - n0, csel]
149+
146150
sr.close()
147151
if self.remove_cached:
148152
shutil.rmtree(self.target_dir)

brainbox/plot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
55
Run the following to set-up the workspace to run the docstring examples:
66
>>> from brainbox import processing
7-
>>> import alf.io as aio
7+
>>> import one.alf.io as alfio
88
>>> import numpy as np
99
>>> import matplotlib.pyplot as plt
1010
>>> import ibllib.ephys.spikes as e_spks
1111
# (*Note, if there is no 'alf' directory, make 'alf' directory from 'ks2' output directory):
1212
>>> e_spks.ks2_to_alf(path_to_ks_out, path_to_alf_out)
1313
# Load the alf spikes bunch and clusters bunch, and get a units bunch.
14-
>>> spks_b = aio.load_object(path_to_alf_out, 'spikes')
15-
>>> clstrs_b = aio.load_object(path_to_alf_out, 'clusters')
14+
>>> spks_b = alfio.load_object(path_to_alf_out, 'spikes')
15+
>>> clstrs_b = alfio.load_object(path_to_alf_out, 'clusters')
1616
>>> units_b = processing.get_units_bunch(spks_b) # may take a few mins to compute
1717
"""
1818

@@ -28,7 +28,7 @@
2828
from brainbox.metrics import single_units
2929
from brainbox.processing import bincount2D
3030
from brainbox.io.spikeglx import extract_waveforms
31-
from ibllib.io import spikeglx
31+
import spikeglx
3232

3333

3434
def feat_vars(units_b, units=None, feat_name='amps', dist='norm', test='ks', cmap_name='coolwarm',

brainbox/tests/test_io.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import shutil
66

77
import numpy as np
8+
import numpy.testing
89

910
from brainbox.io import one as bbone
1011
from one.api import ONE
@@ -66,5 +67,24 @@ def tearDown(self) -> None:
6667
shutil.rmtree(self.tmpdir)
6768

6869

69-
if __name__ == "__main__":
70+
class TestIO_ONE(unittest.TestCase):
71+
"""Tests for brainbox.io.one functions that don't require fixtures on disk."""
72+
def test_load_iti(self):
73+
"""Test for brainbox.io.one.load_iti function."""
74+
trials = bbone.alfio.AlfBunch({})
75+
trials.intervals = np.array([
76+
[114.52487625, 117.88103707],
77+
[118.5169474, 122.89742147],
78+
[123.49302927, 126.12216664],
79+
[126.68107337, 129.53872083],
80+
[130.11952807, 133.90539162]
81+
])
82+
trials.stimOff_times = [117.38098379, 122.39736201, 125.62210278, 129.03865947, 133.4053633]
83+
expected = np.array([1.13596361, 1.09566726, 1.05897059, 1.0808686, np.nan])
84+
np.testing.assert_array_almost_equal(bbone.load_iti(trials), expected)
85+
_ = trials.pop('stimOff_times')
86+
self.assertRaises(ValueError, bbone.load_iti, trials)
87+
88+
89+
if __name__ == '__main__':
7090
unittest.main(exit=False, verbosity=2)

examples/data_release/data_release_behavior.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"* [These instructions](https://int-brain-lab.github.io/iblenv/notebooks_external/data_structure.html) to download an example dataset for one session, and get familiarised with the data structure\n",
3030
"* [These instructions](https://int-brain-lab.github.io/iblenv/notebooks_external/data_download.html) to learn how to use the ONE-api to search and download the released datasets\n",
3131
"* [These instructions](https://int-brain-lab.github.io/iblenv/loading_examples.html) to get familiarised with specific data loading functions\n",
32+
"* [These instructions](https://int-brain-lab.github.io/iblenv/dj_docs/dj_public.html) for instructions on how to access this dataset via Datajoint. (warning: this method may be retired in 2023)\n",
33+
"\n",
3234
"\n",
3335
"Note:\n",
3436
"\n",
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "7ceb904d",
6+
"metadata": {},
7+
"source": [
8+
"# Data Release - Spike sorting benchmark datasets\n",
9+
"\n",
10+
"Spike sorting is the process by which one extracts the spikes information (times, waveforms) from the raw electrophysiology signals. In the case of our Brainwide map dataset, such electrophysiology signals are heterogeneous, changing from one brain region to another.\n",
11+
"By looking at recordings in widespread anatomical regions we discovered that the current spike sorting method has a limited range of applicability. Specifically, we uncovered two major issues. Firstly, there is no one-size-fit-all: an algorithm that is well tailored to extract signals for a given region or electrode type may perform poorly for another. Secondly, and most importantly, we had very limited means to conclude on the performance of such algorithms beyond eyes on the data and qualitative judgements.\n",
12+
"\n",
13+
"In order to facilitate the development of spike sorting algorithms, we aim to provide benchmarks datasets (for a full explanation, see our proposal [Spike Net](https://docs.google.com/document/d/1OA69Ptg58AQnGdmGi6UvZFrngwZDMixil1V7hJX6bNI/edit)). Here, we explain how to download these datasets, taken to represent various anatomical regions from our Brainwide map."
14+
]
15+
},
16+
{
17+
"cell_type": "markdown",
18+
"id": "ea567308",
19+
"metadata": {
20+
"pycharm": {
21+
"name": "#%% md\n"
22+
}
23+
},
24+
"source": [
25+
"## Overview of the Data\n",
26+
"We have selected 13 recordings for our benchmarks.\n",
27+
"\n",
28+
"The insertion IDs are :\n",
29+
"```python\n",
30+
"pids = [\n",
31+
" '1a276285-8b0e-4cc9-9f0a-a3a002978724',\n",
32+
" '1e104bf4-7a24-4624-a5b2-c2c8289c0de7',\n",
33+
" '5d570bf6-a4c6-4bf1-a14b-2c878c84ef0e',\n",
34+
" '5f7766ce-8e2e-410c-9195-6bf089fea4fd',\n",
35+
" '6638cfb3-3831-4fc2-9327-194b76cf22e1',\n",
36+
" '749cb2b7-e57e-4453-a794-f6230e4d0226',\n",
37+
" 'd7ec0892-0a6c-4f4f-9d8f-72083692af5c',\n",
38+
" 'da8dfec1-d265-44e8-84ce-6ae9c109b8bd',\n",
39+
" 'dab512bd-a02d-4c1f-8dbc-9155a163efc0',\n",
40+
" 'dc7e9403-19f7-409f-9240-05ee57cb7aea',\n",
41+
" 'e8f9fba4-d151-4b00-bee7-447f0f3e752c',\n",
42+
" 'eebcaf65-7fa4-4118-869d-a084e84530e2',\n",
43+
" 'fe380793-8035-414e-b000-09bfe5ece92a',\n",
44+
"]\n",
45+
"```\n",
46+
"\n",
47+
"(Coming soon) In 2023, we will provide 20-30min chunks of raw electrophysiology data processed in a standardised fashion, with manual annotations of spikes and quality metrics for spike detection recall. These will serve as benchmarks for spike sorting algorithm development. In the meantime, you can familiarise yourself with the data heterogeneity by looking at the whole recordings.\n",
48+
"\n",
49+
"## View the data\n",
50+
"You can view the whole electrophysiology data:\n",
51+
"\n",
52+
"* [Through a specific AWS website](http://benchmarks.internationalbrainlab.org.s3-website-us-east-1.amazonaws.com)\n",
53+
"* [Through our main visualisation website](https://viz.internationalbrainlab.org/app) , inputting a PID in the search bar at the top\n",
54+
"* By downloading the electrophysiology data (see below), and using the GUI [viewephys](https://github.com/oliche/viewephys) to navigate through it\n",
55+
"\n",
56+
"## Data structure and download\n",
57+
"The organisation of the data follows the standard IBL data structure.\n",
58+
"\n",
59+
"Please see\n",
60+
"\n",
61+
"* [These instructions](https://int-brain-lab.github.io/iblenv/notebooks_external/data_structure.html) to download an example dataset for one session, and get familiarised with the data structure\n",
62+
" * Note that probe insertion ids `pid` are provided here, not session ids `eid`.\n",
63+
" * Note that you will be most interested in the folders [raw_ephys_data](https://int-brain-lab.github.io/iblenv/notebooks_external/data_structure.html#Datasets-in-raw_ephys_data) / [probeXX](https://int-brain-lab.github.io/iblenv/notebooks_external/data_structure.html#Datasets-in-raw_ephys_data/probeXX) for the raw ephys data, and [alf/probeXX/pykilosort](https://int-brain-lab.github.io/iblenv/notebooks_external/data_structure.html#Datasets-in-alf/probeXX/pykilosort) if using the pyKilosort spike sorting output.\n",
64+
"* [These instructions](https://int-brain-lab.github.io/iblenv/notebooks_external/data_download.html) to learn how to use the ONE-api to search and download the released datasets\n",
65+
"* [These instructions](https://int-brain-lab.github.io/iblenv/loading_examples.html) to get familiarised with specific data loading functions\n",
66+
" * You will want to load in particular the [raw ephys data](https://int-brain-lab.github.io/iblenv/notebooks_external/loading_raw_ephys_data.html) and the [spike sorting data](https://int-brain-lab.github.io/iblenv/notebooks_external/loading_spikesorting_data.html) for a given `pid`\n",
67+
"\n",
68+
"\n",
69+
"Note:\n",
70+
"\n",
71+
"* The tag associated to this release is (coming up soon)"
72+
]
73+
}
74+
],
75+
"metadata": {
76+
"celltoolbar": "Edit Metadata",
77+
"kernelspec": {
78+
"display_name": "Python [conda env:iblenv] *",
79+
"language": "python",
80+
"name": "conda-env-iblenv-py"
81+
},
82+
"language_info": {
83+
"codemirror_mode": {
84+
"name": "ipython",
85+
"version": 3
86+
},
87+
"file_extension": ".py",
88+
"mimetype": "text/x-python",
89+
"name": "python",
90+
"nbconvert_exporter": "python",
91+
"pygments_lexer": "ipython3",
92+
"version": "3.9.7"
93+
}
94+
},
95+
"nbformat": 4,
96+
"nbformat_minor": 5
97+
}

examples/exploring_data/data_download.ipynb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,18 @@
196196
"execution_count": null,
197197
"outputs": [],
198198
"source": [
199+
"# Note that tags are associated with datasets originally\n",
200+
"# Find datasets that are tagged for the repeated site paper\n",
201+
"datasets_rep_site = one.alyx.rest('datasets', 'list', tag='2022_Q2_IBL_et_al_RepeatedSite')\n",
202+
"\n",
199203
"# Find sessions that have data and are tagged for the repeated site paper\n",
200-
"sessions_rep_site = one.alyx.rest('sessions', 'list', dataset_types='spikes.times', tag='2022_Q2_IBL_et_al_RepeatedSite')"
204+
"# (you have access to the tag endpoint from the session list)\n",
205+
"sessions_rep_site = one.alyx.rest('sessions', 'list', dataset_types='spikes.times', tag='2022_Q2_IBL_et_al_RepeatedSite')\n",
206+
"\n",
207+
"# Find insertions that are tagged\n",
208+
"# (you do not have access to the tag endpoint from the insertion list, so you need to create a django query)\n",
209+
"ins_str_query = 'datasets__tags__name,2022_Q2_IBL_et_al_RepeatedSite'\n",
210+
"insertions_rep_site = one.alyx.rest('insertions', 'list', django=ins_str_query)"
201211
],
202212
"metadata": {
203213
"collapsed": false
@@ -206,7 +216,7 @@
206216
{
207217
"cell_type": "markdown",
208218
"source": [
209-
"However, if you are only interested in data with a specific tag, the cleanest approach is to follow [these instructions](ttps://int-brain-lab.github.io/ONE/FAQ.html#how-do-i-download-the-datasets-cache-for-a-specific-ibl-paper-release) to work with a tag-specific cache table."
219+
"However, if you are only interested in data with a specific tag, the cleanest approach is to follow [these instructions](https://int-brain-lab.github.io/ONE/FAQ.html#how-do-i-download-the-datasets-cache-for-a-specific-ibl-paper-release) to work with a tag-specific cache table."
210220
],
211221
"metadata": {
212222
"collapsed": false
@@ -365,4 +375,4 @@
365375
},
366376
"nbformat": 4,
367377
"nbformat_minor": 0
368-
}
378+
}

ibllib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import warnings
44

5-
__version__ = '2.20.0'
5+
__version__ = '2.21.0'
66
warnings.filterwarnings('always', category=DeprecationWarning, module='ibllib')
77

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

ibllib/atlas/allen_structure_tree.csv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,12 @@ id,atlas_id,name,acronym,st_level,ontology_id,hemisphere_id,weight,parent_struct
367367
289,1026,Temporal association areas layer 5,TEa5,,1,3,8690,541,7,1,364,/997/8/567/688/695/315/541/289/,15B0B3,,,f,365,475299804,734881840,Temporal association areas layer 5
368368
729,1081,Temporal association areas layer 6a,TEa6a,,1,3,8690,541,7,1,365,/997/8/567/688/695/315/541/729/,15B0B3,,,f,366,1289955072,734881840,Temporal association areas layer 6a
369369
786,1088,Temporal association areas layer 6b,TEa6b,,1,3,8690,541,7,1,366,/997/8/567/688/695/315/541/786/,15B0B3,,,f,367,3588912826,734881840,Temporal association areas layer 6b
370-
922,256,Perirhinal area,PERI,,1,3,8690,315,6,1,367,/997/8/567/688/695/315/922/,0,,,f,368,173995527,734881840,Perirhinal area
371-
540,1057,Perirhinal area layer 1,PERI1,,1,3,8690,922,7,1,368,/997/8/567/688/695/315/922/540/,0,,,f,369,161492388,734881840,Perirhinal area layer 1
372-
888,959,Perirhinal area layer 2/3,PERI2/3,,1,3,8690,922,7,1,369,/997/8/567/688/695/315/922/888/,0,,,f,370,1642584549,734881840,Perirhinal area layer 2/3
373-
692,1076,Perirhinal area layer 5,PERI5,,1,3,8690,922,7,1,370,/997/8/567/688/695/315/922/692/,0,,,f,371,248375741,734881840,Perirhinal area layer 5
374-
335,890,Perirhinal area layer 6a,PERI6a,,1,3,8690,922,7,1,371,/997/8/567/688/695/315/922/335/,0,,,f,372,1984229208,734881840,Perirhinal area layer 6a
375-
368,894,Perirhinal area layer 6b,PERI6b,,1,3,8690,922,7,1,372,/997/8/567/688/695/315/922/368/,0,,,f,373,4014849762,734881840,Perirhinal area layer 6b
370+
922,256,Perirhinal area,PERI,,1,3,8690,315,6,1,367,/997/8/567/688/695/315/922/,0E9684,,,f,368,173995527,734881840,Perirhinal area
371+
540,1057,Perirhinal area layer 1,PERI1,,1,3,8690,922,7,1,368,/997/8/567/688/695/315/922/540/,0E9684,,,f,369,161492388,734881840,Perirhinal area layer 1
372+
888,959,Perirhinal area layer 2/3,PERI2/3,,1,3,8690,922,7,1,369,/997/8/567/688/695/315/922/888/,0E9684,,,f,370,1642584549,734881840,Perirhinal area layer 2/3
373+
692,1076,Perirhinal area layer 5,PERI5,,1,3,8690,922,7,1,370,/997/8/567/688/695/315/922/692/,0E9684,,,f,371,248375741,734881840,Perirhinal area layer 5
374+
335,890,Perirhinal area layer 6a,PERI6a,,1,3,8690,922,7,1,371,/997/8/567/688/695/315/922/335/,0E9684,,,f,372,1984229208,734881840,Perirhinal area layer 6a
375+
368,894,Perirhinal area layer 6b,PERI6b,,1,3,8690,922,7,1,372,/997/8/567/688/695/315/922/368/,0E9684,,,f,373,4014849762,734881840,Perirhinal area layer 6b
376376
895,111,Ectorhinal area,ECT,,1,3,8690,315,6,1,373,/997/8/567/688/695/315/895/,0D9F91,,,f,374,3399607880,734881840,Ectorhinal area
377377
836,1094,Ectorhinal area/Layer 1,ECT1,,1,3,8690,895,7,1,374,/997/8/567/688/695/315/895/836/,0D9F91,,,f,375,2240743692,734881840,Ectorhinal area/Layer 1
378378
427,1043,Ectorhinal area/Layer 2/3,ECT2/3,,1,3,8690,895,7,1,375,/997/8/567/688/695/315/895/427/,0D9F91,,,f,376,993691642,734881840,Ectorhinal area/Layer 2/3

0 commit comments

Comments
 (0)