如何使用Metpy.interpaly从一组数据中插值温度

发布于 2025-01-31 23:44:46 字数 654 浏览 3 评论 0原文

我正在尝试使用CartopyMetpy.interpaly生成地图,我希望最终产品与下面的图片相似从ndawn网站拍摄的图像。我有一组具有坐标和温度的数据(LAT,LON,TEMP):

lat:[49.8134,49.8134,49.8134,49.8134,49.8134,49.8134,49.8134,49.8134, 49.8134,49.8134,49.8134]

lon:[-100.3721,-100.3721,-100.3721,-100.3721,-100.3721, -100.3721,-100.3721,-100.3721,-100.3721,-100.3721]

tem:[-8.45,-4.026,-5.993,-3.68,-7.35,-7.421,-6.477,-8.03,-8.03, -3.834,-13.04]

我正在尝试插入温度并使用Contourf将其抽出。但是,我不知道如何使用Metpy的插值函数将它们插入。有人可以帮忙吗?

I'm trying to generate a map using cartopy and metpy.interpolate, and I want the final products to be similar to this picture below Image taken from NDAWN website. I have a set of data with coordinate and temperature (lat, lon, temp):

lat: [49.8134, 49.8134, 49.8134, 49.8134, 49.8134, 49.8134, 49.8134,
49.8134, 49.8134, 49.8134]

lon: [-100.3721, -100.3721, -100.3721, -100.3721, -100.3721,
-100.3721, -100.3721, -100.3721, -100.3721, -100.3721]

tem: [-8.45, -4.026, -5.993, -3.68, -7.35, -7.421, -6.477, -8.03,
-3.834, -13.04]

I'm trying to interpolate the temperature and use contourf to draw it out. However, I have no idea how to interpolate them using metpy's interpolation function. Can someone please help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独享拥抱 2025-02-07 23:44:46

这是一个例子。我必须从上面更改LAT/LON值,因为这是一个仅在上面重复的点(您无法插入

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import metpy.interpolate as minterp
from metpy.plots import StationPlot
import numpy as np

# Generate some locations for the data--originals were a single point
tem = np.array([-8.45, -4.026, -5.993, -3.68, -7.35, -7.421,
                -6.477, -8.03, -3.834, -13.04])
lat = 49 + np.random.rand(len(tem))
lon = -100 - np.random.rand(len(tem))

# Interpolating directly on the sphere with lat/lon is problematic
# so interpolate to a grid on a LambertConformal projection
proj = ccrs.LambertConformal(central_latitude=49, central_longitude=-100)
x, y, _ = proj.transform_points(ccrs.PlateCarree(), lon, lat).T

# Interpolate to a grid with 5km spacing
x_grid, y_grid, tem_grid = minterp.interpolate_to_grid(x, y, tem, interp_type='barnes',
                                                       hres=5000)

# Create figure
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(1, 1, 1, projection=proj)

# Contourf plot
ax.contourf(x_grid, y_grid, tem_grid)

# Use MetPy's StationPlot to plot the text values
sp = StationPlot(ax, x, y, transform=proj, fontsize=16)
sp.plot_parameter('C', tem)

# Show grid locations
ax.scatter(x_grid, y_grid)

的插件:

“带有填充轮廓和文本图的示例图像”

有关更多信息,我建议您查找更多信息at 在METPY文档中此示例

的,因为间距不相等

M从LAT/LON中转换为LAT/LON,因为用度插值是有问题 在调用transform_points()的调用中,使用platecarree()是您与造型的传达方式,所给出的坐标为LON/LAT坐标。

Here's an example. I had to change the lat/lon values from above since that is a single point only repeated above (which you can't interpo

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import metpy.interpolate as minterp
from metpy.plots import StationPlot
import numpy as np

# Generate some locations for the data--originals were a single point
tem = np.array([-8.45, -4.026, -5.993, -3.68, -7.35, -7.421,
                -6.477, -8.03, -3.834, -13.04])
lat = 49 + np.random.rand(len(tem))
lon = -100 - np.random.rand(len(tem))

# Interpolating directly on the sphere with lat/lon is problematic
# so interpolate to a grid on a LambertConformal projection
proj = ccrs.LambertConformal(central_latitude=49, central_longitude=-100)
x, y, _ = proj.transform_points(ccrs.PlateCarree(), lon, lat).T

# Interpolate to a grid with 5km spacing
x_grid, y_grid, tem_grid = minterp.interpolate_to_grid(x, y, tem, interp_type='barnes',
                                                       hres=5000)

# Create figure
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(1, 1, 1, projection=proj)

# Contourf plot
ax.contourf(x_grid, y_grid, tem_grid)

# Use MetPy's StationPlot to plot the text values
sp = StationPlot(ax, x, y, transform=proj, fontsize=16)
sp.plot_parameter('C', tem)

# Show grid locations
ax.scatter(x_grid, y_grid)

which yields:

Sample image with filled contours and text plot

For more information I'd suggest looking at this example in the MetPy documentation.

EDIT: I'm transforming the coordinates from lat/lon in degrees because interpolating with degrees is problematic since the spacing isn't equal. So I transform to a projected coordinate system, which gives us an even spacing and I can request the grid spacing of 5km.

The use of PlateCarree() in the call to transform_points() is how you communicate to Cartopy that the coordinates being given are lon/lat coordinates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文