@@ -270,6 +270,8 @@ def channel_locations_interpolation(channels_aligned, channels=None, brain_regio
270270
271271def _load_channel_locations_traj (eid , probe = None , one = None , revision = None , aligned = False ,
272272 brain_atlas = None , return_source = False ):
273+ if not hasattr (one , 'alyx' ):
274+ return {}, None
273275 _logger .debug (f"trying to load from traj { probe } " )
274276 channels = Bunch ()
275277 brain_atlas = brain_atlas or AllenAtlas
@@ -416,6 +418,8 @@ def load_spike_sorting_fast(eid, one=None, probe=None, dataset_types=None, spike
416418 :param return_collection: (False) if True, will return the collection used to load
417419 :return: spikes, clusters, channels (dict of bunch, 1 bunch per probe)
418420 """
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' )
419423 if collection is None :
420424 collection = _collection_filter_from_args (probe , spike_sorter )
421425 _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
455459 :param return_collection:(bool - False) if True, returns the collection for loading the data
456460 :return: spikes, clusters (dict of bunch, 1 bunch per probe)
457461 """
462+ _logger .warning ('Deprecation warning: brainbox.io.one.load_spike_sorting will be removed in future versions.'
463+ 'Use brainbox.io.one.SpikeSortingLoader instead' )
458464 collection = _collection_filter_from_args (probe , spike_sorter )
459465 _logger .debug (f"load spike sorting with collection filter { collection } " )
460466 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
506512 'atlas_id', 'x', 'y', 'z'). Atlas IDs non-lateralized.
507513 """
508514 # --- 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' )
509517 one = one or ONE ()
510518 brain_atlas = brain_atlas or AllenAtlas ()
511519 spikes , clusters , collection = load_spike_sorting (
@@ -862,12 +870,17 @@ def load_channels_from_insertion(ins, depths=None, one=None, ba=None):
862870
863871@dataclass
864872class 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+ """
867878 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
870881 eid : str = ''
882+ pname : str = ''
883+ # the following properties are the outcome of the post init funciton
871884 session_path : Path = ''
872885 collections : list = None
873886 datasets : list = None # list of all datasets belonging to the sesion
@@ -878,7 +891,10 @@ class SpikeSortingLoader:
878891 spike_sorting_path : Path = None
879892
880893 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 ()
882898 self .session_path = self .one .eid2path (self .eid )
883899 self .collections = self .one .list_collections (
884900 self .eid , filename = 'spikes*' , collection = f"alf/{ self .pname } *" )
@@ -909,32 +925,61 @@ def _get_spike_sorting_collection(self, spike_sorter='pykilosort', revision=None
909925 return collection
910926
911927 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+ """
912935 if len (self .collections ) == 0 :
913936 return {}, {}, {}
914937 self .collection = self ._get_spike_sorting_collection (spike_sorter = spike_sorter )
938+ _logger .debug (f"loading spike sorting from { self .collection } " )
915939 spike_attributes , cluster_attributes = self ._get_attributes (dataset_types )
916940 attributes = {'spikes' : spike_attributes , 'clusters' : cluster_attributes , 'channels' : None }
917941 self .files [obj ] = self .one .load_object (self .eid , obj = obj , attribute = attributes [obj ],
918942 collection = self .collection , download_only = True )
919943
920944 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+ """
922951 for obj in ['spikes' , 'clusters' , 'channels' ]:
923952 self ._download_spike_sorting_object (obj = obj , ** kwargs )
924953 self .spike_sorting_path = self .files ['spikes' ][0 ].parent
925954
926955 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+ """
928972 if len (self .collections ) == 0 :
929973 return {}, {}, {}
930974 self .download_spike_sorting (** kwargs )
931975 channels = alfio .load_object (self .files ['channels' ], wildcards = self .one .wildcards )
932976 clusters = alfio .load_object (self .files ['clusters' ], wildcards = self .one .wildcards )
933977 spikes = alfio .load_object (self .files ['spikes' ], wildcards = self .one .wildcards )
934978 if 'brainLocationIds_ccf_2017' not in channels :
935- channels , self .histology = _load_channel_locations_traj (
979+ _channels , self .histology = _load_channel_locations_traj (
936980 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 ]
938983 else :
939984 channels = _channels_alf2bunch (channels , brain_regions = self .atlas .regions )
940985 self .histology = 'alf'
0 commit comments