Skip to content

Commit

Permalink
autoformatter compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
bbean23 committed Mar 29, 2024
1 parent 4ba9feb commit b720656
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
25 changes: 12 additions & 13 deletions opencsp/app/sofast/SofastGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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"""
Expand Down
35 changes: 17 additions & 18 deletions opencsp/app/sofast/SofastService.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]] = {
Expand Down Expand Up @@ -59,15 +59,15 @@ 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.
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.')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion opencsp/app/sofast/lib/SofastServiceCallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import opencsp.app.sofast.lib.SystemSofastFringe as ssf


class SofastServiceCallback():
class SofastServiceCallback:
def on_service_set(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion opencsp/app/sofast/lib/SystemSofastFringe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion opencsp/common/lib/tool/exception_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions opencsp/common/lib/tool/image_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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):
Expand Down

0 comments on commit b720656

Please sign in to comment.