Skip to content

Commit

Permalink
py-lints
Browse files Browse the repository at this point in the history
  • Loading branch information
zrezke committed Feb 27, 2024
1 parent 1740a1c commit b291e95
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
1 change: 0 additions & 1 deletion pipeline.json

This file was deleted.

15 changes: 8 additions & 7 deletions rerun_py/depthai_viewer/_backend/device.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import itertools
import os
import time
from queue import Empty as QueueEmpty
from queue import Queue
from typing import Dict, List, Optional, Tuple
import os

import depthai as dai
import numpy as np
Expand All @@ -15,7 +15,6 @@
)
from depthai_sdk.components.tof_component import Component
from numpy.typing import NDArray
from depthai_viewer.install_requirements import model_dir

import depthai_viewer as viewer
from depthai_viewer._backend.device_configuration import (
Expand All @@ -41,8 +40,9 @@
Message,
WarningMessage,
)
from depthai_viewer._backend.packet_handler import PacketHandler, PacketHandlerContext, DetectionContext
from depthai_viewer._backend.packet_handler import DetectionContext, PacketHandler, PacketHandlerContext
from depthai_viewer._backend.store import Store
from depthai_viewer.install_requirements import model_dir


class XlinkStatistics:
Expand Down Expand Up @@ -84,7 +84,7 @@ class Device:
_sys_info_q: Optional[Queue] = None # type: ignore[type-arg]
_pipeline_start_t: Optional[float] = None
_queues: List[Tuple[Component, ComponentOutput]] = []
_dai_queues: List[Tuple[dai.Node, Optional[PacketHandlerContext]]] = []
_dai_queues: List[Tuple[dai.Node, dai.DataOutputQueue, Optional[PacketHandlerContext]]] = []

# _profiler = cProfile.Profile()

Expand Down Expand Up @@ -274,8 +274,9 @@ def reconnect_to_oak(self) -> Message:

def _get_component_by_socket(self, socket: dai.CameraBoardSocket) -> Optional[CameraComponent]:
component = list(
filter(
lambda c: isinstance(c, CameraComponent) and c.node.getBoardSocket() == socket, self._oak._components
filter( # type: ignore[arg-type]
lambda c: isinstance(c, CameraComponent) and c.node.getBoardSocket() == socket,
self._oak._components if self._oak else [],
)
)
if not component:
Expand Down Expand Up @@ -386,7 +387,7 @@ def update_pipeline(self, runtime_only: bool) -> Message:
else:
self._create_auto_pipeline_config(config)

create_dai_queues_after_start: Dict[str, (dai.Node, Optional[PacketHandlerContext])] = {}
create_dai_queues_after_start: Dict[str, Tuple[dai.Node, Optional[PacketHandlerContext]]] = {}
self._stereo = None
self._packet_handler.reset()
self._sys_info_q = None
Expand Down
10 changes: 6 additions & 4 deletions rerun_py/depthai_viewer/_backend/device_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def to_runtime_controls(self) -> Dict[str, Any]:
"align": (
"RECTIFIED_LEFT"
if self.align == dai.CameraBoardSocket.LEFT
else "RECTIFIED_RIGHT" if self.align == dai.CameraBoardSocket.RIGHT else "CENTER"
else "RECTIFIED_RIGHT"
if self.align == dai.CameraBoardSocket.RIGHT
else "CENTER"
),
"lr_check": self.lr_check,
"lrc_check_threshold": self.lrc_threshold,
Expand Down Expand Up @@ -275,9 +277,9 @@ class DeviceProperties(BaseModel): # type: ignore[misc]
id: str
cameras: List[CameraFeatures] = []
imu: Optional[ImuKind]
stereo_pairs: List[Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket]] = (
[]
) # Which cameras can be paired for stereo
stereo_pairs: List[
Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket]
] = [] # Which cameras can be paired for stereo
default_stereo_pair: Optional[Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket]] = None
info: DeviceInfo = DeviceInfo()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import depthai as dai
from depthai_viewer._backend.device_configuration import (
AiModelConfiguration,
CameraConfiguration,
CameraSensorResolution,
PipelineConfiguration,
AiModelConfiguration,
)

config = PipelineConfiguration(
Expand Down
19 changes: 9 additions & 10 deletions rerun_py/depthai_viewer/_backend/packet_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from depthai_sdk.classes.packets import ( # PointcloudPacket,
BasePacket,
DepthPacket,
Detection,
DetectionPacket,
DisparityDepthPacket,
FramePacket,
Expand All @@ -17,16 +16,15 @@
from depthai_sdk.components import CameraComponent, Component, NNComponent, StereoComponent
from depthai_sdk.components.tof_component import ToFComponent
from numpy.typing import NDArray
from pydantic import BaseModel

import depthai_viewer as viewer
from depthai_viewer._backend.store import Store
from depthai_viewer._backend.topic import Topic
from depthai_viewer.components.rect2d import RectFormat
from pydantic import BaseModel


class PacketHandlerContext(BaseModel):

class PacketHandlerContext(BaseModel): # type: ignore[misc]
class Config:
arbitrary_types_allowed = True

Expand Down Expand Up @@ -64,7 +62,7 @@ def set_camera_intrinsics_getter(
# type: ignore[assignment, misc]
self._get_camera_intrinsics = camera_intrinsics_getter

def log_dai_packet(self, node: dai.Node, packet: dai.Buffer, context: PacketHandlerContext) -> None:
def log_dai_packet(self, node: dai.Node, packet: dai.Buffer, context: Optional[PacketHandlerContext]) -> None:
if isinstance(packet, dai.ImgFrame):
board_socket = None
if isinstance(node, dai.node.ColorCamera):
Expand All @@ -78,8 +76,9 @@ def log_dai_packet(self, node: dai.Node, packet: dai.Buffer, context: PacketHand
else:
print("Unknown node type:", type(node), "for packet:", type(packet))
elif isinstance(packet, dai.ImgDetections):
if not isinstance(context, DetectionContext):
if context is None or not isinstance(context, DetectionContext):
print("Invalid context for detections packet", context)
return
self._on_dai_detections(packet, context)
else:
print("Unknown dai packet type:", type(packet))
Expand Down Expand Up @@ -274,10 +273,10 @@ def _on_age_gender_packet(self, packet: TwoStagePacket, component: NNComponent)

def _rect_from_detection(self, detection: dai.ImgDetection, max_height: int, max_width: int) -> List[int]:
return [
max(min(detection.xmin, max_width), 0) * max_width,
max(min(detection.xmax, max_height), 0) * max_height,
max(min(detection.ymax, max_width), 0) * max_width,
max(min(detection.ymin, max_height), 0) * max_height,
int(max(min(detection.xmin, max_width), 0) * max_width),
int(max(min(detection.xmax, max_height), 0) * max_height),
int(max(min(detection.ymax, max_width), 0) * max_width),
int(max(min(detection.ymin, max_height), 0) * max_height),
]


Expand Down
1 change: 0 additions & 1 deletion rerun_py/depthai_viewer/install_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import subprocess
import sys
import traceback
from typing import Any, Dict
from pathlib import Path

# type: ignore[attr-defined]
Expand Down

0 comments on commit b291e95

Please sign in to comment.