【问题标题】:Spatial interpolation of discrete points onto x/y coordinate mesh grid in PythonPython中离散点在x/y坐标网格上的空间插值
【发布时间】:2021-11-13 03:12:36
【问题描述】:

我对编程和尝试使用 Cartopy 创建整个夏威夷的碱度等值线图还是很陌生。我需要根据 x-y 网格对名为 MODIFIED_TA 的点值进行插值,但无法弄清楚如何执行此操作。我使用的代码是:

import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
import cartopy.mpl.ticker as cticker
import statistics
from scipy.interpolate import UnivariateSpline
import numpy as np
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import warnings

warnings.filterwarnings("ignore") # ignoring the warning prompts.

%matplotlib inline

fig = plt.figure(figsize=(15,15))

ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(central_longitude=-170))

landgreen = cfeature.NaturalEarthFeature('physical', 'land', '110m', 
                                        edgecolor='face', facecolor='green')


oceanaqua = cfeature.NaturalEarthFeature('physical', 'ocean', '110m', 
                                       edgecolor='face', facecolor='aqua')


ax.set_extent([-151.5, -162, 18, 24], ccrs.PlateCarree())
ax.set_title('TOTAL ALKALINITY')
ax.add_feature(landgreen)
ax.add_feature(cfeature.OCEAN, color = 'k')
ax.gridlines(draw_labels=True)


lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.grid(linewidth=2, color='black', alpha=0.5, linestyle='--')


lons = all_data.LONGITUDE[:]
lats = all_data.LATITUDE[:]
alk = all_data.MODIFIED_TA[:]
x1,y1 = np.meshgrid(lons,lats)
z1,z2 = np.meshgrid(all_data.MODIFIED_TA,all_data.MODIFIED_TA)


plt.tricontourf(lons,lats,alk, transform=ccrs.PlateCarree(), cmap=cm.gist_rainbow)
plt.colorbar(shrink=0.5)
plt.title('$A_{T}$ VALUES', color = 'k', fontname='Times New Roman',size = 23)

plt.plot()

结果与我所希望的完全不同,而且我不知道如何插入这个值,使其在 x/y 坐标网格上呈现为平滑渐变。任何帮助将不胜感激!

See output here

【问题讨论】:

    标签: python interpolation cartopy contourf discrete


    【解决方案1】:

    如果不能看到您的数据,就很难确定。我试图创建一个MRE,它成功了。我会先看看这是否有效。

    import cartopy.feature as cfeature
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    import cartopy.mpl.ticker as cticker
    import numpy as np
    from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
    
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(central_longitude=-170))
    
    ax.set_extent([-151.5, -162, 18, 24], ccrs.PlateCarree())
    ax.add_feature(cfeature.OCEAN)
    ax.gridlines(draw_labels=True)
    
    
    lon_formatter = cticker.LongitudeFormatter()
    lat_formatter = cticker.LatitudeFormatter()
    ax.xaxis.set_major_formatter(lon_formatter)
    ax.yaxis.set_major_formatter(lat_formatter)
    ax.grid(linewidth=2, color='black', alpha=0.5, linestyle='--')
    
    lons = np.random.random(80) * 7 - 160
    lats = np.random.random(80) * 4 + 19
    alk = np.cos(lons * 10 * np.pi / 180) * np.sin(lats * 20 / 180)
    
    plt.plot(lons, lats, 'k.', transform = ccrs.PlateCarree())
    plt.tricontourf(lons,lats,alk, transform=ccrs.PlateCarree(), alpha = 0.5)
    plt.colorbar(shrink=0.5)
    plt.title('$A_{T}$ VALUES', color = 'k', fontname='Times New Roman',size = 23)
    

    如果它确实有效,那么我会看的内容包括:

    • all_data.LONGITUDEall_data.LATITUDEall_data.MOTIFIED_TA的尺寸是多少?
    • 是否存在重复值?
    • 在投影之外绘制它是否有效?

    如果我的示例不起作用,则表明您的安装存在问题,在这种情况下,如果可以,请更新它。如果问题仍然存在,可能是存在需要报告的错误cartopy 或与其他包冲突。

    对不起,我不能再帮忙了。

    【讨论】:

    • 谢谢!!我能够让它工作。与此同时,我最终在设置数据插值循环时获得了一些帮助,并且能够在此过程中重新网格化数据集,并将插值结果映射到 Cartopy 网格上。此外,我能够获得您发送运行的示例,没有任何问题,并且肯定会参考它以供将来参考。非常感谢您的帮助!
    猜你喜欢
    • 2013-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多