我已经设法写了一个符合我的目的的函数。它通过沿网格线插值,然后在x和y方向插值平面,并取两者的平均值,从坐标网格中插值(填充)平面。在

通过将坐标重塑为一维矢量,一次性插值平面,然后再重新塑造为二维,应该可以稍微加快这一速度。但是,对于合理的平面尺寸来说,这个代码已经足够快了。在

如果坐标也在平面外,似乎也可以工作。

如果网格近似规则,则外推法也有效。不管怎样,它都会外推,但是随着栅格不规则度的增加,你会看到一些尖锐的折痕远离边缘。在

这是密码。docstring中提供了一个示例。在def interlin2d(x,y,z,fsize):

"""

Linear 2D interpolation of a plane from arbitrary gridded points.

:param x: 2D array of x coordinates

:param y: 2D array of y coordinates

:param z: 2D array of z coordinates

:param fsize: Tuple of x and y dimensions of plane to be interpolated.

:return: 2D array with interpolated plane.

This function works by interpolating lines along the grid point in both dimensions,

then interpolating the plane area in both the x and y directions, and taking the

average of the two. Result looks like a series of approximately curvilinear quadrilaterals.

Note, the structure of the x,y,z coordinate arrays are such that the index of the coordinates

indicates the relative physical position of the point with respect to the plane to be interpoalted.

Plane is allowed to be a subset of the range of grid coordinates provided.

Extrapolation is accounted for, however sharp creases will start to appear

in the extrapolated region as the grid of coordinates becomes increasingly irregular.

Scipy's interpolation function is used for the grid lines as it allows for proper linear extrapolation.

However Numpy's interpolation function is used for the plane itself as it is robust against gridlines

that overlap (divide by zero distance).

Example:

#set up number of grid lines and size of field to interpolate

nlines=[3,3]

fsize=(100,100,100)

#initialize the coordinate arrays

x=np.empty((nlines[0],nlines[1]))

y=np.empty((nlines[0],nlines[1]))

z=np.random.uniform(0.25*fsize[2],0.75*fsize[2],(nlines[0],nlines[1]))

#set random ordered locations for the interior points

spacings=(fsize[0]/(nlines[0]-2),fsize[1]/(nlines[1]-2))

for k in range(0, nlines[0]):

for l in range(0, nlines[1]):

x[k, l] = round(random.uniform(0, 1) * (spacings[0] - 1) + spacings[0] * (k - 1) + 1)

y[k, l] = round(random.uniform(0, 1) * (spacings[1] - 1) + spacings[1] * (l - 1) + 1)

#fix the edge points to the edge

x[0, :] = 0

x[-1, :] = fsize[1]-1

y[:, 0] = 0

y[:, -1] = fsize[0]-1

field = interlin2d(x,y,z,fsize)

"""

from scipy.interpolate import interp1d

import numpy as np

#number of lines in grid in x and y directions

nsegx=x.shape[0]

nsegy=x.shape[1]

#lines along the grid points to be interpolated, x and y directions

#0 indicates own axis, 1 is height (z axis)

intlinesx=np.empty((2,nsegy,fsize[0]))

intlinesy=np.empty((2,nsegx,fsize[1]))

#account for the first and last points being fixed to the edges

intlinesx[0,0,:]=0

intlinesx[0,-1,:]=fsize[1]-1

intlinesy[0,0,:]=0

intlinesy[0,-1,:]=fsize[0]-1

#temp fields for interpolation in x and y directions

tempx=np.empty((fsize[0],fsize[1]))

tempy=np.empty((fsize[0],fsize[1]))

#interpolate grid lines in the x direction

for k in range(nsegy):

interp = interp1d(x[:,k], y[:,k], kind='linear', copy=False, fill_value='extrapolate')

intlinesx[0,k,:] = np.round(interp(range(fsize[0])))

interp = interp1d(x[:, k], z[:, k], kind='linear', copy=False, fill_value='extrapolate')

intlinesx[1, k, :] = interp(range(fsize[0]))

intlinesx[0,:,:].sort(0)

# interpolate grid lines in the y direction

for k in range(nsegx):

interp = interp1d(y[k, :], x[k, :], kind='linear', copy=False, fill_value='extrapolate')

intlinesy[0, k, :] = np.round(interp(range(fsize[1])))

interp = interp1d(y[k, :], z[k, :], kind='linear', copy=False, fill_value='extrapolate')

intlinesy[1, k, :] = interp(range(fsize[1]))

intlinesy[0,:,:].sort(0)

#interpolate plane in x direction

for k in range(fsize[1]):

tempx[k, :] = np.interp(range(fsize[1]),intlinesx[0,:,k], intlinesx[1,:,k])

#interpolate plane in y direction

for k in range(fsize[1]):

tempy[:, k] = np.interp(range(fsize[0]), intlinesy[0, :, k], intlinesy[1, :, k])

return (tempx+tempy)/2

python2d 平滑插值处理_python中平滑的、通用的2D线性插值相关推荐

  1. python规则网格插值_Python中规则网格上的插值

    什么是合理的解决方案很大程度上取决于你试图用插值像素回答的问题--请注意清空器:对丢失的数据进行外推会导致非常误导的答案! 径向基函数插值/核平滑 就Python中可用的实际解决方案而言,填充这些像素 ...

  2. matlab contour光滑,使用Matplotlib在Contour Plot中平滑数据

    我正在使用Matplotlib创建轮廓图.我有所有的数据 在一个多维的数组中.这是12长约2000宽.所以它是 基本上是12个长度为2000的列表.我有等高线图 工作正常,但我需要平滑数据.我读了很多 ...

  3. spss三次指数平滑_选取SPSS中较优指数平滑预测模型的研究.doc

    选取SPSS中较优指数平滑预测模型的研究.doc 选取SPSS中较优指数平滑预测模型的研究 作者简介:张博文(1989-),男,汉族,山东日照人, 安徽理工大学经济与管理学院硕士研究生在读,专业:物流 ...

  4. python算法和数据结构_Python中的数据结构和算法

    python算法和数据结构 To 至 Leonardo da Vinci 达芬奇(Leonardo da Vinci) 介绍 (Introduction) The purpose of this ar ...

  5. [FormulaExcelPython] 一次指数平滑、二次指数平滑、三次指数平滑(Holt-Winters)...

    指数平滑由移动平均发展而来,和指数移动平均有点相似,也可认为是一种特殊的加权移动平均.按平滑的次数,指数平滑可分为一次指数平滑.二次指数平滑.三次指数平滑.移动平均除了简单预测外另在股市中作为支撑线发 ...

  6. 指数平滑方法(一次指数平滑、二次指数平滑、三次指数平滑):理论、代码、参数 介绍(全)

    @创建于:20210324 @修改于:20210324 文章目录 特别说明 参考来源 包版本号 1.简介 2.一次指数平滑 2.1 理论介绍 2.2 代码展示 2.3 参数介绍 3. 二次指数平滑 3 ...

  7. 一文速学数模-时序预测模型(四)二次指数平滑法和三次指数平滑法详解+Python代码实现

    目录 前言 二次指数平滑法(Holt's linear trend method) 1.定义 2.公式 二次指数平滑值: 二次指数平滑数学模型: 3.案例实现 三次指数平滑法(Holt-Winters ...

  8. 贝叶斯滤波和贝叶斯平滑(Kalman滤波,RTS平滑)

    文章目录 贝叶斯滤波(*Bayesian filtering equations*) 贝叶斯滤波方程 Kalman滤波 贝叶斯平滑(*Bayesian smoothing*) 贝叶斯最优平滑方程 Ra ...

  9. matlab sglay平滑,基于MATLABGUI的谱线平滑处理.PDF

    基于MATLABGUI的谱线平滑处理 第41 卷 第6 期 核 技 术 Vol.41, No.6 2018 年6 月 NUCLEAR TECHNIQUES June 2018 基于MATLAB GUI ...

最新文章

  1. 互联网+”时代,如何实现高效协同移动办公?
  2. PCA图像数据降维及重构误差分析实战并使用TSNE进行异常数据可视化分析
  3. php多维数组和对象,在PHP中将多维多对象数组转换为标准多维数组
  4. java语言程序设计你_清华大学出版社-图书详情-《Java语言程序设计》
  5. SPOJ - COT Count on a tree(LCA+主席树+离散化)
  6. Python 第三方库之 Celery 分布式任务队列
  7. 我的《野蛮生长》书摘
  8. linux缓冲区攻击实验报告,linux 下缓冲区溢出攻击原理及示例
  9. 学java什么书好?推荐几本Java开发的书
  10. 在一个IPython Notebook单元中显示多个图像?
  11. PC建立WIFI热点
  12. 超强OCR文字识别软件首选ABBYY FineReader
  13. AutoRunner 功能自动化测试项目实训之AutoRunner的下载安装(十九)
  14. 软考(中级软件设计师)考试信息
  15. C#——初识Console
  16. 关于TAA SMAA
  17. STM32硬件I2C的一点心得(AT24C32C和AT24C64C)
  18. HttpClient详细使用示例
  19. 特权容器以及安全隐患的规避
  20. 小米应用商店支持 64 位架构适配

热门文章

  1. 精读linux源码,Linux基础入门的操作精读.doc
  2. android收入管理系统,毕业设计(论文)-基于Android系统的家庭理财通软件的设计——收入管理模块.docx...
  3. 转:有关常量的知识点
  4. uboot源码——内核启动分析
  5. C# 委托 / 跨线程访问UI / 线程间操作无效: 从不是创建控件“Form1”的线程访问它...
  6. WPS Office文档未保存怎么恢复
  7. jQuery验证validate插件
  8. google Chrome 浏览器源码地址地址!
  9. CPU是如何访问到内存的?
  10. C/C++函数指针与指针函数