added ruff code reivew
This commit is contained in:
+21
-19
@@ -7,23 +7,19 @@ and Helmholtz-Hodge decomposition.
|
||||
"""
|
||||
|
||||
# import os # only used by commented-out stitch_cal
|
||||
import numpy as np
|
||||
import cv2
|
||||
import time
|
||||
from enum import Enum, auto
|
||||
from pathlib import Path
|
||||
from typing import Optional, Tuple
|
||||
# from threading import Thread, Event
|
||||
# from queue import Queue, Empty
|
||||
|
||||
from .Stitcher import Stitcher
|
||||
from .tracker import Tracker
|
||||
from .hhd import nHHD
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
from . import calibration as cal_mod
|
||||
from . import configs
|
||||
from .get_depth import Contact3D
|
||||
from .backend_availability import (check_cupy_available, check_opencl_available)
|
||||
from . import configs
|
||||
from .backend_availability import check_cupy_available, check_opencl_available
|
||||
from .frame_processors import create_frame_processor
|
||||
from .get_depth import Contact3D
|
||||
from .hhd import nHHD
|
||||
from .signal_processing import (
|
||||
DEFAULT_SAMPLE_RATE_HZ,
|
||||
CausalMedianFilter,
|
||||
@@ -31,6 +27,11 @@ from .signal_processing import (
|
||||
SampleRateEstimator,
|
||||
)
|
||||
|
||||
# from threading import Thread, Event
|
||||
# from queue import Queue, Empty
|
||||
from .Stitcher import Stitcher
|
||||
from .tracker import Tracker
|
||||
|
||||
# Default signal-conditioning settings (config: top-level "filters" block).
|
||||
#
|
||||
# A key a config does not state is **off**, not "whatever we thought was
|
||||
@@ -101,6 +102,7 @@ from .capture import (
|
||||
open_capture,
|
||||
)
|
||||
|
||||
|
||||
class Sensor:
|
||||
"""
|
||||
Optical tactile sensor interface with deformation analysis.
|
||||
@@ -137,7 +139,7 @@ class Sensor:
|
||||
|
||||
def __init__(self, vid_src, cuda=True, isstitch=True, verbose=True, debug=False,
|
||||
config_name="prototype", cal_path=None, override=False, box=None, mirror=True,
|
||||
backend='auto', capture_config: Optional[CaptureConfig] = None,
|
||||
backend='auto', capture_config: CaptureConfig | None = None,
|
||||
auto_reconnect: bool = False, capture_mode: str = "latest",
|
||||
capture_queue_size: int = 1, capture_overflow: str = "drop_oldest",
|
||||
**_deprecated_capture_kwargs):
|
||||
@@ -215,11 +217,11 @@ class Sensor:
|
||||
self.n_boxes = None
|
||||
self.fnormal = self.fshearx = self.fsheary = self.ftor = 0.0
|
||||
self._force_raw = (0.0, 0.0, 0.0)
|
||||
self.calibration: Optional[cal_mod.Calibration] = None
|
||||
self._force_cal_sensor_name: Optional[str] = None
|
||||
self.calibration: cal_mod.Calibration | None = None
|
||||
self._force_cal_sensor_name: str | None = None
|
||||
#: Why no calibration was applied, when a bundle existed but carried no
|
||||
#: usable coefficients. ``None`` means the question never came up.
|
||||
self._force_cal_attempts: Optional[list[dict]] = None
|
||||
self._force_cal_attempts: list[dict] | None = None
|
||||
self._init_force_calibration()
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
@@ -413,7 +415,7 @@ class Sensor:
|
||||
# self._av_stream = None
|
||||
# self._av_decoder = None
|
||||
self.cap = None # compat alias for _capture_worker.source.cap
|
||||
self._capture_source: Optional[CaptureSource] = None
|
||||
self._capture_source: CaptureSource | None = None
|
||||
self._is_live_camera = (
|
||||
is_live_camera(self.vid_src) and not self._external_only
|
||||
)
|
||||
@@ -1013,7 +1015,7 @@ class Sensor:
|
||||
return result
|
||||
|
||||
|
||||
def read_info(self, *args) -> Tuple:
|
||||
def read_info(self, *args) -> tuple:
|
||||
"""
|
||||
Get sensor data by info type.
|
||||
|
||||
@@ -1323,7 +1325,7 @@ class Sensor:
|
||||
return
|
||||
try:
|
||||
attempts.append(configs.describe_bundle_resolution(name))
|
||||
except Exception: # noqa: BLE001 - diagnostics must never break loading
|
||||
except Exception: # noqa: BLE001, S112 - diagnostics must never break loading
|
||||
continue
|
||||
# Deliberately NOT setting ``_force_cal_sensor_name``: callers read a
|
||||
# non-None value there as "this sensor is calibrated", and a bundle
|
||||
@@ -1700,6 +1702,6 @@ class Sensor:
|
||||
for k, v in timings.items():
|
||||
if k != 'total':
|
||||
print(f" {k}: {v:7.2f} ms")
|
||||
print(f" ─────────────────────────")
|
||||
print(" ─────────────────────────")
|
||||
print(f" TOTAL: {timings['total']:7.2f} ms ({1000/timings['total']:.1f} FPS)")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user