Python/Scipy 2D Interpolation (Non-uniform Data)

前端 未结 1 993
攒了一身酷
攒了一身酷 2020-11-29 08:52

This is a follow-up question to my previous post: Python/Scipy Interpolation (map_coordinates)

Let\'s say I want to interpolate over a 2d rectangular area. My varia

相关标签:
1条回答
  • 2020-11-29 09:22

    Looks like you got it.

    In your upper code example and in your previous (linked) question you have structured data. Which can be interpolated using RectBivariateSpline or interp2d. This means you have data that can be described on a grid (all points on the grid have a known value). The grid doesn't necessarily have to have all the same dx and dy. (if all dx's and dy's were equal, you'd have a Regular Grid)

    Now, your current question asks what to do if not all the points are known. This is known as unstructured data. All you have are a selection of points in a field. You can't necessarily construct rectangles where all vertices have known values. For this type of data, you can use (as you have) griddata, or a flavor of BivariateSpline.

    Now which to choose?

    The nearest analogy to the structured RectBivariateSpline is one of the unstructured BivariateSpline classes: SmoothBivariateSpline or LSQBivariateSpline. If you want to use splines to interpolate the data, go with these. this makes your function smooth and differentiable, but you can get a surface that swings outside Z.max() or Z.min().

    Since you are setting ky=1 and kx=1 and are getting what I am pretty sure is just linear interpolation on the structured data, I'd personally just switch from the RectBivariateSpline spline scheme to the interp2d structured grid interpolation scheme. I know the documentation says it is for regular grids, but the example in the __doc__ itself is only structured, not regular.

    I'd be curious if you found any significant differences between the methods if you do end up switching. Welcome to SciPy.

    0 讨论(0)
提交回复
热议问题