Skip to content

Commit 91abb56

Browse files
committed
Merge branch 'release/2.1.2'
2 parents fa8f3d4 + 8cbd7cd commit 91abb56

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

ibllib/ephys/ephysqc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ class EphysQC(base.QC):
4242
default database if not given.
4343
"""
4444

45-
def __init__(self, probe_id, **kwargs):
45+
def __init__(self, probe_id, session_path=None, **kwargs):
4646
super().__init__(probe_id, endpoint='insertions', **kwargs)
4747
self.pid = probe_id
48+
self.session_path = session_path
4849
self.stream = kwargs.pop('stream', True)
4950
keys = ('ap', 'ap_meta', 'lf', 'lf_meta')
5051
self.data = Bunch.fromkeys(keys)
@@ -57,7 +58,9 @@ def _ensure_required_data(self):
5758
"""
5859
assert self.one is not None, 'ONE instance is required to ensure required data'
5960
eid, pname = self.one.pid2eid(self.pid)
60-
self.probe_path = self.one.eid2path(eid).joinpath('raw_ephys_data', pname)
61+
if self.session_path is None:
62+
self.session_path = self.one.eid2path(eid)
63+
self.probe_path = Path(self.session_path).joinpath('raw_ephys_data', pname)
6164
# Check if there is at least one meta file available
6265
meta_files = list(self.probe_path.rglob('*.meta'))
6366
assert len(meta_files) != 0, f'No meta files in {self.probe_path}'

ibllib/io/extractors/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,14 @@ def get_pipeline(session_path):
220220

221221

222222
def _get_pipeline_from_task_type(stype):
223+
"""
224+
Returns the pipeline from the task type. Some tasks types directly define the pipeline
225+
:param stype: session_type or task extractor type
226+
:return:
227+
"""
223228
if 'ephys' in stype:
224229
return 'ephys'
225230
elif stype in ['habituation', 'training', 'biased', 'biased_opto']:
226231
return 'training'
232+
else:
233+
return stype

ibllib/pipes/ephys_preprocessing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _run(self, overwrite=False):
6969
pids = [p['id'] for p in create_alyx_probe_insertions(self.session_path, one=self.one)]
7070
qc_files = []
7171
for pid in pids:
72-
eqc = ephysqc.EphysQC(pid, one=self.one)
72+
eqc = ephysqc.EphysQC(pid, session_path=self.session_path, one=self.one)
7373
qc_files.extend(eqc.run(update=True, overwrite=overwrite))
7474
return qc_files
7575

ibllib/qc/dlc.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from ibllib.qc import base
1616
import one.alf.io as alfio
17+
from one.alf.exceptions import ALFObjectNotFound
1718
from one.alf.spec import is_session_path
1819
from iblutil.util import Bunch
1920

@@ -23,7 +24,6 @@
2324
class DlcQC(base.QC):
2425
"""A class for computing camera QC metrics"""
2526

26-
dstypes = ['camera.dlc', 'camera.times']
2727
bbox = {
2828
'body': {
2929
'xrange': range(201, 500),
@@ -42,16 +42,17 @@ class DlcQC(base.QC):
4242
def __init__(self, session_path_or_eid, side, **kwargs):
4343
"""
4444
:param session_path_or_eid: A session eid or path
45+
:param side: The camera to run QC on
4546
:param log: A logging.Logger instance, if None the 'ibllib' logger is used
4647
:param one: An ONE instance for fetching and setting the QC on Alyx
47-
:param camera: The camera to run QC on, if None QC is run for all three cameras.
4848
"""
49+
# Make sure the type of camera is chosen
50+
self.side = side
4951
# When an eid is provided, we will download the required data by default (if necessary)
5052
download_data = not is_session_path(session_path_or_eid)
5153
self.download_data = kwargs.pop('download_data', download_data)
5254
super().__init__(session_path_or_eid, **kwargs)
5355
self.data = Bunch()
54-
self.side = side
5556

5657
# QC outcomes map
5758
self.metrics = None
@@ -95,15 +96,18 @@ def _ensure_required_data(self):
9596
it an exception is raised.
9697
:return:
9798
"""
98-
assert self.one is not None, 'ONE required to download data'
99-
for dstype in self.dstypes:
100-
dataset = self.one.type2datasets(self.eid, dstype, details=True)
101-
present = (
102-
self.one._download_datasets(dataset)
103-
if self.download_data
104-
else (next(self.session_path.rglob(d), None) for d in dataset['rel_path'])
105-
)
106-
assert (not dataset.empty and all(present)), f'Dataset {dstype} not found'
99+
# Check if data available locally
100+
for ds in [f'_ibl_{self.side}Camera.dlc.*', f'_ibl_{self.side}Camera.times.*']:
101+
if not next(self.session_path.rglob(ds), None):
102+
# If download is allowed, try to download
103+
if self.download_data is True:
104+
assert self.one is not None, 'ONE required to download data'
105+
try:
106+
self.one.load_dataset(self.eid, ds, download_only=True)
107+
except ALFObjectNotFound:
108+
raise AssertionError(f'Dataset {ds} not found locally and failed to download')
109+
else:
110+
raise AssertionError(f'Dataset {ds} not found locally and download_data is False')
107111

108112
def run(self, update: bool = False, **kwargs) -> (str, dict):
109113
"""

ibllib/tests/qc/test_dlc_qc.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ def tearDownClass(cls) -> None:
3333
def test_ensure_data(self):
3434
self.qc.eid = self.eid
3535
self.qc.download_data = False
36-
# If data for this session exists locally, overwrite the methods so it is not found
37-
if self.one.eid2path(self.eid).exists():
38-
self.qc.one.to_eid = lambda _: self.eid
39-
self.qc.one._download_datasets = lambda _: None
40-
with self.assertRaises(AssertionError):
36+
# Remove file so that the test fails as intended
37+
if self.qc.session_path.exists():
38+
self.qc.session_path.joinpath('alf/_ibl_leftCamera.dlc.pqt').unlink()
39+
with self.assertRaises(AssertionError) as excp:
4140
self.qc.run(update=False)
41+
msg = excp.exception.args[0]
42+
self.assertEqual(msg, 'Dataset _ibl_leftCamera.dlc.* not found locally and download_data is False')
43+
# Set download_data to True. Data is not in the database so we expect a (different) error trying to download
44+
self.qc.download_data = True
45+
with self.assertRaises(AssertionError) as excp:
46+
self.qc.run(update=False)
47+
msg = excp.exception.args[0]
48+
self.assertEqual(msg, 'Dataset _ibl_leftCamera.dlc.* not found locally and failed to download')
4249

4350
def test_check_time_trace_length_match(self):
4451
self.qc.data['dlc_coords'] = {'nose_tip': np.ones((2, 20)), 'pupil_r': np.ones((2, 20))}

release_notes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
- destriping as pykilosort internal pre-processing
44
- NP2 probe framework for splitting shanks and LFP band
55
- Extension of task module to rerun from different locations
6-
### Release Notes 2.1.0 2021-10-06
6+
### Release Notes 2.1.1 2021-10-06
77
- RawEphysQC tasks computes median RMS from samples for .ap data (stored in _iblqc_ephysChannels.RMS)
88
- New EphysQC class
9+
### Release Notes 2.1.2 2021-10-14
10+
- Fix issue with RawEphysQC that was not looking in local Subjects folder for data
11+
- Fix ensure_required_data in DlcQc
912

1013
## Release Notes 2.0
1114
### Release Notes 2.0.1 2021-08-07

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
setup(
2626
name='ibllib',
27-
version='2.1.1',
27+
version='2.1.2',
2828
python_requires='>={}.{}'.format(*REQUIRED_PYTHON),
2929
description='IBL libraries',
3030
license="MIT",

0 commit comments

Comments
 (0)