Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up component imports #985

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ lint: toml-lint py-lint

### Python

py_folders := "rerun_py examples"

# Set up a Pythonvirtual environment for development
py-dev-env:
#!/usr/bin/env bash
Expand All @@ -41,18 +43,18 @@ py-build:

# Run autoformatting
py-format:
black --config rerun_py/pyproject.toml .
blackdoc .
isort .
black --config rerun_py/pyproject.toml {{py_folders}}
blackdoc {{py_folders}}
isort {{py_folders}}
pyupgrade --py37-plus `find rerun_py/rerun/ -name "*.py" -type f`

# Run linting
py-lint:
black --check --config rerun_py/pyproject.toml --diff .
blackdoc --check .
isort --check .
black --check --config rerun_py/pyproject.toml --diff {{py_folders}}
blackdoc --check {{py_folders}}
isort --check {{py_folders}}
mypy --no-warn-unused-ignore
flake8
flake8 {{py_folders}}

# Run fast unittests
py-test:
Expand Down
26 changes: 25 additions & 1 deletion rerun_py/rerun/components/rect2d.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
from __future__ import annotations

from enum import Enum

import numpy as np
import numpy.typing as npt
import pyarrow as pa
from rerun.components import REGISTERED_FIELDS, ComponentTypeFactory, build_dense_union
from rerun.log.rects import RectFormat

__all__ = [
"Rect2DArray",
"Rect2DType",
"RectFormat",
]


class RectFormat(Enum):
"""How to specify rectangles (axis-aligned bounding boxes)."""

XYWH = "XYWH"
"""[x,y,w,h], with x,y = left,top."""

YXHW = "YXHW"
"""[y,x,h,w], with x,y = left,top."""

XYXY = "XYXY"
"""[x0, y0, x1, y1], with x0,y0 = left,top and x1,y1 = right,bottom."""

YXYX = "YXYX"
"""[y0, x0, y1, x1], with x0,y0 = left,top and x1,y1 = right,bottom."""

XCYCWH = "XCYCWH"
"""[x_center, y_center, width, height]."""

XCYCW2H2 = "XCYCW2H2"
"""[x_center, y_center, width/2, height/2]."""


class Rect2DArray(pa.ExtensionArray): # type: ignore[misc]
def from_numpy_and_format(array: npt.NDArray[np.float_], rect_format: RectFormat) -> Rect2DArray:
"""Build a `Rect2DArray` from an Nx4 numpy array."""
Expand Down
9 changes: 4 additions & 5 deletions rerun_py/rerun/log/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import numpy as np
import numpy.typing as npt
from rerun.components.arrow import Arrow3DArray
from rerun.components.color import ColorRGBAArray
from rerun.components.label import LabelArray
from rerun.components.radius import RadiusArray
from rerun.log import _normalize_colors, _normalize_radii

from rerun import bindings
Expand Down Expand Up @@ -48,11 +52,6 @@ def log_arrow(
Object is not time-dependent, and will be visible at any time point.

"""
from rerun.components.arrow import Arrow3DArray
from rerun.components.color import ColorRGBAArray
from rerun.components.label import LabelArray
from rerun.components.radius import RadiusArray

comps = {}

if origin is not None:
Expand Down
15 changes: 7 additions & 8 deletions rerun_py/rerun/log/bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

import numpy as np
import numpy.typing as npt
from rerun.components.annotation import ClassIdArray
from rerun.components.box import Box3DArray
from rerun.components.color import ColorRGBAArray
from rerun.components.label import LabelArray
from rerun.components.quaternion import QuaternionArray
from rerun.components.radius import RadiusArray
from rerun.components.vec import Vec3DArray
from rerun.log import _normalize_colors, _normalize_ids, _normalize_radii

from rerun import bindings
Expand Down Expand Up @@ -34,14 +41,6 @@ def log_obb(
`class_id`: Optional class id for the OBB.
The class id provides colors and labels if not specified explicitly.
"""
from rerun.components.annotation import ClassIdArray
from rerun.components.box import Box3DArray
from rerun.components.color import ColorRGBAArray
from rerun.components.label import LabelArray
from rerun.components.quaternion import QuaternionArray
from rerun.components.radius import RadiusArray
from rerun.components.vec import Vec3DArray

comps = {}

if half_size is not None:
Expand Down
13 changes: 4 additions & 9 deletions rerun_py/rerun/log/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import numpy as np
import numpy.typing as npt
from rerun.components.color import ColorRGBAArray
from rerun.components.instance import InstanceArray
from rerun.components.linestrip import LineStrip2DArray, LineStrip3DArray
from rerun.components.radius import RadiusArray
from rerun.log import _normalize_colors, _normalize_radii

from rerun import bindings
Expand Down Expand Up @@ -39,10 +43,6 @@ def log_path(
if positions is not None:
positions = np.require(positions, dtype="float32")

from rerun.components.color import ColorRGBAArray
from rerun.components.linestrip import LineStrip3DArray
from rerun.components.radius import RadiusArray

comps = {}

if positions is not None:
Expand Down Expand Up @@ -86,11 +86,6 @@ def log_line_segments(
positions = np.require([], dtype="float32")
positions = np.require(positions, dtype="float32")

from rerun.components.color import ColorRGBAArray
from rerun.components.instance import InstanceArray
from rerun.components.linestrip import LineStrip2DArray, LineStrip3DArray
from rerun.components.radius import RadiusArray

# 0 = instanced, 1 = splat
comps = [{}, {}] # type: ignore[var-annotated]

Expand Down
16 changes: 5 additions & 11 deletions rerun_py/rerun/log/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import numpy as np
import numpy.typing as npt
from rerun.components.annotation import ClassIdArray
from rerun.components.color import ColorRGBAArray
from rerun.components.instance import InstanceArray
from rerun.components.label import LabelArray
from rerun.components.point import Point2DArray, Point3DArray
from rerun.components.radius import RadiusArray
from rerun.log import (
Color,
Expand Down Expand Up @@ -64,11 +69,6 @@ def log_point(
if position is not None:
position = np.require(position, dtype="float32")

from rerun.components.annotation import ClassIdArray
from rerun.components.color import ColorRGBAArray
from rerun.components.label import LabelArray
from rerun.components.point import Point2DArray, Point3DArray

comps = {}

if position is not None:
Expand Down Expand Up @@ -149,12 +149,6 @@ def log_points(
class_ids = _normalize_ids(class_ids)
keypoint_ids = _normalize_ids(keypoint_ids)

from rerun.components.annotation import ClassIdArray
from rerun.components.color import ColorRGBAArray
from rerun.components.instance import InstanceArray
from rerun.components.label import LabelArray
from rerun.components.point import Point2DArray, Point3DArray

identifiers_np = np.array((), dtype="int64")
if identifiers:
try:
Expand Down
38 changes: 5 additions & 33 deletions rerun_py/rerun/log/rects.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from enum import Enum
from typing import Optional, Sequence, Union

import numpy as np
import numpy.typing as npt
from rerun.components.annotation import ClassIdArray
from rerun.components.color import ColorRGBAArray
from rerun.components.instance import InstanceArray
from rerun.components.label import LabelArray
from rerun.components.rect2d import Rect2DArray, RectFormat
from rerun.log import (
Color,
Colors,
Expand All @@ -22,27 +26,6 @@
]


# """ How to specify rectangles (axis-aligned bounding boxes). """
class RectFormat(Enum):
# """ [x,y,w,h], with x,y = left,top. """"
XYWH = "XYWH"

# """ [y,x,h,w], with x,y = left,top. """"
YXHW = "YXHW"

# """ [x0, y0, x1, y1], with x0,y0 = left,top and x1,y1 = right,bottom """"
XYXY = "XYXY"

# """ [y0, x0, y1, x1], with x0,y0 = left,top and x1,y1 = right,bottom """"
YXYX = "YXYX"

# """ [x_center, y_center, width, height]"
XCYCWH = "XCYCWH"

# """ [x_center, y_center, width/2, height/2]"
XCYCW2H2 = "XCYCW2H2"


def log_rect(
obj_path: str,
rect: Optional[npt.ArrayLike],
Expand All @@ -64,11 +47,6 @@ def log_rect(
* `class_id`: Optional class id for the rectangle.
The class id provides color and label if not specified explicitly.
"""
from rerun.components.annotation import ClassIdArray
from rerun.components.color import ColorRGBAArray
from rerun.components.label import LabelArray
from rerun.components.rect2d import Rect2DArray

if np.any(rect): # type: ignore[arg-type]
rects = np.asarray([rect], dtype="float32")
else:
Expand Down Expand Up @@ -137,12 +115,6 @@ def log_rects(
class_ids = _normalize_ids(class_ids)
labels = _normalize_labels(labels)

from rerun.components.annotation import ClassIdArray
from rerun.components.color import ColorRGBAArray
from rerun.components.instance import InstanceArray
from rerun.components.label import LabelArray
from rerun.components.rect2d import Rect2DArray

identifiers_np = np.array((), dtype="int64")
if identifiers:
try:
Expand Down
9 changes: 4 additions & 5 deletions rerun_py/rerun/log/scalar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Optional, Sequence

import numpy as np
from rerun.components.color import ColorRGBAArray
from rerun.components.label import LabelArray
from rerun.components.radius import RadiusArray
from rerun.components.scalar import ScalarArray, ScalarPlotPropsArray
from rerun.log import _normalize_colors

from rerun import bindings
Expand Down Expand Up @@ -100,11 +104,6 @@ def log_scalar(
Points within a single line do not have to all share the same scatteredness: the line will
switch between a scattered and a continous representation as required.
"""
from rerun.components.color import ColorRGBAArray
from rerun.components.label import LabelArray
from rerun.components.radius import RadiusArray
from rerun.components.scalar import ScalarArray, ScalarPlotPropsArray

comps = {"rerun.scalar": ScalarArray.from_numpy(np.array([scalar]))}

if label:
Expand Down
3 changes: 1 addition & 2 deletions rerun_py/rerun/log/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
import numpy.typing as npt
from rerun.components.tensor import TensorArray
from rerun.log.error_utils import _send_warning

from rerun import bindings
Expand Down Expand Up @@ -88,8 +89,6 @@ def _log_tensor(
_send_warning(f"Unsupported dtype: {tensor.dtype}. Expected a numeric type. Skipping this tensor.", 2)
return

from rerun.components.tensor import TensorArray

comps = {"rerun.tensor": TensorArray.from_numpy(tensor, names, meaning, meter)}

bindings.log_arrow_msg(obj_path, components=comps, timeless=timeless)
5 changes: 2 additions & 3 deletions rerun_py/rerun/log/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from dataclasses import dataclass
from typing import Final, Optional, Sequence

from rerun.components.color import ColorRGBAArray
from rerun.components.text_entry import TextEntryArray
from rerun.log import _normalize_colors

from rerun import bindings
Expand Down Expand Up @@ -93,9 +95,6 @@ def log_text_entry(
* If no `level` is given, it will default to `LogLevel.INFO`.
* `color` is optional RGB or RGBA triplet in 0-255 sRGB.
"""
from rerun.components.color import ColorRGBAArray
from rerun.components.text_entry import TextEntryArray

comps = {}
if text:
comps["rerun.text_entry"] = TextEntryArray.from_bodies_and_levels([(text, level)])
Expand Down