Interpolation gives negative values

Heli hemla21 at gmail.com
Fri Feb 3 06:34:19 EST 2017


Dear all, 

I have an ASCII file (f1) with 100M lines with columns x,y,z ( new data points) and then I have a second ASCII file (f2) with 2M lines with columns x,y,z and VALUE (v10).(known data points). I need to interpolate f1 over f2, that is I need to have values for v10 for all coordinated in f1. I am using the following script to interpolate.

from scipy.interpolate import NearestNDInterpolator
#new data points
f1=np.loadtxt(os.path.join(dir,coord_source),delimiter=None,skiprows=0) 
x_coord=f1[:,1]
y_coord=f1[:,2]
z_coord=f1[:,3]

# known data points
f2=np.loadtxt(os.path.join(dir,val_source),delimiter=None,skiprows=1) 
x_val=f2[:,1]
y_val=f2[:,2]
z_val=f2[:,3]
v10=f2[:,10] # Value to be interpolated

# my interpolation function
myf_v10=NearestNDInterpolator((x_val, y_val,z_val),v10)
interpolated_v10=myf_v10(x_coord,y_coord,z_coord)

I have the following questions. 1. Considering f1 is 50 times bigger than f2. can I still use the above script? 2. The variable v10 that I need to interpolate should always be >= 0 (positive). Using the above script I am getting negative values for v10. How can I fix this?

I would really appreciate your help, Thanks in Advance,



More information about the Python-list mailing list