99
1010try :
1111 import cv2 # type: ignore
12- except ImportError :
12+
13+ CV2_AVAILABLE = True
14+ except ImportError as e :
1315 cv2 = None # type: ignore
16+ CV2_AVAILABLE = False
17+ _CV2_IMPORT_ERROR = e
1418
1519from pylabrobot .resources .plate import Plate
1620
1721try :
1822 import numpy as np # type: ignore
1923
2024 USE_NUMPY = True
21- except ImportError :
25+ except ImportError as e :
2226 USE_NUMPY = False
27+ _NUMPY_IMPORT_ERROR = e
2328
2429try :
2530 import PySpin # type: ignore
2631
2732 # can be downloaded from https://www.teledynevisionsolutions.com/products/spinnaker-sdk/
2833 USE_PYSPIN = True
29- except ImportError :
34+ except ImportError as e :
3035 USE_PYSPIN = False
36+ _PYSPIN_IMPORT_ERROR = e
3137
3238from pylabrobot .io .ftdi import FTDI
3339from pylabrobot .plate_reading .backend import ImageReaderBackend
@@ -149,7 +155,10 @@ async def setup(self, use_cam: bool = False) -> None:
149155
150156 if use_cam :
151157 if not USE_PYSPIN :
152- raise RuntimeError ("PySpin is not installed. Please follow the imaging setup instructions." )
158+ raise RuntimeError (
159+ "PySpin is not installed. Please follow the imaging setup instructions. "
160+ f"Import error: { _PYSPIN_IMPORT_ERROR } "
161+ )
153162 if self .imaging_config is None :
154163 raise RuntimeError ("Imaging configuration is not set." )
155164
@@ -866,7 +875,10 @@ async def auto_focus(self, timeout: float = 30):
866875 raise RuntimeError ("Row and column not set. Run select() first." )
867876 if not USE_NUMPY :
868877 # This is strange, because Spinnaker requires numpy
869- raise RuntimeError ("numpy is not installed. See Cytation5 installation instructions." )
878+ raise RuntimeError (
879+ "numpy is not installed. See Cytation5 installation instructions. "
880+ f"Import error: { _NUMPY_IMPORT_ERROR } "
881+ )
870882
871883 # objective function: variance of laplacian
872884 async def evaluate_focus (focus_value ):
@@ -882,8 +894,10 @@ async def evaluate_focus(focus_value):
882894 )
883895 image = images [0 ] # self.capture returns List now
884896
885- if cv2 is None :
886- raise RuntimeError ("cv2 needs to be installed for auto focus" )
897+ if not CV2_AVAILABLE :
898+ raise RuntimeError (
899+ f"cv2 needs to be installed for auto focus. Import error: { _CV2_IMPORT_ERROR } "
900+ )
887901
888902 # NVMG: Normalized Variance of the Gradient Magnitude
889903 # Chat invented this i think
0 commit comments