user1764386
user1764386

Reputation: 5611

Python - Interpolating between lines of data

I have data on a 2d grid characterized by points (x,Y,Z). The X and Y values indicate each point's position and Z is "height" or "intensity" at each point.

My issue is that my data coordinates along the X axis are extremely closely spaced (~1000 points), while my Y coordinates are spread out (~50 points). This means that when plotted on a scatter plot, I essentially have lines of data with an equal amount of blank space between neighboring lines.

Example of how my data is spaced on a scatter plot:

ooooooooooooooooooooooooooooooo


ooooooooooooooooooooooooooooooo


ooooooooooooooooooooooooooooooo

I want to interpolate these points to get a continuous surface. I want to be able to evaluate the "height" at any position on this surface. I have tried what seems like every scipy interpolation method and am not sure of what the most "intelligent" method is. Should I interpolate each vertical slice of data, then stitch them together?

I want as smooth a surface as possible, but need a shape preserving method. I do not want any of the interpolated surface to overshoot my input data.

Any help you can provide would be very helpful.

EDIT:

As I think about the problem more, it seems that interpolating the vertical slices and then stitching them together wouldn't work. That would cause the value along a vertical slice to only be effected by that slice, Wouldn't that result in an inaccurate surface?

Upvotes: 1

Views: 2850

Answers (2)

tacaswell
tacaswell

Reputation: 87376

I recommend this tutorial. The guts of it are (lifted from link):

>>> grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
>>> from scipy.interpolate import griddata
>>> grid_z0 = griddata(points, values, (grid_x, grid_y), method='nearest')
>>> grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')
>>> grid_z2 = griddata(points, values, (grid_x, grid_y), method='cubic')

Which will get you three different levels of interpolation of your data (doc).

Upvotes: 3

Alex Mann
Alex Mann

Reputation: 11

If you're looking for the surface, my assumption would be that you can get by using vertical slices, and then plotting the filled out data.

Upvotes: 0

Related Questions