{"id":29021653,"url":"https://github.com/mapiv/pypcd4","last_synced_at":"2026-01-07T12:13:12.591Z","repository":{"id":191983516,"uuid":"685784176","full_name":"MapIV/pypcd4","owner":"MapIV","description":"Read and write PCL .pcd files in python","archived":false,"fork":false,"pushed_at":"2025-06-20T08:31:50.000Z","size":109,"stargazers_count":96,"open_issues_count":3,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-20T09:36:24.210Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MapIV.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-01T02:10:59.000Z","updated_at":"2025-06-20T07:41:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"b6e79e2d-99fe-41f4-b723-60d2a8500735","html_url":"https://github.com/MapIV/pypcd4","commit_stats":null,"previous_names":["mapiv/pypcd4"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/MapIV/pypcd4","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2Fpypcd4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2Fpypcd4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2Fpypcd4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2Fpypcd4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MapIV","download_url":"https://codeload.github.com/MapIV/pypcd4/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MapIV%2Fpypcd4/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261984643,"owners_count":23240304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-26T02:07:25.731Z","updated_at":"2025-12-16T02:56:51.441Z","avatar_url":"https://github.com/MapIV.png","language":"Python","readme":"# pypcd4\n\n[![Test](https://github.com/MapIV/pypcd4/actions/workflows/test.yaml/badge.svg)](https://github.com/MapIV/pypcd4/actions/workflows/test.yaml)\n![PyPI - Version](https://img.shields.io/pypi/v/pypcd4)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pypcd4)\n![GitHub License](https://img.shields.io/github/license/MapIV/pypcd4)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pypcd4)\n\n## Table of Contents\n\n- [pypcd4](#pypcd4)\n  - [Table of Contents](#table-of-contents)\n  - [Description](#description)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Getting Started](#getting-started)\n    - [Working with .pcd Files](#working-with-pcd-files)\n    - [Converting Between PointCloud and NumPy Array](#converting-between-pointcloud-and-numpy-array)\n      - [Creating Custom Conversion Methods](#creating-custom-conversion-methods)\n    - [Working with ROS PointCloud2 Messages](#working-with-ros-pointcloud2-messages)\n    - [Concatenating PointClouds](#concatenating-pointclouds)\n    - [Filtering a PointCloud](#filtering-a-pointcloud)\n      - [Using a Slice](#using-a-slice)\n      - [Using a Boolean Mask](#using-a-boolean-mask)\n      - [Using Field Names](#using-field-names)\n    - [Saving Your Work](#saving-your-work)\n  - [Contributing](#contributing)\n    - [Using Rye (Recommended)](#using-rye-recommended)\n    - [Using pip](#using-pip)\n  - [License](#license)\n\n## Description\n\npypcd4 is a modern reimagining of the original [pypcd](https://github.com/dimatura/pypcd) library,\noffering enhanced capabilities and performance for working with Point Cloud Data (PCD) files.\n\nThis library builds upon the foundation laid by the original pypcd while incorporating modern\nPython3 syntax and methodologies to provide a more efficient and user-friendly experience.\n\n## Installation\n\nTo get started with `pypcd4`, install it using pip:\n\n```shell\npip install pypcd4\n```\n\n## Usage\n\nLet’s walk through some examples of how you can use pypcd4:\n\n### Getting Started\n\nFirst, import the PointCloud class from pypcd4:\n\n```python\nfrom pypcd4 import PointCloud\n```\n\n### Working with .pcd Files\n\nIf you have a .pcd file, you can read it into a PointCloud object:\n\n```python\npc: PointCloud = PointCloud.from_path(\"point_cloud.pcd\")\n\npc.fields\n# ('x', 'y', 'z', 'intensity')\n```\n\n### Converting Between PointCloud and NumPy Array\n\nYou can convert a PointCloud to a NumPy array:\n\n```python\narray: np.ndarray = pc.numpy()\n\narray.shape\n# (1000, 4)\n```\n\nYou can also specify the fields you want to include in the conversion:\n\n```python\narray: np.ndarray = pc.numpy((\"x\", \"y\", \"z\"))\n\narray.shape\n# (1000, 3)\n```\n\nAnd you can convert a NumPy array back to a PointCloud.\nThe method you use depends on the fields in your array:\n\n```python\n# If the array has x, y, z, and intensity fields,\npc = PointCloud.from_xyzi_points(array)\n\n# Or if the array has x, y, z, and label fields,\npc = PointCloud.from_xyzl_points(array, label_type=np.uint32)\n```\n\n#### Creating Custom Conversion Methods\n\nIf you can’t find your preferred point type in the pre-defined conversion methods,\nyou can create your own:\n\n```python\nfields = (\"x\", \"y\", \"z\", \"intensity\", \"new_field\")\ntypes = (np.float32, np.float32, np.float32, np.float32, np.float64)\n\npc = PointCloud.from_points(array, fields, types)\n```\n\n### Working with ROS PointCloud2 Messages\n\nYou can convert a ROS PointCloud2 Message to a PointCloud and vice versa. This requires ROS installed and sourced, or [rosbags](https://ternaris.gitlab.io/rosbags/index.html) to be installed. To publish the converted message, ROS is required:\n\n```python\ndef callback(in_msg: sensor_msgs.msg.PointCloud2):\n    # Convert ROS PointCloud2 Message to a PointCloud\n    pc = PointCloud.from_msg(in_msg)\n\n    pc.fields\n    # (\"x\", \"y\", \"z\", \"intensity\", \"ring\", \"time\")\n\n    # Convert PointCloud to ROS PointCloud2 Message with the input message header\n    out_msg = pc.to_msg(in_msg.header)\n\n    # Publish using ROS (or e.g. write to a rosbag)\n    publisher.publish(out_msg)\n```\n\n### Concatenating PointClouds\n\nThe `pypcd4` supports concatenating `PointCloud` objects together using the `+` operator.\nThis can be useful when you want to merge two point clouds into one.\n\nHere's how you can use it:\n\n```python\npc1: PointCloud = PointCloud.from_path(\"xyzi1.pcd\")\npc2: PointCloud = PointCloud.from_path(\"xyzi2.pcd\")\n\n# Concatenate two PointClouds\npc3: PointCloud = pc1 + pc2\n```\n\nConcatenating many PointClouds in sequence can become slow, especially for large point counts. Using `PointCloud.from_list()` will be faster for those use cases:\n\n```python\npc_list = []\nfor i in range(10):\n    pc_list.append(PointCloud.from_path(f\"xyzi{i}.pcd\"))\n\npc: PointCloud = PointCloud.from_list(pc_list)\n```\n\nPlease note that to concatenate PointCloud objects, they must have the exact same fields and types. If they don’t, a `ValueError` will be raised.\n\n### Filtering a PointCloud\n\nThe `pypcd4` library provides a convenient way to filter a `PointCloud` using a subscript.\n\n#### Using a Slice\n\nYou can use a slice to access a range of points in the point cloud. Here’s an example:\n\n```python\n# Create a point cloud with random points\npc = PointCloud.from_xyz_points(np.random.rand(10, 3))\n\n# Access points using a slice\nsubset = pc[3:8]\n```\n\nIn this case, subset will be a new PointCloud object containing only the points from index 3 to 7.\n\n#### Using a Boolean Mask\n\nYou can use a boolean mask to access points that satisfy certain conditions. Here’s an example:\n\n```python\n# Create a point cloud with random points\npc = PointCloud.from_xyz_points(np.random.rand(10000, 3))\n\n# Create a boolean mask\nmask = (pc.pc_data[\"x\"] \u003e 0.5) \u0026 (pc.pc_data[\"y\"] \u003c 0.5)\n\n# Access points using the mask\nsubset = pc[mask]\n```\n\nIn this case, subset will be a new PointCloud object containing only the points where the x-coordinate is greater than 0.5 and the y-coordinate is less than 0.5.\n\n#### Using Field Names\n\nYou can use a field name or a sequence of field names to access specific fields in the point cloud. Here’s an example:\n\n```python\n# Create a point cloud with random points\npc = PointCloud.from_xyz_points(np.random.rand(100, 3))\n\n# Access specific fields\nsubset = pc[(\"x\", \"y\")]\n```\n\nIn this case, subset will be a new PointCloud object containing only the x and y coordinates of the points.\nThe z-coordinate will not be included.\n\n### Saving Your Work\n\nFinally, you can save your PointCloud as a .pcd file:\n\n```python\npc.save(\"nice_point_cloud.pcd\")\n```\n\n## Contributing\n\nWe are always looking for contributors. If you are interested in contributing,\nplease run the lint and test before submitting a pull request:\n\n### Using Rye (Recommended)\n\nJust run the following command:\n\n```bash\nrye sync\nrye run lint\n```\n\n### Using pip\n\nInstall the testing dependencies by the following command:\n\n```bash\npip install mypy pytest ruff\n```\n\nThen run the following command:\n\n```bash\nruff check --fix src\nruff format src\nmypy src\npytest\n```\n\nMake sure all lints and tests pass before submitting a pull request.\n\n## License\n\nThe library was rewritten and does not borrow any code from the original [pypcd](https://github.com/dimatura/pypcd) library.\nSince it was heavily inspired by the original author's work, we extend his original BSD 3-Clause License and include his Copyright notice.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapiv%2Fpypcd4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmapiv%2Fpypcd4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmapiv%2Fpypcd4/lists"}