Giter Site home page Giter Site logo

liq07lzucn / natural-neighbor-interpolation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from innolitics/natural-neighbor-interpolation

0.0 0.0 0.0 394 KB

Fast, discrete natural neighbor interpolation in 3D on the CPU.

License: MIT License

C++ 54.84% Python 41.19% CMake 3.65% Shell 0.32%

natural-neighbor-interpolation's Introduction

https://travis-ci.org/innolitics/natural-neighbor-interpolation.svg?branch=master

Discrete Sibson (Natural Neighbor) Interpolation

Natural neighbor interpolation is a method for interpolating scattered data (i.e. you know the values of a function at scattered locations). It is often superior to linear barycentric interpolation, which is a commonly used method of interpolation provided by Scipy's griddata function.

There are several implementations of 2D natural neighbor interpolation in Python. We needed a fast 3D implementation that could run without a GPU, so we wrote an implementation of Discrete Sibson Interpolation (a version of natural neighbor interpolation that is fast but introduces slight errors as compared to "geometric" natural neighbor interpolation).

See https://doi.org/10.1109/TVCG.2006.27 for details.

Installation

pip install naturalneighbor

Dependencies

  • Python 2.7 or 3.4+
  • Numpy (has been tested with 1.13+)

Demonstration

Natural neighbor interpolation can be more accurate than linear barycentric interpolation (Scipy's default) for smoothly varying functions.

Also, the final result looks better.

https://raw.githubusercontent.com/innolitics/natural-neighbor-interpolation/master/demo/linear_comparison.png https://raw.githubusercontent.com/innolitics/natural-neighbor-interpolation/master/demo/sin_sin_comparison.png

Note that the natural neighbor values usually are extrapolated; they were cut off in the demo to fairly compare with Scipy's linear barycentric method, which does not extrapolate.

Usage

This module exposes a single function, griddata.

The API for naturalneighbor.griddata is similar to scipy.interpolate.griddata. Unlike Scipy, the third argument is not a dense mgrid, but instead is just the ranges that would have been passed to mgrid. This is because the discrete Sibson approach requires the interpolated points to lie on an evenly spaced grid.

import scipy.interpolate
import numpy as np

import naturalneighbor

num_points = 10
num_dimensions = 3
points = np.random.rand(num_points, num_dimensions)
values = np.random.rand(num_points)

grids = tuple(np.mgrid[0:100:1, 0:50:100j, 0:100:2])
scipy_interpolated_values = scipy.interpolate.griddata(points, values, grids)

grid_ranges = [[0, 100, 1], [0, 50, 100j], [0, 100, 2]]
nn_interpolated_values = naturalneighbor.griddata(points, values, grid_ranges)

Future Work

  • Provide options for extrapolation handling
  • Support floats and complex numbers (only support doubles at the moment)
  • Support 2D (only support 3D)
  • Add documentation with discussion on limitations of discrete sibson's method
  • Uncomment cpplint from tox.ini and cleanup C++ code
  • Generalize the threading model (currently it uses 8 threads---one for each quadrant)

Other Resources

natural-neighbor-interpolation's People

Contributors

johndgiese avatar reecestevens avatar yujanshrestha avatar zach-waggoner avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.