pyhaze
Fast smoothing of per-vertex data on triangular meshes for Python.
About
This package package performs smoothing of per-vertex data on triangular meshes. Such smoothing is typically used to reduce high-frequency noise and improve signal-to-noise ration (SNR). The algorithm for iterative nearest-neighbor smoothing is trivial, but involves nested tight loops, which are very slow in Python, so this package calls into C++ via pybind11 to achieve high performance.
Fig.1: Noisy per-vertex data on a brain mesh (left), and the same data after smoothing (right). White represents NA values.
This is a Python implementation of the haze package for R. The haze website offers a more detailed explanation of the motivation and use cases.
Installation
Via pip:
pip install pyhaze
Alternatively, if you want to use conda:
conda install -c dfspspirit pyhaze
Usage
Example 1: Smooth data on a mesh given as a vertex index list
Here is a simple example using the pyhaze.smooth_pvd function.
import pyhaze
import numpy as np
vertices, faces = pyhaze.construct_cube()
pvd_data = np.arange(len(vertices), dtype=float)
smoothed_data = pyhaze.smooth_pvd(vertices, faces, pvd_data.tolist(), num_iter=5)
A note on the mesh representation used, so you can replace the vertices and faces with your own triangular mesh:
verticesis a list of lists offloat, with dimensionN, 3forNvertices. So the outer list has lengthN. The 3 columns (length of all inner lists) are the x,y,z coordinates for each vertex.facesis a list of lists ofint, with dimensionM, 3forMfaces. So the outer list has lengthM. The 3 columns (length of all inner lists) are the 3 vertices (given as indices intovertices) making up the respective triangular face.
Example 2: Smooth data on a mesh given as an adjacency list
For very large meshes, it pays off to pre-compute the adjacency list of the mesh with a fast method, such as with the igl Python package, which provides Python bindings for libigl, and use the pyhaze.smooth_pvd_adj function.
import pyhaze
import numpy as np
import igl
vertices, faces = pyhaze.construct_cube()
pvd_data = np.arange(len(vertices), dtype=float)
faces_igl = np.array(faces).reshape(-1, 3).astype(np.int64)
mesh_adj = igl.adjacency_list(faces_igl) # Compute adjacency list with igl.
res = pyhaze.smooth_pvd_adj(mesh_adj, pvd_data.tolist(), num_iter=5)
See the unit tests for more examples.
Metadata
Release files for pyhaze 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyhaze-0.1.3.tar.gz | 1.6 MB | Without provenance | Details for pyhaze-0.1.3.tar.gz |
Release files / pyhaze-0.1.3.tar.gz
| Download URL | pyhaze-0.1.3.tar.gz |
|---|---|
| Size | 1.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4dc565f890ea6f1d03661210ad4197d87c95603a6fec4077d8c86891ca4265f
|
|
BLAKE2b-256 checksum How to use checksums |
d290d6c80deffec81f62da5166c4633a7aecebd1c9592eccabeb7051158389b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.15
|
Security for pyhaze 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.