### Install plyfile from source Source: https://github.com/dranjan/python-plyfile/blob/master/doc/install.md Clone the repository and install plyfile locally using pip. ```none pip3 install . ``` -------------------------------- ### Install project dependencies with PDM Source: https://github.com/dranjan/python-plyfile/blob/master/doc/developing.md Install all necessary project dependencies from the project root using PDM. This command should be run after installing PDM itself. ```bash pdm install ``` -------------------------------- ### Install plyfile from source Source: https://github.com/dranjan/python-plyfile/blob/master/README.md Install the plyfile module from its source code. Ensure you are in the project root directory. ```bash # From the project root pip3 install . ``` -------------------------------- ### PLY Property Syntax Example Source: https://github.com/dranjan/python-plyfile/blob/master/doc/philosophy.md This example demonstrates the standard 'property {type} {name}' syntax for defining properties in a PLY file. Plyfile only supports this format. ```none property {type} {name} ``` -------------------------------- ### Install PDM using pip Source: https://github.com/dranjan/python-plyfile/blob/master/doc/developing.md Install the PDM package manager using pip. This is the first step for setting up the development environment. ```bash pip install pdm ``` -------------------------------- ### Install PDM using pipx Source: https://github.com/dranjan/python-plyfile/blob/master/doc/developing.md Install the PDM package manager using pipx. This is an alternative method for setting up the development environment. ```bash pipx install pdm ``` -------------------------------- ### Install plyfile using pip Source: https://github.com/dranjan/python-plyfile/blob/master/README.md Install the latest official release of the plyfile module using pip. ```bash pip3 install plyfile ``` -------------------------------- ### Run all tests with PDM Source: https://github.com/dranjan/python-plyfile/blob/master/doc/developing.md Execute the complete test matrix. This requires all currently supported Python versions to be installed and available. ```bash pdm run test-all ``` -------------------------------- ### Alternative PLY Property Syntax (Not Supported) Source: https://github.com/dranjan/python-plyfile/blob/master/doc/philosophy.md This example shows an alternative, less common syntax for defining PLY properties ('property {name} {type}'). Plyfile does not support this syntax. ```none property {name} {type} ``` -------------------------------- ### Import necessary libraries Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Import numpy and the PlyData and PlyElement classes from plyfile. This is a prerequisite for all subsequent examples. ```python import numpy from plyfile import PlyData, PlyElement ``` -------------------------------- ### Rename PlyElement Property by Modifying Instance Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Provides an example of how to effectively rename a property of a PlyElement by manipulating its 'properties' and 'data' attributes, including creating new PlyProperty instances. ```Python >>> from plyfile import PlyProperty, PlyListProperty >>> face = plydata['face'] >>> face.properties = () >>> face.data.dtype.names = ['idx', 'r', 'g', 'b'] >>> face.properties = (PlyListProperty('idx', 'uchar', 'int'), ... PlyProperty('r', 'uchar'), ... PlyProperty('g', 'uchar'), ... PlyProperty('b', 'uchar')) >>> ``` -------------------------------- ### Get 2D Array from List Property Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Illustrates how to obtain a two-dimensional NumPy array from a list property, such as 'vertex_indices' in a 'face' element, for easier manipulation. ```Python >>> plydata = PlyData.read('tet.ply') >>> tri_data = plydata['face'].data['vertex_indices'] >>> triangles = numpy.vstack(tri_data) >>> ``` -------------------------------- ### Generate documentation with PDM Source: https://github.com/dranjan/python-plyfile/blob/master/doc/developing.md Generate the project's HTML documentation using PDM. The output can be found in the 'doc/build/index.html' file. ```bash pdm run doc ``` -------------------------------- ### Run quick tests with PDM Source: https://github.com/dranjan/python-plyfile/blob/master/doc/developing.md Execute the test suite using a single Python interpreter and a single version of NumPy. This is a quick way to run tests during development. ```bash pdm run test-quick ``` -------------------------------- ### Run linter with PDM Source: https://github.com/dranjan/python-plyfile/blob/master/doc/developing.md Execute the project's linter using PDM. Code should pass linting checks to be considered for merging. ```bash pdm run lint ``` -------------------------------- ### Recommended: Create New PlyData Instance Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Demonstrates the recommended approach for modifying PLY data by creating a new PlyData instance with desired elements and attributes, rather than modifying in place. ```Python >>> # Recommended: >>> plydata = PlyData([plydata['face'], plydata['vertex']], ... text=False, byte_order='<') >>> ``` -------------------------------- ### Enable Memory Mapping for Elements Without List Properties Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Demonstrates how memory mapping is enabled by default for elements without list properties. Shows how to disable it with `mmap=False` and enable it with read-write access using `mmap='r+'`. ```python >>> plydata.text = False >>> plydata.byte_order = '<' >>> plydata.write('tet_binary.ply') >>> >>> # Memory-mapping is enabled by default. >>> plydata = PlyData.read('tet_binary.ply') >>> isinstance(plydata['vertex'].data, numpy.memmap) True >>> # Any falsy value disables memory-mapping here. >>> plydata = PlyData.read('tet_binary.ply', mmap=False) >>> isinstance(plydata['vertex'].data, numpy.memmap) False >>> # Strings can also be given to fine-tune memory-mapping. >>> # For example, with 'r+', changes can be written back to the file. >>> # In this case, the file must be explicitly opened with read-write >>> # access. >>> with open('tet_binary.ply', 'r+b') as f: ... plydata = PlyData.read(f, mmap='r+') >>> isinstance(plydata['vertex'].data, numpy.memmap) True >>> plydata['vertex']['x'] = 100 >>> plydata['vertex'].data.flush() >>> plydata = PlyData.read('tet_binary.ply') >>> all(plydata['vertex']['x'] == 100) True >>> ``` -------------------------------- ### Run comprehensive tests with PDM Source: https://github.com/dranjan/python-plyfile/blob/master/doc/developing.md Run the full test matrix, skipping unavailable Python versions. This provides a more comprehensive test coverage report. ```bash pdm run test-matrix ``` -------------------------------- ### Serialize PlyData to Binary and ASCII Files Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Instantiate PlyData with a list of PlyElement objects and serialize it to a file. Supports both binary and ASCII formats. ```Python PlyData([el]).write('some_binary.ply') ``` ```Python PlyData([el], text=True).write('some_ascii.ply') ``` -------------------------------- ### Publish Release to PyPI Source: https://github.com/dranjan/python-plyfile/blob/master/doc/maintaining.md Publish the new version of the package to the Python Package Index (PyPI) using the 'pdm publish' command with an API token. For testing, use the '-r testpypi' flag. ```bash pdm publish -u __token__ -P $(< token.txt) ``` -------------------------------- ### Describe PLY Element with Comments Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Create a PlyElement instance with associated comments by passing a list of comment strings to PlyElement.describe. ```Python el = PlyElement.describe(vertex, 'vertex', comments=['comment1', 'comment2']) ``` -------------------------------- ### Initialize List Property from 2D Array in Python Source: https://github.com/dranjan/python-plyfile/blob/master/doc/faq.md Use this when initializing a 'face' element from a 2D array of vertex indices. PlyElement.describe requires a one-dimensional structured array. ```Python >>> from plyfile import PlyElement >>> import numpy >>> >>> # Here's a two-dimensional array containing vertex indices. >>> face_data = numpy.array([[0, 1, 2], [3, 4, 5]], dtype='i4') >>> >>> # PlyElement.describe requires a one-dimensional structured array. >>> ply_faces = numpy.empty(len(face_data), ... dtype=[('vertex_indices', 'i4', (3,))]) >>> ply_faces['vertex_indices'] = face_data >>> face = PlyElement.describe(ply_faces, 'face') >>> ``` -------------------------------- ### Update CHANGELOG.md for New Release Source: https://github.com/dranjan/python-plyfile/blob/master/doc/maintaining.md Add a new entry to the CHANGELOG.md file to document changes for a new version. This includes adding a new version heading and updating links. ```diff diff --git a/CHANGELOG.md b/CHANGELOG.md index 03dba5f..22ee9a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented here. ## [Unreleased] + +## [0.8.1] - 2023-03-18 ### Changed - Package metadata management via PDM, rather than `setuptools`. @@ -117,7 +119,8 @@ All notable changes to this project will be documented here. - Rudimentary test setup. - Basic installation script. -[Unreleased]: https://github.com/dranjan/python-plyfile/compare/v0.8...HEAD +[Unreleased]: https://github.com/dranjan/python-plyfile/compare/v0.8.1...HEAD +[0.8.1]: https://github.com/dranjan/python-plyfile/compare/v0.8...v0.8.1 [0.8]: https://github.com/dranjan/python-plyfile/compare/v0.7.4...v0.8 [0.7.4]: https://github.com/dranjan/python-plyfile/compare/v0.7.3...v0.7.4 [0.7.3]: https://github.com/dranjan/python-plyfile/compare/v0.7.2...v0.7.3 ``` -------------------------------- ### Push Changes and Tag to GitHub Source: https://github.com/dranjan/python-plyfile/blob/master/doc/maintaining.md Push the local master branch and the newly created tag to the remote GitHub repository. ```bash git push origin master v0.8.1 ``` -------------------------------- ### Tag the Release Commit Source: https://github.com/dranjan/python-plyfile/blob/master/doc/maintaining.md Create an annotated Git tag for the release. The tag name should follow the version number (e.g., vX.Y.Z). ```bash git tag -a v0.8.1 ``` -------------------------------- ### Show Git Commit Information Source: https://github.com/dranjan/python-plyfile/blob/master/doc/maintaining.md View details of a specific Git commit, often used to inspect version tags. ```bash git show v0.8.1 ``` -------------------------------- ### Lookup PlyProperty by name Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Access specific PlyProperty metadata for an element by its name. ```python plydata.elements[0].ply_property('x') PlyProperty('x', 'float') ``` -------------------------------- ### Enable Memory Mapping for Elements With Known List Lengths Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Shows how to enable memory mapping for elements with list properties when all list properties have fixed and known lengths. The `known_list_len` argument specifies the expected length for each list property. ```python >>> plydata = PlyData.read('tet_binary.ply', ... known_list_len={'face': {'vertex_indices': 3}}) >>> isinstance(plydata['face'].data, numpy.memmap) True >>> ``` -------------------------------- ### Create Numpy Arrays for Vertex and Face Elements Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Prepare numpy structured arrays for 'vertex' and 'face' elements, adhering to PLY file type restrictions. Non-scalar fields are allowed and serialized as list properties. ```Python vertex = numpy.array([(0, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 0)], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')]) face = numpy.array([([0, 1, 2], 255, 255, 255), ([0, 2, 3], 255, 0, 0), ([0, 1, 3], 0, 255, 0), ([1, 2, 3], 0, 0, 255)], dtype=[('vertex_indices', 'i4', (3,)), ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')]) ``` -------------------------------- ### Convenient element and property lookup Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Access element data by name using dictionary-like syntax. Properties within an element can also be accessed directly. ```python plydata['vertex']['x'] array([0., 0., 1., 1.], dtype=float32) ``` -------------------------------- ### Commit Version Changes Source: https://github.com/dranjan/python-plyfile/blob/master/doc/maintaining.md Stage and commit the changes made to pyproject.toml and CHANGELOG.md with a standard commit message. ```bash git add pyproject.toml git add CHANGELOG.md git commit -m "Bump version" ``` -------------------------------- ### Read PLY file using file path Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Use the PlyData.read static method to load data from a PLY file specified by its file path. ```python plydata = PlyData.read('tet.ply') ``` -------------------------------- ### Add Header Comments to PlyData Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Demonstrates how to add header comments to a PlyData instance. These comments are stored in the 'comments' attribute. ```Python >>> ply = PlyData([el], comments=['header comment']) >>> ply.comments ['header comment'] >>> ``` -------------------------------- ### Write Binary PLY to sys.stdout.buffer in Python Source: https://github.com/dranjan/python-plyfile/blob/master/doc/faq.md Write a binary-format PLY file to standard output by accessing the binary stream via `sys.stdout.buffer`. This is necessary because `sys.stdout` is a text-mode stream. ```Python >>> plydata.write(sys.stdout.buffer) # doctest: +SKIP ``` -------------------------------- ### Add obj_info Comments to PlyData Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Shows how to add 'obj_info' comments to a PlyData instance. These are distinct from regular header comments and are stored in the 'obj_info' attribute. ```Python >>> ply = PlyData([el], obj_info=['obj_info1', 'obj_info2']) >>> ply.obj_info ['obj_info1', 'obj_info2'] >>> ``` -------------------------------- ### Accessing PlyElement metadata Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Retrieve metadata associated with a PlyElement, such as its properties and count. ```python plydata.elements[0].properties (PlyProperty('x', 'float'), PlyProperty('y', 'float'), PlyProperty('z', 'float')) ``` ```python plydata.elements[0].count 4 ``` -------------------------------- ### Direct element indexing Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Index elements directly without accessing the 'data' attribute, providing a shortcut to element data. ```python plydata['vertex'][0].tolist() (0.0, 0.0, 0.0) ``` -------------------------------- ### Write ASCII PLY to /dev/stdout in Python Source: https://github.com/dranjan/python-plyfile/blob/master/doc/faq.md Write an ASCII-format PLY file directly to standard output using the '/dev/stdout' path. This method is suitable for text-mode streams. ```Python >>> plydata.write('/dev/stdout') # doctest: +SKIP ``` -------------------------------- ### Describe PLY Element from Numpy Array Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Use PlyElement.describe to create a PlyElement instance from a numpy array. This method infers property types from the array's dtype. ```Python el = PlyElement.describe(vertex, 'vertex') ``` -------------------------------- ### Read PLY file using file object Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Alternatively, read PLY data from an opened file object in binary read mode ('rb'). ```python with open('tet.ply', 'rb') as f: plydata = PlyData.read(f) ``` -------------------------------- ### Update Project Version in pyproject.toml Source: https://github.com/dranjan/python-plyfile/blob/master/doc/maintaining.md Modify the version number in the pyproject.toml file. This is a required step before making a new release. ```diff diff --git a/pyproject.toml b/pyproject.toml index d079b17..5c42074 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [project] name = "plyfile" -version = "0.8" +version = "0.8.1" description = "PLY file reader/writer" authors = [ ``` -------------------------------- ### Alternative: Modify PlyData Instance Attributes Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Shows an alternative method for modifying PLY data by directly assigning to the 'elements', 'text', 'byte_order', 'comments', and 'obj_info' attributes of an existing PlyData instance. ```Python >>> # Also supported: >>> plydata.elements = [plydata['face'], plydata['vertex']] >>> plydata.text = False >>> plydata.byte_order = '<' >>> plydata.comments = [] >>> plydata.obj_info = [] >>> ``` -------------------------------- ### Describe PLY Element with Custom List Property Types Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Specify custom data types for list properties, such as 'vertex_indices', using val_types and len_types arguments in PlyElement.describe. This is necessary when numpy array types do not directly map to desired PLY list types. ```Python el = PlyElement.describe(face, 'face', val_types={'vertex_indices': 'u2'}, len_types={'vertex_indices': 'u4'}) ``` -------------------------------- ### Serialize PlyData with Big-Endian Byte Order Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Force the byte order of the output PLY file to big-endian by specifying '>" in the byte_order argument when creating PlyData. ```Python PlyData([el], byte_order='>').write('some_big_endian_binary.ply') ``` -------------------------------- ### Serialize PlyData to a File Object Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Write PLY data to a file object instead of a filename. When writing in text mode, ensure the file is opened in binary mode ('wb') to handle line endings correctly across different operating systems. ```Python with open('some_ascii.ply', mode='wb') as f: PlyData([el], text=True).write(f) ``` -------------------------------- ### Accessing PLY data elements and properties Source: https://github.com/dranjan/python-plyfile/blob/master/doc/usage.md Access the name and data of PLY elements. Element data is stored in numpy structured arrays. List properties are represented as numpy arrays. ```python plydata.elements[0].name 'vertex' ``` ```python plydata.elements[0].data[0].tolist() (0.0, 0.0, 0.0) ``` ```python plydata.elements[0].data['x'] array([0., 0., 1., 1.], dtype=float32) ``` ```python plydata['face'].data['vertex_indices'][0] array([0, 1, 2], dtype=int32) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.