Closed browniea closed 1 year ago
"On the edges of the grid" - it's possible that scipy.interpolate (which is what I believe 'interp' is here) sees data on the grid edges as outside of the range of the input data. An easy way to check that is to set the fill_value
keyword arg to "extrapolate" (kwargs={'fill_value':"extrapolate"}
), and see if it still returns those nan's.
Addressed in #190
Describe the bug:
When interpolating data, data on the edges of the grid can come up as
nan
when interpolating with the methodnearest
.To Reproduce:
example
x_sample = np.linspace(xmin, xmax, num=100)
y_samples = np.mean([ymin,ymax])
z_samples = np.linspace(zmin,zmax, num=256)
sample_points = d3d.create_points(x_sample, y_samples, z_samples)
contour_variable = interp.griddata(var_data_df[['x','y','z']],
var_data_df[variable],
sample_points[['x','y','z']]
Expected behavior:
Replace the nan that result from the linear interpolation with a nearest interpolation.
idx= np.where(np.isnan(contour_variable))
if len(idx[0]):
for i in idx[0]:
contour_variable[i]= interp.griddata(var_data_df[['x','y','z']],
var_data_df[variable],
[sample_points['x'][i],sample_points['y'][i], sample_points['z'][i]],
method='nearest')