GithubHelp home page GithubHelp logo

twang006 / btwxt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bigladder/btwxt

1.0 0.0 0.0 257 KB

N-dimensional grid interpolation library

License: BSD 3-Clause "New" or "Revised" License

Shell 1.00% C++ 70.96% CMake 28.04%

btwxt's Introduction

Build and Test codecov

Btwxt

General-purpose, N-dimensional interpolation library...

Btwxt is a free and open source c++ library to perform numerical interpolation on a gridded data set. The general architecture is that it creates a RegularGridInterpolator object from a) a collection of grid axes and b) a collection of values that fit that axis system. That RegularGridInterpolator object can then be queried repeatedly for values that fall inside its grid.

Btwxt supports linear and cubic spline (Catmull-Rom) interpolation methods, and those methods can be specified independently for each axis. The API also allows specification of preferred extrapolation methods (constant or linear)--again independently for each axis--and extrapolation limits.

The input grid is required to be regular (rectilinear) but the axes are not required to have uniform spacing. Each axis need only be strictly increasing.

The values are imported as a long vector: a flattened array. It is your responsibility to ensure that you load the grid vectors in the same order as they are defined for the values. Btwxt ensures that the number of values aligns with the grid space, but it does not attempt to verify that the grid axis order is consistent with the values.

Btwxt accepts:

  • a collection of N vectors representing the input variables,
  • attributes of each of the input vectors describing preferred interpolation and extrapolation methods, and
  • an array of (or collection of arrays of) values that map onto the grid defined by the input vectors.

How to Use

How to install/include

Need to complete this section

API

An individual axis can be instantiated with

std::vector<double> one_axis{6, 10, 15};
GridAxis(one_axis);
GridAxis(one_axis, interpolation_method = Method::CUBIC);
// interpolation method defaults to LINEAR
GridAxis(one_axis, extrapolation_method = Method::LINEAR);
// extrapolation method defaults to CONSTANT
std::pair<double, double> extrap_bounds{0, 20};
GridAxis(one_axis, Method::LINEAR, Method::CUBIC, extrap_bounds);
// extrapolation bounds default to {-DBL_MAX, DBL_MAX}

A collection of axes can be tied together into a GriddedData object

std::vector<GridAxis> my_grid{first_axis, second_axis, third_axis};
std::vector< std::vector<double> > values = {...};
GriddedData(my_grid, values);

Or you can feed a vector of vectors straight into GriddedData and let it construct the GridAxis objects:

std::vector<std::vector<double> > vector_grid = {{6, 10, 15},
                                                 {4, 6, 9}};
std::vector< std::vector<double> > values = {...};
GriddedData gridded_data(vector_grid, values);
gridded_data.set_axis_interp_method(0, Method::CUBIC);
gridded_data.set_axis_extrap_method(1, Method::LINEAR);
gridded_data.set_axis_extrap_limits(1, {2, 10});

RegularGridInterpolator holds a GriddedData object and adds capabilities for interpolation. If specified straight from vectors, it will build the GriddedData and GridAxis objects appropriately.

RegularGridInterpolator my_interpolator(gridded_data);
// or
std::vector<std::vector<double> > vector_grid = {{6, 10, 15},
                                                 {4, 6, 9}};
std::vector< std::vector<double> > values = {...};
my_interpolator(vector_grid, values);

Once you have an RGI object, you can set a point to interpolate to:

std::vector<double> target{12.5, 5.1};
my_interpolator.set_new_grid_point(target);
std::vector<double> result = my_interpolator.calculate_all_values_at_target();
my_interpolator.clear_current_grid_point();
// or set the point within the calculate:
std::vector<double> new_target{11.7, 6.1};
result = my_interpolator.calculate_all_values_at_target(new_target);

We have overloaded the () operator on the RGI to perform the interpolation, enabling the following:

std::vector<double> target{12.5, 5.1};
my_interpolator.set_new_grid_point(target);
std::vector<double> result = my_interpolator();
std::vector<double> new_target{11.7, 6.1};
std::vector<double> result = my_interpolator(new_target);

Dependencies

Btwxt uses

btwxt's People

Contributors

nealkruis avatar ajscimone avatar ptsullivan avatar galanca avatar

Stargazers

Yufan Liu 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.