Skip to main content

ndpolator: fast, n-dimensional linear interpolation and extrapolation on sparse grids

Project description

GitHub commit activity GitHub last commit GitHub Issues or Pull Requests GitHub Actions Workflow Status Documentation

Ndpolator

Fast, n-dimensional linear interpolation and extrapolation on sparse grids.

Ndpolator is a combined interpolator/extrapolator that operates on sparse (incompletely populated) $n$-dimensional grids. It estimates scalar or vector function values within and beyond the definition range of the grid while still avoiding the need to impute missing data or sacrifice the benefits of structured grids. Ndpolator is written in C for speed and portability; a python wrapper that uses numpy arrays is provided for convenience.

A high-level introduction to ndpolator is available here (pdf).

Installation

To install ndpolator, clone the github repo and install with pip:

$> git clone https://github.com/aprsa/ndpolator ndpolator
$> cd ndpolator
$> pip install .

Once installed, you can test it by running a pytest:

$> cd tests
$> pytest

Documentation

API reference is available at gh-pages.

A draft JOSS paper that describes the operational details of ndpolator is available here. The draft has been submitted on Mar 13, 2024.

Usage example

To demonstrate the usage of ndpolator, let us consider a 3-dimensional space with three axes of vastly different vertex magnitudes. For comparison purposes, let the function that we want to interpolate and extrapolate be a linear scalar field:

$$ \mathbf a_1 = (1000, 2000, 3000, 4000, 5000), \quad \mathbf a_2 = (1, 2, 3, 4, 5), \quad \mathbf a_3 = (0.01, 0.02, 0.03, 0.04, 0.05), $$

$$ \mathbf F(x, y, z) = \frac{x}{1000} + y + 100 z. $$

A suitable ndpolator instance would be initiated and operated as follows:

import numpy
import ndpolator

# initialize the axes:
a1 = np.linspace(1000, 5000, 5)
a2 = np.linspace(1, 5, 5)
a3 = np.linspace(0.01, 0.05, 5)

# initialize interpolation space:
ndp = ndpolator.Ndpolator(basic_axes=(a1, a2, a3))

# define a scalar function field and evaluate it across the grid:
def fv(pt):
    return pt[0]/1000 + pt[1] + 100*pt[2]

grid = np.empty((len(ax1), len(ax2), len(ax3), 1))
for i, x in enumerate(ax1):
        for j, y in enumerate(ax2):
            for k, z in enumerate(ax3):
                grid[i, j, k, 0] = fv((x, y, z))

# label the grid ('main') and register it with the ndpolator instance:
ndp.register(table='main', associated_axes=None, grid=grid)

# draw query points randomly within and beyond the definition ranges:
query_pts = np.ascontiguousarray(
    np.vstack((
        np.random.uniform(500, 5500, 1000),
        np.random.uniform(0.5, 5.5, 1000),
        np.random.uniform(0.005, 0.055, 1000))
    ).T
)

# interpolate and extrapolate linearly:
interps = ndp.ndpolate(table='main', query_pts, extrapolation_method='nearest')

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

ndpolator-1.0.tar.gz (41.1 kB view details)

Uploaded Source

File details

Details for the file ndpolator-1.0.tar.gz.

File metadata

  • Download URL: ndpolator-1.0.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for ndpolator-1.0.tar.gz
Algorithm Hash digest
SHA256 c373ad25430574fb15ed6fdf1ad462f73bbb5c8fbfe922ee283969660fece8cd
MD5 3bb98a5471ea826dd6795158d4d6164e
BLAKE2b-256 4b8a171e1fb8f3cf1f409c302c9e4c40a5ff26a456ac57ccc1327d96155b5ea0

See more details on using hashes here.

Supported by

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