Skip to content

Commit 3ecf41c

Browse files
authored
Merge pull request #367 from int-brain-lab/activate_wheel_period
Active wheel period
2 parents f7a5a74 + 21f181f commit 3ecf41c

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

ibllib/io/extractors/ephys_fpga.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,37 @@
6060
}
6161

6262

63+
def data_for_keys(keys, data):
64+
"""Check keys exist in 'data' dict and contain values other than None"""
65+
return data is not None and all(k in data and data.get(k, None) is not None for k in keys)
66+
67+
6368
def get_ibl_sync_map(ef, version):
6469
"""
6570
Gets default channel map for the version/binary file type combination
6671
:param ef: ibllib.io.spikeglx.glob_ephys_file dictionary with field 'ap' or 'nidq'
6772
:return: channel map dictionary
6873
"""
74+
# Determine default channel map
6975
if version == '3A':
7076
default_chmap = CHMAPS['3A']['ap']
7177
elif version == '3B':
7278
if ef.get('nidq', None):
7379
default_chmap = CHMAPS['3B']['nidq']
7480
elif ef.get('ap', None):
7581
default_chmap = CHMAPS['3B']['ap']
76-
return spikeglx.get_sync_map(ef['path']) or default_chmap
82+
# Try to load channel map from file
83+
chmap = spikeglx.get_sync_map(ef['path'])
84+
# If chmap provided but not with all keys, fill up with default values
85+
if not chmap:
86+
return default_chmap
87+
else:
88+
if data_for_keys(default_chmap.keys(), chmap):
89+
return chmap
90+
else:
91+
_logger.warning("Keys missing from provided channel map, "
92+
"setting missing keys from default channel map")
93+
return {**default_chmap, **chmap}
7794

7895

7996
def _sync_to_alf(raw_ephys_apfile, output_path=None, save=False, parts=''):

ibllib/qc/camera.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ def get_active_wheel_period(wheel, duration_range=(3., 20.), display=False):
274274
edges = np.c_[on, off]
275275
indices, _ = np.where(np.logical_and(
276276
np.diff(edges) > duration_range[0], np.diff(edges) < duration_range[1]))
277+
if len(indices) == 0:
278+
_log.warning('No period of wheel movement found for motion alignment.')
279+
return None
277280
# Pick movement somewhere in the middle
278281
i = indices[int(indices.size / 2)]
279282
if display:
@@ -304,7 +307,7 @@ def ensure_required_data(self):
304307
# Assert 3A probe model; if so download all probe data
305308
det = self.one.get_details(self.eid, full=True)
306309
probe_model = next(x['model'] for x in det['probe_insertion'])
307-
assert probe_model == '3A', 'raw ephys data not missing'
310+
assert probe_model == '3A', 'raw ephys data missing'
308311
collections += ('raw_ephys_data/probe00', 'raw_ephys_data/probe01')
309312
assert_unique = False
310313
for dstype in dtypes:

ibllib/tests/qc/test_camera_qc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,18 @@ def test_check_wheel_alignment(self):
252252
outcome = self.qc.check_wheel_alignment()
253253
self.assertEqual('NOT_SET', outcome)
254254

255+
def test_get_active_wheel_period(self):
256+
"""Check that warning is raised, period is returned None, and QC is NOT_SET
257+
if there is active wheel period to be found"""
258+
wheel_keys = ('timestamps', 'position')
259+
wheel_data = (np.arange(1000), np.ones(1000))
260+
self.qc.data['wheel'] = Bunch(zip(wheel_keys, wheel_data))
261+
with self.assertLogs(logging.getLogger('ibllib'), logging.WARNING):
262+
period = self.qc.get_active_wheel_period(self.qc.data['wheel'])
263+
self.assertEqual(None, period)
264+
outcome = self.qc.check_wheel_alignment()
265+
self.assertEqual('NOT_SET', outcome)
266+
255267
def test_ensure_data(self):
256268
self.qc.eid = self.eid
257269
self.qc.download_data = False

0 commit comments

Comments
 (0)