Skip to content

NREL/ninterp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ninterp

docs.rs Crates.io Version GitHub

The ninterp crate provides multivariate interpolation over rectilinear grids of any dimensionality. A variety of interpolation strategies are implemented, and more are likely to be added.

There are hard-coded interpolators for lower dimensionalities (up to N = 3) for better runtime performance.

cargo add ninterp

Feature Flags

  • serde: support for serde

Getting Started

A prelude module has been defined: use ninterp::prelude::*;. This exposes the types necessary for usage: Interpolator, Strategy, and Extrapolate.

Interpolation is executed by calling Interpolator::interpolate. The length of the supplied point slice must be equal to the interpolator dimensionality.

For interpolators of dimensionality N ≥ 1:

  • Instantiation is done via the Interpolator enum's new_* methods (new_1d, new_2d, new_3d, new_nd). These methods run a validation step that catches any potential errors early, preventing runtime panics.
    • To set or get field values, use the corresponding named methods (x, set_x, etc.).
  • An interpolation Strategy (e.g. linear, left-nearest, etc.) must be specified. Not all interpolation strategies are implemented for every dimensionality. Strategy::Linear and Strategy::Nearest are implemented for all dimensionalities.
  • An Extrapolate setting must be specified. This controls what happens when a point is beyond the range of supplied coordinates. If you are unsure which variant to choose, Extrapolate::Error is likely what you want. Linear extrapolation is implemented for all dimensionalities.

For 0-D (constant-value) interpolators, instantiate directly, e.g. Interpolator::Interp0D(0.5)

Examples