MHKiT-Software / MHKiT-Python

MHKiT-Python provides the marine renewable energy (MRE) community tools for data processing, visualization, quality control, resource assessment, and device performance.
https://mhkit-software.github.io/MHKiT/
BSD 3-Clause "New" or "Revised" License
47 stars 45 forks source link

Delft3D interpolating nan with nearest #173

Closed browniea closed 1 year ago

browniea commented 2 years ago

Describe the bug:

When interpolating data, data on the edges of the grid can come up as nan when interpolating with the method nearest.

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')

jmcvey3 commented 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.

ssolson commented 1 year ago

Addressed in #190