Natural Neighbor Interpolation in 3D
Project description
Natural Neighbor Interpolation in 3D
This is a Python package for 3D natural neighbor interpolation (Sibson interpolation).
Natural neighbor interpolation is a form of scattered data interpolation, where you have a set of sample values of a function at arbitrary locations in 3D space (let's call the locations keys), and you want to interpolate the function value at other points (let's call them queries).
Specifically, in natural neighbor interpolation, the interpolated value is a weighted average of the function values of the query point's "natural neighbors". The natural neighbors of a query point are those vertices which, if we were to add the query point to the data, would have Voronoi cells sharing a face with the query point's Voronoi cell. The weights are proportional to the volume "stolen" from the neighbor's Voronoi cell upon the query point's insertion.
This package uses Cython to wrap my modified version of Ross Hemsley's interpolate3d. The modifications are:
- parallelization via OpenMP
- option to extract the natural neighbor weights (Sibson coordinates) directly (the original version only gives the final interpolated value, but not the weights)
- k-d tree for faster search for the containing simplex of an inserted point
Installation
For now, install via:
pip install git+https://github.com/isarandi/natinterp3d.git
Publishing to PyPI is planned.
Usage
Simplest is to call natinterp3d.interpolate(queries, keys, values) or natinterp3d.get_weights(queries, keys):
import natinterp3d
import numpy as np
# The positions of the data points where the function values are known
keys = np.array([[x1, y1, z1], [x2, y2, z2], ...])
# The values can also be a 2D array of shape (N, values_dim) with D dimensional vectors as values at each data point
values = np.array([v1, v2, v3, ...])
# The positions where we want to interpolate the function values
queries = np.array([[qx1, qy1, qz1], [qx2, qy2, qz2], ...])
# Returns either [num_queries] or [num_queries, values_dim], the array of interpolated values
interpolated_values = natinterp3d.interpolate(queries, keys, values)
# or get the interpolation weights as a sparse matrix of size [num_queries, num_keys] (scipy.sparse.csr_matrix)
weights = natinterp3d.get_weights(queries, keys)
For more control, e.g., if you want to interpolate queries and/or values on the same key positions, you can use the natinterp3d.Interpolator class as:
import natinterp3d
keys = np.array([[x1, y1, z1], [x2, y2, z2], ...])
interpolator = natinterp3d.Interpolator(keys)
values = np.array([v1, v2, v3, ...]) # or a 2D array of shape (N, values_dim)
queries = np.array([[qx1, qy1, qz1], [qx2, qy2, qz2], ...])
interpolated_values = interpolator.interpolate(queries, values)
# or:
weights = interpolator.get_weights(queries)
Multithreaded computation is automatically enabled. To customize, use the argument parallel=True/False and num_threads in interpolate or get_weights. With num_threads=None (default), the number of threads is automatically determined based on the available CPU cores.
License
GNU GPL v3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file natinterp3d-0.2.0.tar.gz.
File metadata
- Download URL: natinterp3d-0.2.0.tar.gz
- Upload date:
- Size: 176.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0592773c7bed475ab618081968bf665a9bbfc9f5c75ef64f6e657cbb2396aa58
|
|
| MD5 |
0fc82a5065532a5a5de01cbbdda6db46
|
|
| BLAKE2b-256 |
57992f427d2507d6583c987f3f02f4de25cdd44ac11ac694136b27631e8de3f2
|