1414
1515from ibllib .qc import base
1616import one .alf .io as alfio
17+ from one .alf .exceptions import ALFObjectNotFound
1718from one .alf .spec import is_session_path
1819from iblutil .util import Bunch
1920
2324class 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 """
0 commit comments