Skip to content

Commit da9b315

Browse files
authored
Merge pull request #450 from int-brain-lab/ow
bugfix: ephys streamer always re-downloads files
2 parents fa7bbd4 + f5eb8a6 commit da9b315

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

brainbox/io/one.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ def _get_spike_sorting_collection(self, spike_sorter='pykilosort', revision=None
941941
_logger.debug(f"selecting: {collection} to load amongst candidates: {self.collections}")
942942
return collection
943943

944-
def _download_spike_sorting_object(self, obj, spike_sorter='pykilosort', dataset_types=None):
944+
def download_spike_sorting_object(self, obj, spike_sorter='pykilosort', dataset_types=None):
945945
"""
946946
Downloads an ALF object
947947
:param obj: object name, str between 'spikes', 'clusters' or 'channels'
@@ -954,7 +954,8 @@ def _download_spike_sorting_object(self, obj, spike_sorter='pykilosort', dataset
954954
self.collection = self._get_spike_sorting_collection(spike_sorter=spike_sorter)
955955
_logger.debug(f"loading spike sorting from {self.collection}")
956956
spike_attributes, cluster_attributes = self._get_attributes(dataset_types)
957-
attributes = {'spikes': spike_attributes, 'clusters': cluster_attributes, 'channels': None}
957+
attributes = {'spikes': spike_attributes, 'clusters': cluster_attributes, 'channels': None,
958+
'templates': None, 'spikes_subset': None}
958959
self.files[obj] = self.one.load_object(self.eid, obj=obj, attribute=attributes[obj],
959960
collection=self.collection, download_only=True)
960961

@@ -966,7 +967,7 @@ def download_spike_sorting(self, **kwargs):
966967
:return:
967968
"""
968969
for obj in ['spikes', 'clusters', 'channels']:
969-
self._download_spike_sorting_object(obj=obj, **kwargs)
970+
self.download_spike_sorting_object(obj=obj, **kwargs)
970971
self.spike_sorting_path = self.files['spikes'][0].parent
971972

972973
def load_spike_sorting(self, **kwargs):

brainbox/io/spikeglx.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from pathlib import Path
44
import time
5+
import json
56

67
import numpy as np
78

@@ -126,14 +127,22 @@ def stream(pid, t0, nsecs=1, one=None, cache_folder=None, remove_cached=False, t
126127
if cache_folder is None:
127128
samples_folder = Path(one.alyx._par.CACHE_DIR).joinpath('cache', typ)
128129

130+
def _get_file(one_rec):
131+
fpath = Path(one.alyx._par.CACHE_DIR).joinpath(
132+
str(one_rec['session_path'].values[0]),
133+
str(one_rec['rel_path'].values[0]))
134+
if fpath.exists():
135+
return fpath
136+
else:
137+
return one._download_datasets(one_rec)[0]
138+
129139
eid, pname = one.pid2eid(pid)
130140
cbin_rec = one.list_datasets(eid, collection=f"*{pname}", filename=f'*{typ}.*bin', details=True)
131141
ch_rec = one.list_datasets(eid, collection=f"*{pname}", filename=f'*{typ}.ch', details=True)
132142
meta_rec = one.list_datasets(eid, collection=f"*{pname}", filename=f'*{typ}.meta', details=True)
133-
ch_file = one._download_datasets(ch_rec)[0]
134-
one._download_datasets(meta_rec)[0]
143+
ch_file = _get_file(ch_rec)
144+
_get_file(meta_rec)
135145

136-
import json
137146
with open(ch_file) as fid:
138147
chinfo = json.load(fid)
139148
tbounds = np.array(chinfo['chunk_bounds']) / chinfo['sample_rate']

0 commit comments

Comments
 (0)