From b7206569f36777e65745ee872fd6669af9b355b6 Mon Sep 17 00:00:00 2001 From: bbean Date: Fri, 29 Mar 2024 12:47:50 -0600 Subject: [PATCH] autoformatter compliance --- opencsp/app/sofast/SofastGUI.py | 25 +++++++------ opencsp/app/sofast/SofastService.py | 35 +++++++++---------- .../app/sofast/lib/SofastServiceCallback.py | 2 +- opencsp/app/sofast/lib/SystemSofastFringe.py | 2 +- opencsp/common/lib/tool/exception_tools.py | 2 +- opencsp/common/lib/tool/image_tools.py | 3 ++ 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/opencsp/app/sofast/SofastGUI.py b/opencsp/app/sofast/SofastGUI.py index 007ce9094..e67cde4b0 100644 --- a/opencsp/app/sofast/SofastGUI.py +++ b/opencsp/app/sofast/SofastGUI.py @@ -285,12 +285,8 @@ def _create_layout(self) -> None: r = 0 # Camera type dropdown self.var_cam_select = tkinter.StringVar(value=list(self.cam_options.keys())[0]) - lbl_camera_type = tkinter.Label( - label_frame_settings, text='Select camera:', font=('calibre', 10, 'bold') - ) - drop_camera_type = tkinter.OptionMenu( - label_frame_settings, self.var_cam_select, *list(self.cam_options.keys()) - ) + lbl_camera_type = tkinter.Label(label_frame_settings, text='Select camera:', font=('calibre', 10, 'bold')) + drop_camera_type = tkinter.OptionMenu(label_frame_settings, self.var_cam_select, *list(self.cam_options.keys())) TkToolTip(drop_camera_type, 'Select type of camera object to load.') lbl_camera_type.grid(row=r, column=1, pady=2, padx=2, sticky='nse') @@ -302,8 +298,9 @@ def _create_layout(self) -> None: lbl_cal_type = tkinter.Label( label_frame_settings, text='Select calibration method:', font=('calibre', 10, 'bold') ) - drop_cal_type = tkinter.OptionMenu(label_frame_settings, self.var_cal_select, - *list(SofastService.cal_options.keys())) + drop_cal_type = tkinter.OptionMenu( + label_frame_settings, self.var_cal_select, *list(SofastService.cal_options.keys()) + ) TkToolTip(drop_cal_type, 'Select type of Projector-Camera Brightness Calibration process to use.') lbl_cal_type.grid(row=r, column=1, pady=2, padx=2, sticky='nse') @@ -610,11 +607,13 @@ def on_processed(): print(f'Calibration complete. Results loaded and saved to\n {file}') # Run calibration - self.service.run_gray_levels_cal(calibration_class=cal_type, - calibration_hdf5_path_name_ext=file, - on_calibrating=on_calibrating, - on_processing=on_processing, - on_processed=on_processed) + self.service.run_gray_levels_cal( + calibration_class=cal_type, + calibration_hdf5_path_name_ext=file, + on_calibrating=on_calibrating, + on_processing=on_processing, + on_processed=on_processed, + ) def load_gray_levels_cal(self) -> None: """Loads saved results of a projector-camera intensity calibration""" diff --git a/opencsp/app/sofast/SofastService.py b/opencsp/app/sofast/SofastService.py index 6e902189e..a3c972e14 100644 --- a/opencsp/app/sofast/SofastService.py +++ b/opencsp/app/sofast/SofastService.py @@ -9,9 +9,9 @@ from opencsp.app.sofast.lib.Fringes import Fringes from opencsp.common.lib.camera.ImageAcquisitionAbstract import ImageAcquisitionAbstract -from opencsp.common.lib.camera.ImageAcquisition_DCAM_mono import (ImageAcquisition as ImageAcquisition_DCAM) -from opencsp.common.lib.camera.ImageAcquisition_DCAM_color import (ImageAcquisition as ImageAcquisition_DCAM_color) -from opencsp.common.lib.camera.ImageAcquisition_MSMF import (ImageAcquisition as ImageAcquisition_MSMF) +from opencsp.common.lib.camera.ImageAcquisition_DCAM_mono import ImageAcquisition as ImageAcquisition_DCAM +from opencsp.common.lib.camera.ImageAcquisition_DCAM_color import ImageAcquisition as ImageAcquisition_DCAM_color +from opencsp.common.lib.camera.ImageAcquisition_MSMF import ImageAcquisition as ImageAcquisition_MSMF from opencsp.app.sofast.lib.ImageCalibrationAbstract import ImageCalibrationAbstract from opencsp.app.sofast.lib.ImageCalibrationGlobal import ImageCalibrationGlobal from opencsp.app.sofast.lib.ImageCalibrationScaling import ImageCalibrationScaling @@ -23,7 +23,7 @@ import opencsp.common.lib.tool.log_tools as lt -class SofastService(): +class SofastService: """Class that interfaces with SOFAST to run data acquisition and process results""" cam_options: dict[str, type[ImageAcquisitionAbstract]] = { @@ -59,7 +59,7 @@ def __del__(self): @property def system(self) -> SystemSofastFringe: - """ Get the sofast system object. + """Get the sofast system object. Checks if the system object has been instantiated, or if the system object can be instantiated. @@ -67,7 +67,7 @@ def system(self) -> SystemSofastFringe: Raises: ------- RuntimeError: - If the system instance hasn't been and can't be instantiated yet """ + If the system instance hasn't been and can't be instantiated yet""" if self._system is None: if not self._load_system_elements(): lt.error_and_raise(RuntimeError, 'Both ImageAcquisiton and ImageProjection must both be loaded.') @@ -155,7 +155,7 @@ def get_frame(self) -> np.ndarray: return frame def _load_system_elements(self) -> bool: - """ Loads the system instance, as appropriate. + """Loads the system instance, as appropriate. Checks if System object can be instantiated (if both ImageAcquisition and ImageProjection classes are loaded) @@ -191,19 +191,19 @@ def run_exposure_cal(self) -> None: run_next = self.image_projection.show_crosshairs self.system.run_camera_exposure_calibration(run_next) - def run_gray_levels_cal(self, - calibration_class: type[ImageCalibrationAbstract], - calibration_hdf5_path_name_ext: str = None, - on_captured: Callable = None, - on_processing: Callable = None, - on_processed: Callable = None) -> None: + def run_gray_levels_cal( + self, + calibration_class: type[ImageCalibrationAbstract], + calibration_hdf5_path_name_ext: str = None, + on_captured: Callable = None, + on_processing: Callable = None, + on_processed: Callable = None, + ) -> None: """Runs the projector-camera intensity calibration""" # Capture images def _func_0(): - self.system.run_display_camera_response_calibration( - res=10, run_next=self.system.run_next_in_queue - ) + self.system.run_display_camera_response_calibration(res=10, run_next=self.system.run_next_in_queue) # Run the "on captured" callback if on_captured != None: @@ -241,8 +241,7 @@ def _func_1(): def load_gray_levels_cal(self, hdf5_file_path_name_ext: str) -> None: """Loads saved results of a projector-camera intensity calibration""" # Load file - cal_type = h5.load_hdf5_datasets(['Calibration/calibration_type'], - hdf5_file_path_name_ext)['calibration_type'] + cal_type = h5.load_hdf5_datasets(['Calibration/calibration_type'], hdf5_file_path_name_ext)['calibration_type'] if cal_type == 'ImageCalibrationGlobal': self.calibration = ImageCalibrationGlobal.load_from_hdf(hdf5_file_path_name_ext) diff --git a/opencsp/app/sofast/lib/SofastServiceCallback.py b/opencsp/app/sofast/lib/SofastServiceCallback.py index e9cad709f..0a0be05ae 100644 --- a/opencsp/app/sofast/lib/SofastServiceCallback.py +++ b/opencsp/app/sofast/lib/SofastServiceCallback.py @@ -4,7 +4,7 @@ import opencsp.app.sofast.lib.SystemSofastFringe as ssf -class SofastServiceCallback(): +class SofastServiceCallback: def on_service_set(self): pass diff --git a/opencsp/app/sofast/lib/SystemSofastFringe.py b/opencsp/app/sofast/lib/SystemSofastFringe.py index 0ff781085..f702ddd15 100644 --- a/opencsp/app/sofast/lib/SystemSofastFringe.py +++ b/opencsp/app/sofast/lib/SystemSofastFringe.py @@ -209,7 +209,7 @@ def load_fringes(self, fringes: Fringes, min_display_value: int) -> None: self.fringe_images_to_display = [] for idx in range(fringe_images_base.shape[2]): # Create image - self.fringe_images_to_display.append(np.concatenate([fringe_images_base[:, :, idx: idx + 1]] * 3, axis=2)) + self.fringe_images_to_display.append(np.concatenate([fringe_images_base[:, :, idx : idx + 1]] * 3, axis=2)) def check_saturation(self, image: ndarray, camera_max_int: int, thresh: float = 0.005) -> None: """ diff --git a/opencsp/common/lib/tool/exception_tools.py b/opencsp/common/lib/tool/exception_tools.py index 5c3d2fad1..b78c04a69 100644 --- a/opencsp/common/lib/tool/exception_tools.py +++ b/opencsp/common/lib/tool/exception_tools.py @@ -3,7 +3,7 @@ @contextmanager def ignored(*exceptions): - """ Easy wrapper to ignore specific kinds of exceptions. + """Easy wrapper to ignore specific kinds of exceptions. From https://stackoverflow.com/questions/15572288/general-decorator-to-wrap-try-except-in-python diff --git a/opencsp/common/lib/tool/image_tools.py b/opencsp/common/lib/tool/image_tools.py index 712d02896..23faa2e0e 100644 --- a/opencsp/common/lib/tool/image_tools.py +++ b/opencsp/common/lib/tool/image_tools.py @@ -10,6 +10,8 @@ import opencsp.common.lib.tool.log_tools as lt +# disable auto formatting +# fmt: off # from https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html pil_image_formats_rw = ["blp", "bmp", "dds", "dib", "eps", "gif", "icns", "ico", "im", "jpg", "jpeg", "msp", "pcx", "png", "apng", "pbm", "pgm", "ppm", "pnm", "sgi", "spider", "tga", "tiff", "webp", "xbm"] @@ -19,6 +21,7 @@ """ A list of all image image formats that can be read by the Python Imaging Library (PIL). Note that not all of these formats can be written by PIL. """ pil_image_formats_writable = pil_image_formats_rw + ["palm", "pdf", "xv"] """ A list of all image image formats that can be written by the Python Imaging Library (PIL). Note that not all of these formats can be ready by PIL. """ +# fmt: on def numpy_to_image(arr: np.ndarray, rescale_or_clip='rescale', rescale_max=-1):