|
14 | 14 |
|
15 | 15 | from ibllib.qc import base |
16 | 16 | import one.alf.io as alfio |
| 17 | +from one.alf.exceptions import ALFObjectNotFound |
17 | 18 | from one.alf.spec import is_session_path |
18 | 19 | from iblutil.util import Bunch |
19 | 20 |
|
|
23 | 24 | class DlcQC(base.QC): |
24 | 25 | """A class for computing camera QC metrics""" |
25 | 26 |
|
26 | | - dstypes = ['camera.dlc', 'camera.times'] |
27 | 27 | bbox = { |
28 | 28 | 'body': { |
29 | 29 | 'xrange': range(201, 500), |
@@ -96,15 +96,18 @@ def _ensure_required_data(self): |
96 | 96 | it an exception is raised. |
97 | 97 | :return: |
98 | 98 | """ |
99 | | - assert self.one is not None, 'ONE required to download data' |
100 | | - for dstype in self.dstypes: |
101 | | - dataset = self.one.type2datasets(self.eid, dstype, details=True) |
102 | | - present = ( |
103 | | - self.one._download_datasets(dataset) |
104 | | - if self.download_data |
105 | | - else (next(self.session_path.rglob(d), None) for d in dataset['rel_path'] if self.side in d) |
106 | | - ) |
107 | | - 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') |
108 | 111 |
|
109 | 112 | def run(self, update: bool = False, **kwargs) -> (str, dict): |
110 | 113 | """ |
|
0 commit comments