无法让 scipy.interpolate.RBFInterpolator 工作

问题描述 投票:0回答:0

我正在尝试在 2D 网格上插入散点数据,但似乎无法使 RBF 函数起作用。我收到有关输入但没有输出的错误消息。

总的来说,我是 Python 的新手,meshgrid 函数对我来说也有点混乱,所以我在该领域的使用也可能存在问题。

import os
import matplotlib.pyplot as plt
from scipy.interpolate import RBFInterpolator
import numpy as np
import json

def main():

    file_path="C:/rawdata/"
    files=os.listdir(file_path)

    for filename in files:
        #open file and load data
        if filename.endswith(".json"):
            jfile=open(file_path+filename, 'r')
            global jdata
            jdata=json.load(jfile)

            #get meta data
            width_m=int(round(float(jdata["WidthMm"])/1000))
            length_m=int(round(float(jdata["LengthM"])))

            #create empty lists           
            x=[0,1,2,3,4,5]
            y=[]
            z=[]

            #populate lists
            for items in jdata["OnlineScans"]:                                                  
                type_str=items["Type"]

                if type_str!="Weight":
                    continue

                for keys in items["Scans"]:
                    y_point=int(round(float(keys)))
                    y.append(y_point)

                    for r in items["Scans"][keys]:
                        z.append(int(round(float(r))))

    #printer(x,y,z)
    interpol(x,y,z,length_m,width_m)


#interpolate data on the total surface (length x width)
#store interpolated data in new array
def interpol(x,y,z,length_m,width_m):
    
    X, Y = np.meshgrid(x, y)
    rbf = RBFInterpolator(x, y, z)
    Z = rbf(X, Y)

    plt.pcolor(X, Y, Z)
    plt.tight_layout()
    plt.show()


def printer(x,y,z):
    
    X, Y = np.meshgrid(x, y)

    plt.scatter(X,Y)
    plt.tight_layout()
    plt.show()

main()

任何帮助表示赞赏。

根据我提供的输入,我会收到错误消息,例如:

Programs\Python\Python310\lib\site-packages\scipy\interpolate_rbfinterp.py",第 293 行,在 init raise ValueError("

y
必须是二维数组。") ValueError:
y
必须是二维数组。

python interpolation
© www.soinside.com 2019 - 2024. All rights reserved.