@@ -270,6 +270,8 @@ def channel_locations_interpolation(channels_aligned, channels=None, brain_regio
270
270
271
271
def _load_channel_locations_traj (eid , probe = None , one = None , revision = None , aligned = False ,
272
272
brain_atlas = None , return_source = False ):
273
+ if not hasattr (one , 'alyx' ):
274
+ return {}, None
273
275
_logger .debug (f"trying to load from traj { probe } " )
274
276
channels = Bunch ()
275
277
brain_atlas = brain_atlas or AllenAtlas
@@ -416,6 +418,8 @@ def load_spike_sorting_fast(eid, one=None, probe=None, dataset_types=None, spike
416
418
:param return_collection: (False) if True, will return the collection used to load
417
419
:return: spikes, clusters, channels (dict of bunch, 1 bunch per probe)
418
420
"""
421
+ _logger .warning ('Deprecation warning: brainbox.io.one.load_spike_sorting_fast will be removed in future versions.'
422
+ 'Use brainbox.io.one.SpikeSortingLoader instead' )
419
423
if collection is None :
420
424
collection = _collection_filter_from_args (probe , spike_sorter )
421
425
_logger .debug (f"load spike sorting with collection filter { collection } " )
@@ -455,6 +459,8 @@ def load_spike_sorting(eid, one=None, probe=None, dataset_types=None, spike_sort
455
459
:param return_collection:(bool - False) if True, returns the collection for loading the data
456
460
:return: spikes, clusters (dict of bunch, 1 bunch per probe)
457
461
"""
462
+ _logger .warning ('Deprecation warning: brainbox.io.one.load_spike_sorting will be removed in future versions.'
463
+ 'Use brainbox.io.one.SpikeSortingLoader instead' )
458
464
collection = _collection_filter_from_args (probe , spike_sorter )
459
465
_logger .debug (f"load spike sorting with collection filter { collection } " )
460
466
spikes , clusters = _load_spike_sorting (eid = eid , one = one , collection = collection , revision = revision ,
@@ -506,6 +512,8 @@ def load_spike_sorting_with_channel(eid, one=None, probe=None, aligned=False, da
506
512
'atlas_id', 'x', 'y', 'z'). Atlas IDs non-lateralized.
507
513
"""
508
514
# --- Get spikes and clusters data
515
+ _logger .warning ('Deprecation warning: brainbox.io.one.load_spike_sorting will be removed in future versions.'
516
+ 'Use brainbox.io.one.SpikeSortingLoader instead' )
509
517
one = one or ONE ()
510
518
brain_atlas = brain_atlas or AllenAtlas ()
511
519
spikes , clusters , collection = load_spike_sorting (
@@ -862,12 +870,17 @@ def load_channels_from_insertion(ins, depths=None, one=None, ba=None):
862
870
863
871
@dataclass
864
872
class SpikeSortingLoader :
865
- """Class for loading spike sorting"""
866
- pid : str
873
+ """
874
+ Object that will load spike sorting data for a given probe insertion.
875
+
876
+
877
+ """
867
878
one : ONE
868
- atlas : None
869
- # the following properties are the outcome of the post init funciton
879
+ atlas : None = None
880
+ pid : str = None
870
881
eid : str = ''
882
+ pname : str = ''
883
+ # the following properties are the outcome of the post init funciton
871
884
session_path : Path = ''
872
885
collections : list = None
873
886
datasets : list = None # list of all datasets belonging to the sesion
@@ -878,7 +891,10 @@ class SpikeSortingLoader:
878
891
spike_sorting_path : Path = None
879
892
880
893
def __post_init__ (self ):
881
- self .eid , self .pname = self .one .pid2eid (self .pid )
894
+ if self .pid is not None :
895
+ self .eid , self .pname = self .one .pid2eid (self .pid )
896
+ if self .atlas is None :
897
+ self .atlas = AllenAtlas ()
882
898
self .session_path = self .one .eid2path (self .eid )
883
899
self .collections = self .one .list_collections (
884
900
self .eid , filename = 'spikes*' , collection = f"alf/{ self .pname } *" )
@@ -909,32 +925,61 @@ def _get_spike_sorting_collection(self, spike_sorter='pykilosort', revision=None
909
925
return collection
910
926
911
927
def _download_spike_sorting_object (self , obj , spike_sorter = 'pykilosort' , dataset_types = None ):
928
+ """
929
+ Downloads an ALF object
930
+ :param obj: object name, str between 'spikes', 'clusters' or 'channels'
931
+ :param spike_sorter: (defaults to 'pykilosort')
932
+ :param dataset_types: list of extra dataset types
933
+ :return:
934
+ """
912
935
if len (self .collections ) == 0 :
913
936
return {}, {}, {}
914
937
self .collection = self ._get_spike_sorting_collection (spike_sorter = spike_sorter )
938
+ _logger .debug (f"loading spike sorting from { self .collection } " )
915
939
spike_attributes , cluster_attributes = self ._get_attributes (dataset_types )
916
940
attributes = {'spikes' : spike_attributes , 'clusters' : cluster_attributes , 'channels' : None }
917
941
self .files [obj ] = self .one .load_object (self .eid , obj = obj , attribute = attributes [obj ],
918
942
collection = self .collection , download_only = True )
919
943
920
944
def download_spike_sorting (self , ** kwargs ):
921
- """spike_sorter='pykilosort', dataset_types=None"""
945
+ """
946
+ Downloads spikes, clusters and channels
947
+ :param spike_sorter: (defaults to 'pykilosort')
948
+ :param dataset_types: list of extra dataset types
949
+ :return:
950
+ """
922
951
for obj in ['spikes' , 'clusters' , 'channels' ]:
923
952
self ._download_spike_sorting_object (obj = obj , ** kwargs )
924
953
self .spike_sorting_path = self .files ['spikes' ][0 ].parent
925
954
926
955
def load_spike_sorting (self , ** kwargs ):
927
- """spike_sorter='pykilosort', dataset_types=None"""
956
+ """
957
+ Loads spikes, clusters and channels
958
+
959
+ There could be several spike sorting collections, by default the loader will get the pykilosort collection
960
+
961
+ The channel locations can come from several sources, it will load the most advanced version of the histology available,
962
+ regardless of the spike sorting version loaded. The steps are (from most advanced to fresh out of the imaging):
963
+ - alf: the final version of channel locations, same as resolved with the difference that data is on file
964
+ - resolved: channel locations alignments have been agreed upon
965
+ - aligned: channel locations have been aligned, but review or other alignments are pending, potentially not accurate
966
+ - traced: the histology track has been recovered from microscopy, however the depths may not match, inacurate data
967
+
968
+ :param spike_sorter: (defaults to 'pykilosort')
969
+ :param dataset_types: list of extra dataset types
970
+ :return:
971
+ """
928
972
if len (self .collections ) == 0 :
929
973
return {}, {}, {}
930
974
self .download_spike_sorting (** kwargs )
931
975
channels = alfio .load_object (self .files ['channels' ], wildcards = self .one .wildcards )
932
976
clusters = alfio .load_object (self .files ['clusters' ], wildcards = self .one .wildcards )
933
977
spikes = alfio .load_object (self .files ['spikes' ], wildcards = self .one .wildcards )
934
978
if 'brainLocationIds_ccf_2017' not in channels :
935
- channels , self .histology = _load_channel_locations_traj (
979
+ _channels , self .histology = _load_channel_locations_traj (
936
980
self .eid , probe = self .pname , one = self .one , brain_atlas = self .atlas , return_source = True )
937
- channels = channels [self .pname ]
981
+ if _channels :
982
+ channels = _channels [self .pname ]
938
983
else :
939
984
channels = _channels_alf2bunch (channels , brain_regions = self .atlas .regions )
940
985
self .histology = 'alf'
0 commit comments