Skip to content

Commit 0d80f27

Browse files
committed
Remove deprecated spike sorting loader functions
1 parent 65e8176 commit 0d80f27

File tree

3 files changed

+0
-287
lines changed

3 files changed

+0
-287
lines changed

brainbox/examples/raster_depths.py

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

brainbox/io/one.py

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import gc
44
import logging
55
import re
6-
import os
76
from pathlib import Path
87
from collections import defaultdict
98

@@ -410,191 +409,6 @@ def load_channel_locations(eid, probe=None, one=None, aligned=False, brain_atlas
410409
return channels
411410

412411

413-
def load_spike_sorting_fast(eid, one=None, probe=None, dataset_types=None, spike_sorter=None, revision=None,
414-
brain_regions=None, nested=True, collection=None, return_collection=False):
415-
"""
416-
From an eid, loads spikes and clusters for all probes
417-
The following set of dataset types are loaded:
418-
'clusters.channels',
419-
'clusters.depths',
420-
'clusters.metrics',
421-
'spikes.clusters',
422-
'spikes.times',
423-
'probes.description'
424-
:param eid: experiment UUID or pathlib.Path of the local session
425-
:param one: an instance of OneAlyx
426-
:param probe: name of probe to load in, if not given all probes for session will be loaded
427-
:param dataset_types: additional spikes/clusters objects to add to the standard default list
428-
:param spike_sorter: name of the spike sorting you want to load (None for default)
429-
:param collection: name of the spike sorting collection to load - exclusive with spike sorter name ex: "alf/probe00"
430-
:param brain_regions: iblatlas.regions.BrainRegions object - will label acronyms if provided
431-
:param nested: if a single probe is required, do not output a dictionary with the probe name as key
432-
:param return_collection: (False) if True, will return the collection used to load
433-
:return: spikes, clusters, channels (dict of bunch, 1 bunch per probe)
434-
"""
435-
_logger.warning('Deprecation warning: brainbox.io.one.load_spike_sorting_fast will be removed in future versions.'
436-
'Use brainbox.io.one.SpikeSortingLoader instead')
437-
if collection is None:
438-
collection = _collection_filter_from_args(probe, spike_sorter)
439-
_logger.debug(f"load spike sorting with collection filter {collection}")
440-
kwargs = dict(eid=eid, one=one, collection=collection, revision=revision, dataset_types=dataset_types,
441-
brain_regions=brain_regions)
442-
spikes, clusters, channels = _load_spike_sorting(**kwargs, return_channels=True)
443-
clusters = merge_clusters_channels(clusters, channels, keys_to_add_extra=None)
444-
if nested is False and len(spikes.keys()) == 1:
445-
k = list(spikes.keys())[0]
446-
channels = channels[k]
447-
clusters = clusters[k]
448-
spikes = spikes[k]
449-
if return_collection:
450-
return spikes, clusters, channels, collection
451-
else:
452-
return spikes, clusters, channels
453-
454-
455-
def load_spike_sorting(eid, one=None, probe=None, dataset_types=None, spike_sorter=None, revision=None,
456-
brain_regions=None, return_collection=False):
457-
"""
458-
From an eid, loads spikes and clusters for all probes
459-
The following set of dataset types are loaded:
460-
'clusters.channels',
461-
'clusters.depths',
462-
'clusters.metrics',
463-
'spikes.clusters',
464-
'spikes.times',
465-
'probes.description'
466-
:param eid: experiment UUID or pathlib.Path of the local session
467-
:param one: an instance of OneAlyx
468-
:param probe: name of probe to load in, if not given all probes for session will be loaded
469-
:param dataset_types: additional spikes/clusters objects to add to the standard default list
470-
:param spike_sorter: name of the spike sorting you want to load (None for default)
471-
:param brain_regions: iblatlas.regions.BrainRegions object - will label acronyms if provided
472-
:param return_collection:(bool - False) if True, returns the collection for loading the data
473-
:return: spikes, clusters (dict of bunch, 1 bunch per probe)
474-
"""
475-
_logger.warning('Deprecation warning: brainbox.io.one.load_spike_sorting will be removed in future versions.'
476-
'Use brainbox.io.one.SpikeSortingLoader instead')
477-
collection = _collection_filter_from_args(probe, spike_sorter)
478-
_logger.debug(f"load spike sorting with collection filter {collection}")
479-
spikes, clusters = _load_spike_sorting(eid=eid, one=one, collection=collection, revision=revision,
480-
return_channels=False, dataset_types=dataset_types,
481-
brain_regions=brain_regions)
482-
if return_collection:
483-
return spikes, clusters, collection
484-
else:
485-
return spikes, clusters
486-
487-
488-
def load_spike_sorting_with_channel(eid, one=None, probe=None, aligned=False, dataset_types=None,
489-
spike_sorter=None, brain_atlas=None, nested=True, return_collection=False):
490-
"""
491-
For a given eid, get spikes, clusters and channels information, and merges clusters
492-
and channels information before returning all three variables.
493-
494-
Parameters
495-
----------
496-
eid : [str, UUID, Path, dict]
497-
Experiment session identifier; may be a UUID, URL, experiment reference string
498-
details dict or Path
499-
one : one.api.OneAlyx
500-
An instance of ONE (shouldn't be in 'local' mode)
501-
probe : [str, list of str]
502-
The probe label(s), e.g. 'probe01'
503-
aligned : bool
504-
Whether to get the latest user aligned channel when not resolved or use histology track
505-
dataset_types : list of str
506-
Optional additional spikes/clusters objects to add to the standard default list
507-
spike_sorter : str
508-
Name of the spike sorting you want to load (None for default which is pykilosort if it's
509-
available otherwise the default MATLAB kilosort)
510-
brain_atlas : iblatlas.atlas.BrainAtlas
511-
Brain atlas object (default: Allen atlas)
512-
return_collection: bool
513-
Returns an extra argument with the collection chosen
514-
515-
Returns
516-
-------
517-
spikes : dict of one.alf.io.AlfBunch
518-
A dict with probe labels as keys, contains bunch(es) of spike data for the provided
519-
session and spike sorter, with keys ('clusters', 'times')
520-
clusters : dict of one.alf.io.AlfBunch
521-
A dict with probe labels as keys, contains bunch(es) of cluster data, with keys
522-
('channels', 'depths', 'metrics')
523-
channels : dict of one.alf.io.AlfBunch
524-
A dict with probe labels as keys, contains channel locations with keys ('acronym',
525-
'atlas_id', 'x', 'y', 'z'). Atlas IDs non-lateralized.
526-
"""
527-
# --- Get spikes and clusters data
528-
_logger.warning('Deprecation warning: brainbox.io.one.load_spike_sorting will be removed in future versions.'
529-
'Use brainbox.io.one.SpikeSortingLoader instead')
530-
one = one or ONE()
531-
brain_atlas = brain_atlas or AllenAtlas()
532-
spikes, clusters, collection = load_spike_sorting(
533-
eid, one=one, probe=probe, dataset_types=dataset_types, spike_sorter=spike_sorter, return_collection=True)
534-
# -- Get brain regions and assign to clusters
535-
channels = load_channel_locations(eid, one=one, probe=probe, aligned=aligned,
536-
brain_atlas=brain_atlas)
537-
clusters = merge_clusters_channels(clusters, channels, keys_to_add_extra=None)
538-
if nested is False and len(spikes.keys()) == 1:
539-
k = list(spikes.keys())[0]
540-
channels = channels[k]
541-
clusters = clusters[k]
542-
spikes = spikes[k]
543-
if return_collection:
544-
return spikes, clusters, channels, collection
545-
else:
546-
return spikes, clusters, channels
547-
548-
549-
def load_ephys_session(eid, one=None):
550-
"""
551-
From an eid, hits the Alyx database and downloads a standard default set of dataset types
552-
From a local session Path (pathlib.Path), loads a standard default set of dataset types
553-
to perform analysis:
554-
'clusters.channels',
555-
'clusters.depths',
556-
'clusters.metrics',
557-
'spikes.clusters',
558-
'spikes.times',
559-
'probes.description'
560-
561-
Parameters
562-
----------
563-
eid : [str, UUID, Path, dict]
564-
Experiment session identifier; may be a UUID, URL, experiment reference string
565-
details dict or Path
566-
one : oneibl.one.OneAlyx, optional
567-
ONE object to use for loading. Will generate internal one if not used, by default None
568-
569-
Returns
570-
-------
571-
spikes : dict of one.alf.io.AlfBunch
572-
A dict with probe labels as keys, contains bunch(es) of spike data for the provided
573-
session and spike sorter, with keys ('clusters', 'times')
574-
clusters : dict of one.alf.io.AlfBunch
575-
A dict with probe labels as keys, contains bunch(es) of cluster data, with keys
576-
('channels', 'depths', 'metrics')
577-
trials : one.alf.io.AlfBunch of numpy.ndarray
578-
The session trials data
579-
"""
580-
assert one
581-
spikes, clusters = load_spike_sorting(eid, one=one)
582-
trials = one.load_object(eid, 'trials')
583-
return spikes, clusters, trials
584-
585-
586-
def _remove_old_clusters(session_path, probe):
587-
# gets clusters and spikes from a local session folder
588-
probe_path = session_path.joinpath('alf', probe)
589-
590-
# look for clusters.metrics.csv file, if it exists delete as we now have .pqt file instead
591-
cluster_file = probe_path.joinpath('clusters.metrics.csv')
592-
593-
if cluster_file.exists():
594-
os.remove(cluster_file)
595-
_logger.info('Deleting old clusters.metrics.csv file')
596-
597-
598412
def merge_clusters_channels(dic_clus, channels, keys_to_add_extra=None):
599413
"""
600414
Takes (default and any extra) values in given keys from channels and assign them to clusters.

brainbox/tests/test_io.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,8 @@
1-
import json
2-
from pathlib import Path
31
import unittest
4-
import tempfile
5-
import shutil
62

73
import numpy as np
8-
import numpy.testing
94

105
from brainbox.io import one as bbone
11-
from one.api import ONE
12-
from one.alf.cache import make_parquet_db
13-
14-
15-
class TestIO_ALF(unittest.TestCase):
16-
17-
def setUp(self) -> None:
18-
"""
19-
Creates a mock ephys alf data folder with minimal spikes info for loading
20-
:return:
21-
"""
22-
self.tmpdir = Path(tempfile.gettempdir()) / 'test_bbio'
23-
self.tmpdir.mkdir(exist_ok=True)
24-
self.one = ONE(mode='local', cache_dir=self.tmpdir)
25-
self.alf_path = self.tmpdir.joinpath(
26-
'lab', 'Subjects', 'subject', '2019-08-12', '001', 'alf'
27-
)
28-
self.session_path = self.alf_path.parent
29-
self.probes = ['probe00', 'probe01']
30-
nspi = [10000, 10001]
31-
nclusters = [420, 421]
32-
nch = [64, 62]
33-
probe_description = []
34-
for i, prb in enumerate(self.probes):
35-
prb_path = self.alf_path.joinpath(prb)
36-
prb_path.mkdir(exist_ok=True, parents=True)
37-
np.save(prb_path.joinpath('clusters.channels.npy'),
38-
np.random.randint(0, nch[i], nclusters[i]))
39-
np.save(prb_path.joinpath('spikes.depths.npy'),
40-
np.random.rand(nspi[i]) * 3200)
41-
np.save(prb_path.joinpath('spikes.clusters.npy'),
42-
np.random.randint(0, nclusters[i], nspi[i]))
43-
np.save(prb_path.joinpath('spikes.times.npy'),
44-
np.sort(np.random.random(nspi[i]) * 1200))
45-
46-
probe_description.append({'label': prb,
47-
'model': '3B1',
48-
'serial': int(456248),
49-
'raw_file_name': 'gnagnagnaga',
50-
})
51-
# create session level
52-
with open(self.alf_path.joinpath('probes.description.json'), 'w+') as fid:
53-
fid.write(json.dumps(probe_description))
54-
np.save(self.alf_path.joinpath('trials.gnagnag.npy'), np.random.rand(50))
55-
# Add some fake records to the cache
56-
if not self.one.search(subject='subject', date='2019-08-12', number='001'):
57-
make_parquet_db(self.tmpdir)
58-
self.one.load_cache(cache_dir=self.tmpdir)
59-
60-
def test_load_ephys(self):
61-
# straight test
62-
spikes, clusters, trials = bbone.load_ephys_session(self.session_path, one=self.one)
63-
self.assertTrue(set(spikes.keys()) == set(self.probes))
64-
self.assertTrue(set(clusters.keys()) == set(self.probes))
65-
66-
def tearDown(self) -> None:
67-
shutil.rmtree(self.tmpdir)
686

697

708
class TestIO_ONE(unittest.TestCase):

0 commit comments

Comments
 (0)