Skip to main content

A package for performing optimized k-NN IDW interpolation using C++.

Project description

PyTerp

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).

Theoretical Summary

The interpolation is performed in a two-step process that combines the k-NN and IDW algorithms.

  1. 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).

  2. 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 p is a power parameter), causing closer points to have a much greater influence on the result.

Prerequisites

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.

Installation

PyPI

Install the package:

pip install pyterp

GitHub

1. Clone the repository:

git clone https://github.com/jgmotta98/PyTerp.git
cd PyTerp

2. Create and activate a virtual environment:

# 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/activate

3. Install the requirements:

pip install -r requirements.txt

4. Install the package:

pip install .

Usage Example

import numpy as np
import pyterp as pt

# Assuming 'source_points', 'source_values', and 'target_points'
# are properly prepared NumPy arrays.
interpolated_values = pt.interpolate(
    source_points=source_points,
    source_values=source_values,
    target_points=target_points,
    k_neighbors=10,
    power=2
)

print("Interpolated values:", interpolated_values)

For a complete and runnable example, including the creation and preparation of input data, please see the script in the examples folder.

Acknowledgements

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyterp-0.1.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyterp-0.1.0-cp310-cp310-win_amd64.whl (79.7 kB view details)

Uploaded CPython 3.10Windows x86-64

pyterp-0.1.0-cp310-cp310-win32.whl (73.8 kB view details)

Uploaded CPython 3.10Windows x86

pyterp-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file pyterp-0.1.0.tar.gz.

File metadata

  • Download URL: pyterp-0.1.0.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.1

File hashes

Hashes for pyterp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dd7abbf16312046ccc9908fe5b673546a97be01c154f4da36c0a341e76d6f5e2
MD5 7d4941146011efd491e452be35e53d38
BLAKE2b-256 5ac5675911f4613d1cc04bd37ae5d261dc97e02d4ecfd0e69430224cb091b9ec

See more details on using hashes here.

File details

Details for the file pyterp-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyterp-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 79.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.1

File hashes

Hashes for pyterp-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b2c25b1b01c478552b0c5aa5f9ba576452d175c1ee71698e3019b7ec69f3ad78
MD5 7e3efdc69e86ffbcb0ef8df349c15482
BLAKE2b-256 4846f1ff540ad520d8a6e2f0c74c7ded4b60d27f35c47985ade8031720e80115

See more details on using hashes here.

File details

Details for the file pyterp-0.1.0-cp310-cp310-win32.whl.

File metadata

  • Download URL: pyterp-0.1.0-cp310-cp310-win32.whl
  • Upload date:
  • Size: 73.8 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyterp-0.1.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 993cc55e0209618f1612cea240e8bbe8ed02308e5dcbb81a28658234925333db
MD5 5e05462ba0ef733dc6803926e67700a9
BLAKE2b-256 291380bd6b82d088cf83e5974173d1706fb2ca7b194682ce036a4a13e64904a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyterp-0.1.0-cp310-cp310-win32.whl:

Publisher: release.yaml on jgmotta98/PyTerp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyterp-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyterp-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0627c4637fec43212ca804cb86900cd52de9149cea7a5a8fd7f732174d86e98
MD5 b9d2d3d4ffc305be3bb84a0db78d40bc
BLAKE2b-256 adafa2713222b698b66d1aee9aacd2d07679ee16da9e09a4487669340bf43297

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyterp-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yaml on jgmotta98/PyTerp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page