Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Use It? #2

Open
jamiejackson opened this issue Nov 2, 2023 · 1 comment
Open

How to Use It? #2

jamiejackson opened this issue Nov 2, 2023 · 1 comment

Comments

@jamiejackson
Copy link

jamiejackson commented Nov 2, 2023

I can't find much documentation on this and the README is both bare-bones and pretty opaque. A real-world use case would help.

The following is my naive attempt. I know it's wrong but it will be useful to show what I need. Also note that the grid spacing of the known data is not even. (By the way, here is my working example using python.)

I am also interested in extrapolating values outside of the known data bounds. Is the ndarray-linar-interpolate library capable of that?

var ndarray = require("ndarray");
var interp = require("ndarray-linear-interpolate");

// Create the 2D ndarray object from the given data
// The first column is "diameter in inches" and the first row is "psi"
// The first cell (A:1)is a dummy value
var data = ndarray(new Float32Array([
  0, 60, 120, 240, 360, 480,
  4, 71, 100, 142, 173, 200,
  6, 106, 150, 212, 260, 300,
  8, 142, 200, 283, 347, 400 ,
  10, 177, 250, 354, 433, 500,
  12, 212, 300, 425, 520, 601,
  14,  248, 350, 495, 607, 701,
  16,  283, 400, 566, 693, 801,
  18,  318, 450, 637, 780, 901,
  20,  354, 500, 708, 867, 1001,
  22,  389, 550, 779, 953, 1101
]), [10,6]);

console.log(interp(data, 4.1, 61)); // x=4.1 inches, y=61 psi. expect a value of a little over 72 but it returns 0.
@jamiejackson
Copy link
Author

jamiejackson commented May 17, 2024

Soon after I posted, I bailed and went with Python / scipy / RegularGridInterpolator, which was documented, relatively easy to work with, and supported extrapolation outside of known data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant