在 cartopy 中绘制高斯网格数据

问题描述 投票:0回答:0

我有一个带有网格化数据的 xarray 数据集。使用另一个线程How to reshape xarray data with new dimensions 我能够成功地将纬度和经度坐标转换为维度,但是我遇到的问题是绘制数据。

似乎数据的值不符合数据集的新维度和形状,因为大多数值在我重塑数据集后变成了 nan。

    import xarray as xr

sl_forecasts = xr.open_zarr(
    'gs://gcp-public-data-arco-era5/co/single-level-forecast.zarr/', 
    chunks={'time': 48},
    consolidated=True,
)

sl_forecasts = sl_forecasts.sel(time = '2021-02-27T06:00:00.000000000')

sl_forecasts = sl_forecasts.sel(step = '3600000000000')

sl_forecasts = sl_forecasts['tp']

import pandas as pd

index = pd.MultiIndex.from_arrays(
    [sl_forecasts.longitude.values,sl_forecasts.latitude.values], names=['longitude', 'latitude']
)
sl_forecasts['values'] = index
sl_forecasts = sl_forecasts.unstack('values')

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
proj = ccrs.PlateCarree()
fig, ax = plt.subplots(figsize=(10, 8), subplot_kw=dict(projection=proj))

tp = sl_forecasts.values
lon = sl_forecasts['longitude'].values
lat = sl_forecasts['latitude'].values
ax.coastlines()
tp_plot = ax.contourf(lon, lat, tp, transform=proj, cmap='Blues')
python reshape python-xarray cartopy
© www.soinside.com 2019 - 2024. All rights reserved.