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

Wrong interpolated value when initialising with grid of ones #1

Closed
nordam opened this issue May 26, 2020 · 2 comments
Closed

Wrong interpolated value when initialising with grid of ones #1

nordam opened this issue May 26, 2020 · 2 comments

Comments

@nordam
Copy link

nordam commented May 26, 2020

I'm trying out the tricubic interpolator, but I have trouble getting it to work. I have constructed the following example:

import numpy as np 
import ARBTools 
from ARBTools.ARBInterp import tricubic

Nx = 3
Ny = 5
Nz = 7

xc = np.linspace(-1, 1, Nx) # x coordinates
yc = np.linspace(-1, 1, Ny) # y coordinates
zc = np.linspace(-1, 1, Nz) # z coordinates

interpolator_array = np.zeros((Nx*Ny*Nz, 4))
ind = 0
for i in range(Nx):
    for j in range(Ny):
        for k in range(Nz):
            interpolator_array[ind,0] = xc[i]
            interpolator_array[ind,1] = yc[j]
            interpolator_array[ind,2] = zc[k]
            interpolator_array[ind,3] = 1.0 # All input values are 1.0
            ind += 1

f = tricubic(interpolator_array)
coords = np.zeros(3)

# Returned interpolated value is 0.0
f.Query(coords)[0]

Here, I pass in a value of 1.0 at all points, but the returned intepolated value at the point (0,0,0) is 0.0, not 1.0.

@nordam
Copy link
Author

nordam commented May 27, 2020

Since yesterday, I have been reminded that 3 points isn't enough to create a cubic spline, so of course each dimension has to have at least 4 points. With this change, it works as expected. I suppose a warning about invalid input would be handy.

@DurhamDecLab
Copy link
Owner

Hi, I'm extremely sorry that I did not respond to this issue, I didn't get a notification about it - I've only seen it now because I logged in to upload a slightly updated file.
I'm glad you were able to get things working. I'll look into what you report, the interpolator is designed to return "NaN" if you try to query a point outside the valid region. As you say, you need a minimum number of points to make a spline, in the case of the tricubic interpolator this means that we cannot interpolate any value within the outer layer of cuboid volume elements. I'll reproduce your problem and try and incorporate a warning.
Thank you for the bug report!

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

2 participants