I have constructed an interpolation code using rbf in python and following
Unfortunately, I am doing something wrong. The resulting interpolation should look like a 90 degree turn of the previous image.
I have tried to alter the values of np.np.mgrid
but I haven't found any combination which returns what I want. Note that I am working with latitudes and longitudes. I have 19 values of latitude and 21 of longitude in my original data.
Any idea on what might be going on?
CodePudding user response:
In the end, I have managed to "fix" this by using a combination of flipped lists and changing the axis. This is the code:
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)