我有高斯坐标数据。我相信我已经成功地将高斯坐标转换为可以在 cartopy 中绘制的纬度/经度坐标。但是,绘制时数据看起来不正确,我不确定为什么。我使用的数据是云托管的,所以我可以共享整个代码和数据集。
import xarray as xr
import pandas as pd
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
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',
step = '3600000000000'
)['tp']
sl_forecasts['values'] = pd.MultiIndex.from_arrays(
[sl_forecasts.longitude.values,sl_forecasts.latitude.values],
names=['longitude', 'latitude']
)
sl_forecasts = sl_forecasts.unstack('values')
proj = ccrs.PlateCarree()
fig, ax = plt.subplots(figsize=(10, 8), subplot_kw=dict(projection=proj))
tp_plot = ax.contourf(
sl_forecasts.values,
cmap='jet'
)
ax.coastlines()
这是绘制时数据的样子
这有帮助吗?
import cartopy.crs as crs
import matplotlib.pyplot as plt
import numpy as np
# Set up the projection
lon_0 = -75.0 # central longitude of projection
proj = crs.LambertConformal(globe=None, central_longitude=lon_0)
# Set up the latitude and longitude arrays in radians
nlats, nlons = 73, 144
lats = np.linspace(-np.pi/2, np.pi/2, nlats)
lons = np.linspace(0, 2*np.pi, nlons)
lons, lats = np.meshgrid(lons, lats)
x, y = proj.transform_points(crs.PlateCarree(), lons, lats)[:2]
# Set up the data
data = np.sin(lats)**10 + np.cos(10 + lons*lats) * np.cos(lats)
# Plot the data
fig, ax = plt.subplots(subplot_kw={'projection': proj})
im = ax.pcolormesh(x, y, data, cmap='viridis')
ax.coastlines()
fig.colorbar(im, ax=ax, shrink=0.6)
plt.show()