使用光滑双变量花键插值
我正在使用python来完成我的硕士项目。当我是一个初学者和一个人学习时,我在完成老师提出的任务时发现了一些困难。
特定问题是:
我有Excel提供的水温数据,与其位置相关(纬度,纵向)。该任务的目的是准备一个Ineline Map,但首先,由于数据是有限的,因此我需要插入以获取更多值。为此,我使用光滑的双变量花键功能。
然而,由于最终结果(一旦创建了插值和轮廓图创建),我获得了一个地图,边界给我没有任何意义的温度值(120 ..-90ºC),因为我的数据温度在围绕围绕25ºC。(对不起,但是网页不允许我添加图)。
在这里,我附上了我使用的命令。如果有人能告诉我命令中有什么问题,如果有必要添加其他内容,或者还有另一种选择更适合我的问题:我将非常感谢:
#Loading packages:
import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
from scipy import interpolate
# Temperature and positions of the measurements
EstadisticosFluorimetro = pd.read_excel("C:\\Users\\usuario\\Desktop\\TFM\\Datos Partida\\CTD_Fluorimetro_IRTA\\Resumen_Puntos_Fluorimetro.xlsx", sheet_name = "Res_Python")
temperatura_Med = EstadisticosFluorimetro['T_Media']
latitudes = EstadisticosFluorimetro['Lat_Punto']
longitudes = EstadisticosFluorimetro['Long_Punto']
# I also load the coast line corresponding to the study zone
ContornoCosta = pd.read_excel("C:\\Users\\usuario\\Desktop\\Isolineas\\Límite Costero\\Posiciones_Límites.xlsx", sheet_name = "Contorno_Costa")
latitudes_costa = ContornoCosta['Latitud']
longitudes_costa = ContornoCosta['Longitud']
# Apply Interpolation by using the Smooth Bivariate Splines function:
# I have defined at bbox the boundaries of the grid where I want to get values interpolated,
# according to min, max longitudes and min, max latitudes of the grid.
interpolación = interpolate.SmoothBivariateSpline(longitudes,latitudes,temperatura_Med, bbox=[0.7285, 0.7415, 40.7675, 40.781], kx=3, ky=3)
# Then, I want the values of temperature according to the grid that I define:
longitudes_grid = np.linspace(0.7285,0.7415,1000)
latitudes_grid = np.linspace(40.7675,40.781,1000)
temperatura_imagen=interpolación.__call__(longitudes_grid,latitudes_grid,grid=True)
# Now I create the figure:
# First, text characteristics:
fontTitle = {'family': 'serif',
'color': 'black',
'weight': 'normal',
'size': 16,
'style': 'italic',
}
fontAxis = {'family': 'serif',
'color': 'black',
'weight': 'normal',
'size': 10,
'style': 'oblique',
}
# Then, I plot in a same figure the coast contour and the isolines:
plot1 = plt.figure(1)
# First, the coast contour:
plt.plot(longitudes_costa,latitudes_costa,color='black', linewidth=1)
# And then the isolines:
plt.contour(longitudes_grid, latitudes_grid, temperatura_imagen, levels=25, linewidths=0.5, colors='k')
cntr1 = plt.contourf(longitudes_grid, latitudes_grid, temperatura_imagen, levels=25, cmap="Jet")
# The labels:
plt.xlabel('Longitud,º', fontsize=12, fontdict=fontAxis, labelpad=10)
plt.ylabel('Latitud, º', fontsize=12, fontdict=fontAxis, labelpad=10)
plt.title('Isolineas Temperatura Media', fontsize=18, fontdict=fontTitle, pad=10)
# I adjust the contours of the figure:
plt.ylim(40.765,40.785)
plt.xlim(0.725,0.745)
plt.colorbar()
# And the size:
plot1.set_figheight(6)
plot1.set_figwidth(12)
plt.show
I'm using Python in order to do my Master's Project. As I'm a beginner and learning by myself, there are some difficulties that I found while doing the tasks proposed by my teachers.
The particular problem is the following:
I have water temperature data provided by an excel, associated to its locations (latitude, longitudes). The objective of the task is to prepare an isolines map, but first of all, as the data is limited, I need to interpolate in order to get more values. In order to do that I use the Smooth Bivariate Splines function.
Nevertheless, as the final result (once interpolation and contour map creation have been created), I obtain a map where the boundaries give me values of temperature that have no sense (120.. -90 º C), since my data temperature oscilates around 25 º C. (Sorry ,but the webpage doesn't let me add the figure)
Here I attach the commands that I've used. I would appreciate very much if someone can tell me what it's wrong in the commands, if its necessary to add something else or maybe there is another alternative that fits better to my problem:
#Loading packages:
import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
from scipy import interpolate
# Temperature and positions of the measurements
EstadisticosFluorimetro = pd.read_excel("C:\\Users\\usuario\\Desktop\\TFM\\Datos Partida\\CTD_Fluorimetro_IRTA\\Resumen_Puntos_Fluorimetro.xlsx", sheet_name = "Res_Python")
temperatura_Med = EstadisticosFluorimetro['T_Media']
latitudes = EstadisticosFluorimetro['Lat_Punto']
longitudes = EstadisticosFluorimetro['Long_Punto']
# I also load the coast line corresponding to the study zone
ContornoCosta = pd.read_excel("C:\\Users\\usuario\\Desktop\\Isolineas\\Límite Costero\\Posiciones_Límites.xlsx", sheet_name = "Contorno_Costa")
latitudes_costa = ContornoCosta['Latitud']
longitudes_costa = ContornoCosta['Longitud']
# Apply Interpolation by using the Smooth Bivariate Splines function:
# I have defined at bbox the boundaries of the grid where I want to get values interpolated,
# according to min, max longitudes and min, max latitudes of the grid.
interpolación = interpolate.SmoothBivariateSpline(longitudes,latitudes,temperatura_Med, bbox=[0.7285, 0.7415, 40.7675, 40.781], kx=3, ky=3)
# Then, I want the values of temperature according to the grid that I define:
longitudes_grid = np.linspace(0.7285,0.7415,1000)
latitudes_grid = np.linspace(40.7675,40.781,1000)
temperatura_imagen=interpolación.__call__(longitudes_grid,latitudes_grid,grid=True)
# Now I create the figure:
# First, text characteristics:
fontTitle = {'family': 'serif',
'color': 'black',
'weight': 'normal',
'size': 16,
'style': 'italic',
}
fontAxis = {'family': 'serif',
'color': 'black',
'weight': 'normal',
'size': 10,
'style': 'oblique',
}
# Then, I plot in a same figure the coast contour and the isolines:
plot1 = plt.figure(1)
# First, the coast contour:
plt.plot(longitudes_costa,latitudes_costa,color='black', linewidth=1)
# And then the isolines:
plt.contour(longitudes_grid, latitudes_grid, temperatura_imagen, levels=25, linewidths=0.5, colors='k')
cntr1 = plt.contourf(longitudes_grid, latitudes_grid, temperatura_imagen, levels=25, cmap="Jet")
# The labels:
plt.xlabel('Longitud,º', fontsize=12, fontdict=fontAxis, labelpad=10)
plt.ylabel('Latitud, º', fontsize=12, fontdict=fontAxis, labelpad=10)
plt.title('Isolineas Temperatura Media', fontsize=18, fontdict=fontTitle, pad=10)
# I adjust the contours of the figure:
plt.ylim(40.765,40.785)
plt.xlim(0.725,0.745)
plt.colorbar()
# And the size:
plot1.set_figheight(6)
plot1.set_figwidth(12)
plt.show
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论