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

Chore/release drafter #16

Merged
merged 2 commits into from
May 15, 2024
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
44 changes: 44 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name-template: 'v$RESOLVED_VERSION 🌈'

tag-template: 'v$RESOLVED_VERSION'

categories:
- title: '🚀 Features'
labels:
- 'rd/feature'

- title: '🐛 Bug Fixes'
labels:
- 'rd/fix'

- title: '🧰 Maintenance'
labels:
- 'rd/chore'

- title: '📄 Documentation'
labels:
- 'rd/docs'

change-template: '- $TITLE @$AUTHOR (#$NUMBER)'

change-title-escapes: '\<*_&'

version-resolver:
major:
labels:
- 'rd/major'

minor:
labels:
- 'rd/minor'

patch:
labels:
- 'rd/patch'

default: patch

template: |
## Changes

$CHANGES
26 changes: 26 additions & 0 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release Drafter

on:
push:
branches:
- main

workflow_dispatch:

permissions:
contents: read

jobs:
update_release_draft:
permissions:
contents: write
pull-requests: write

runs-on: ubuntu-latest

steps:
- uses: release-drafter/release-drafter@v6
with:
disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74 changes: 62 additions & 12 deletions src/pypcd4/pypcd4.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def build_dtype(self) -> np.dtype[np.void]:
field_names.append(field)
np_types.append(np_type)
else:
field_names.extend([f"{field}_{i:04d}" for i in range(count)])
field_names.extend([f"{field}__{i:04d}" for i in range(count)])
np_types.extend([np_type] * count)

return np.dtype([x for x in zip(field_names, np_types)])
Expand Down Expand Up @@ -616,7 +616,7 @@ def to_msg(self, header: Optional["Header"] = None) -> "PointCloud2":
fields = []
itemsize = 0
row_step = 0
for i, (field, type_, count) in enumerate(zip(self.fields, self.types, self.count)):
for i, (field, type_, count) in enumerate(zip(self.fields, self.types, self.counts)):
type_ = np.dtype(type_)

itemsize += type_.itemsize
Expand Down Expand Up @@ -693,11 +693,34 @@ def fields(self) -> Tuple[str, ...]:
Returns:
Tuple[str, ...]: Tuple of field names for each field

>>> pc.fields
Note:
If the field count is not 1, the field names will be suffixed with __0000, __0001, etc.
If you don't want this behavior, use the `pc.metadata.fields` instead.

>>> pc1.metadata.count
(1, 1, 1)

>>> pc1.fields
("x", "y", "z")

>>> pc2.metadata.count
(1, 1, 2)

>>> pc2.fields
("x", "y", "z__0000", "z__0001")

>>> pc2.metadata.fields
("x", "y", "z")
"""

return self.metadata.fields
fields = []
for field, count in zip(self.metadata.fields, self.metadata.count):
if count == 1:
fields.append(field)
else:
fields.extend(f"{field}__{c:04d}" for c in range(count))

return tuple(fields)

@property
def types(self) -> Tuple[npt.DTypeLike, ...]:
Expand All @@ -706,26 +729,53 @@ def types(self) -> Tuple[npt.DTypeLike, ...]:
Returns:
Tuple[npt.DTypeLike, ...]: Tuple of numpy types for each field

>>> pc.types
(np.float32, np.float32, np.float32)
Note:
If the field count is not 1, the type will be repeated for the number of fields

>>> pc1.metadata.count
(1, 1, 1)

>>> pc1.types
(np.float32, np.int32, np.float32)

>>> pc2.metadata.count
(1, 2, 1)

>>> pc2.types
(np.float32, np.int32, np.int32, np.float32)
"""

return tuple(
PCD_TYPE_TO_NUMPY_TYPE[ts] for ts in zip(self.metadata.type, self.metadata.size)
)
types = []
for ts, count in zip(zip(self.metadata.type, self.metadata.size), self.metadata.count):
if count == 1:
types.append(PCD_TYPE_TO_NUMPY_TYPE[ts])
else:
types.extend(PCD_TYPE_TO_NUMPY_TYPE[ts] for _ in range(count))

return tuple(types)

@property
def count(self) -> Tuple[PositiveInt, ...]:
def counts(self) -> Tuple[PositiveInt, ...]:
"""Returns number of elements in each field

Returns:
Tuple[PositiveInt, ...]: Tuple of number of elements in each field

>>> pc.counts
Note:
If the field count is not 1, the count will be repeated for the number of its counts
If you don't want this behavior, use the `pc.metadata.count` instead.

>>> pc1.metadata.count
(1, 1, 1)

>>> pc2.metadata.count
(1, 2, 1)

>>> pc2.counts
(1, 1, 1, 1)
"""

return self.metadata.count
return (1,) * sum(self.metadata.count)

@property
def points(self) -> int:
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ruff: noqa: ANN001, ANN201

from pathlib import Path

import pytest
Expand Down Expand Up @@ -296,6 +298,11 @@ def xyzrgb_ascii_with_empty_points_path():
def xyzintensity_ascii_organized_path():
return f"{Path(__file__).resolve().parent}/pcd/ascii_organized.pcd"


@pytest.fixture
def xyzintensity_ascii_multi_count_path():
return f"{Path(__file__).resolve().parent}/pcd/ascii_multi_count.pcd"

@pytest.fixture
def xyzrgb_binary_path():
return f"{Path(__file__).resolve().parent}/pcd/binary.pcd"
Expand Down
19 changes: 19 additions & 0 deletions tests/pcd/ascii_multi_count.pcd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# .PCD v.7 - Point Cloud Data file format
VERSION .7
FIELDS x y z intensity
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 4
WIDTH 8
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 8
DATA ascii
0.0 0.0 0.0 0.1 0.1 0.1 0.1
0.0 0.0 1.0 0.2 0.2 0.2 0.2
0.0 1.0 0.0 0.3 0.3 0.3 0.3
0.0 1.0 1.0 0.4 0.4 0.4 0.4
1.0 0.0 0.0 0.5 0.5 0.5 0.5
1.0 0.0 1.0 0.6 0.6 0.6 0.6
1.0 1.0 0.0 0.7 0.7 0.7 0.7
1.0 1.0 1.0 0.8 0.8 0.8 0.8
52 changes: 45 additions & 7 deletions tests/test/test_pypcd4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ruff: noqa: ANN001, ANN201

from io import BytesIO
from pathlib import Path
from tempfile import TemporaryDirectory
Expand Down Expand Up @@ -181,10 +183,10 @@ def test_build_dtype_with_multi_count_fields(pcd_header_with_multi_count_fields)
assert metadata.build_dtype() == [
("x", "<f4"),
("y", "<f4"),
("z_0000", "<f4"),
("z_0001", "<f4"),
("z_0002", "<f4"),
("z_0003", "<f4"),
("z__0000", "<f4"),
("z__0001", "<f4"),
("z__0002", "<f4"),
("z__0003", "<f4"),
]


Expand Down Expand Up @@ -278,14 +280,14 @@ def test_from_points():
array = np.array([[1, 2, 3], [4, 5, 6]])
fields = ("x", "y", "z")
types = (np.float32, np.float32, np.float32)
count = (1, 1, 1)
counts = (1, 1, 1)

pc = PointCloud.from_points(array, fields, types, count)
pc = PointCloud.from_points(array, fields, types, counts)

assert pc.fields == fields
assert pc.types == types
assert pc.points == 2
assert pc.count == count
assert pc.counts == counts
assert pc.pc_data.dtype.names == fields

assert np.array_equal(pc.pc_data["x"], array.T[0])
Expand Down Expand Up @@ -678,6 +680,42 @@ def test_numpy():
assert np.allclose(out_points, np.empty((0, 0)))


def test_numpy_with_multi_count_fields(xyzintensity_ascii_multi_count_path):
pc = PointCloud.from_path(xyzintensity_ascii_multi_count_path)

assert pc.fields == (
"x",
"y",
"z",
"intensity__0000",
"intensity__0001",
"intensity__0002",
"intensity__0003",
)
assert pc.metadata.fields == (
"x",
"y",
"z",
"intensity",
)
assert pc.types == (
np.float32,
np.float32,
np.float32,
np.float32,
np.float32,
np.float32,
np.float32,
)
assert pc.counts == (1, 1, 1, 1, 1, 1, 1)
assert pc.metadata.count == (1, 1, 1, 4)
assert pc.points == 8

points = pc.numpy()

assert points.shape == (8, 7)


def test_save_as_ascii():
in_points = np.random.randint(0, 1000, (100, 3))
fields = ("x", "y", "z")
Expand Down