簡體   English   中英

python中的插值結果向右旋轉90度

[英]Interpolation result in python is rotated 90 degrees to the right

我在 python 中使用 rbf 構造了一個插值代碼並遵循了本教程 更准確地說,代碼顯示在 04:57。

import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
import pylab as py
import scipy

token = open('Ydata_48_of_50.txt','r')
linestoken=token.readlines()
tokens_column_numberX = 0
tokens_column_numberY = 1
tokens_column_numberF = 2

resulttokenX=[]
resulttokenY=[]
resulttokenF=[]
for x in linestoken:
    resulttokenX.append(x.split()[tokens_column_numberX])
    resulttokenY.append(x.split()[tokens_column_numberY])
    resulttokenF.append(x.split()[tokens_column_numberF])
token.close()

resulttokenX2 = np.array(resulttokenX)
resulttokenY2 = np.array(resulttokenY)
resulttokenF2 = np.array(resulttokenF)    
newfunc=interpolate.Rbf(resulttokenX2.astype('float'), resulttokenY2.astype('float'), resulttokenF2.astype('float'), function='multiquadric')
    xnew, ynew=np.mgrid[340:350:100j, 23:32:100j]
    fnew=newfunc(xnew, ynew)
    
    #create image plot
    py.figure(1)
    py.clf()
    py.imshow(fnew, extent=[340, 350, 23, 32], cmap=py.cm.jet)

上面的代碼是我的程序示例。 結果可以在這張圖片中看到代碼輸出

不幸的是,我做錯了什么。 生成的插值看起來應該像上一張圖像的 90 度轉彎。 結果應該是什么

我試圖改變 np. np.mgrid但我還沒有找到任何返回我想要的組合。 請注意,我正在處理緯度和經度。 我的原始數據中有 19 個緯度值和 21 個經度值。

對可能發生的事情有任何想法嗎?

最后,我設法通過結合使用翻轉列表和更改軸來“修復”此問題。 這是代碼:

import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
import pylab as py
import scipy

token = open('Ydata_48_of_50.txt','r')
linestoken=token.readlines()
tokens_column_numberX = 0
tokens_column_numberY = 1
tokens_column_numberF = 2

resulttokenX=[]
resulttokenY=[]
resulttokenF=[]
for x in linestoken:
    resulttokenX.append(x.split()[tokens_column_numberX])
    resulttokenY.append(x.split()[tokens_column_numberY])
    resulttokenF.append(x.split()[tokens_column_numberF])
token.close()


resulttokenXflip=resulttokenX[::-1]
resulttokenYflip=resulttokenY[::-1]
resulttokenFflip=resulttokenF[::-1]

resulttokenX2 = np.array(resulttokenX)
resulttokenX2flip = np.array(resulttokenXflip)

resulttokenY2 = np.array(resulttokenY)
resulttokenY2flip = np.array(resulttokenYflip)

resulttokenF2 = np.array(resulttokenF)
resulttokenF2flip = np.array(resulttokenFflip)

#El error tiene que venir del hecho de que Y2 está definida de menor a mayor

len(resulttokenX2)

newfunc=scipy.interpolate.Rbf(resulttokenY2flip.astype('float'), resulttokenX2.astype('float'), resulttokenF2.astype('float'), function='linear')
xnew, ynew=np.mgrid[ 23:32:90j, 340:350:100j]
fnew=newfunc(xnew, ynew)

#create image plot
py.figure(1)
py.clf()
py.imshow(fnew, extent=[ 340, 350, 23,32], cmap=py.cm.jet)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM