A 3D interpolator for Python designed for maximum speed on large datasets. It accelerates the IDW algorithm with a parallelized C++ core (OpenMP) and optimized k-NN searches (nanoflann).
The interpolation is performed in a two-step process that combines the k-NN and IDW algorithms.
-
Neighbor Selection (k-NN): For each point where a value is to be estimated, the k-Nearest Neighbors algorithm first finds the k closest known source points in space. The efficiency of this search is ensured by an optimized data structure (
k-d tree). -
Value Calculation (IDW): Next, the Inverse Distance Weighting method calculates the final value as a weighted average of the k found neighbors. The weight of each neighbor is inversely proportional to its distance (weight = 1/distanceᵖ, where
pis a power parameter), causing closer points to have a much greater influence on the result.
Before you begin, ensure you have the following software installed:
- Python 3.10+
- Git
- A C++ compiler: This package contains C++ code that needs to be compiled during installation.
- Windows: Install Visual Studio Build Tools (select the "Desktop development with C++" workload).
- Linux (Debian/Ubuntu): Install build-essential with: sudo apt-get install build-essential.
pip install pyterpgit clone https://github.com/jgmotta98/PyTerp.git
cd PyTerp# Create the environment
python -m venv .venv
# Activate the environment
# On Windows (cmd.exe):
.venv\Scripts\activate
# On macOS/Linux (bash/zsh):
source .venv/bin/activatepip install -r requirements.txtpip install .For a complete and runnable example, including the creation and preparation of input data, please see the scripts in the examples folder.
This project uses nanoflann, a high-performance C++ library for the k-Nearest Neighbors algorithm. The efficiency of nanoflann's k-d tree implementation is fundamental to this interpolator's performance.
- Official Repository: Nanoflann