【发布时间】:2021-06-15 12:14:23
【问题描述】:
自学 MetPy 中的声明式绘图功能,并不断遇到困难。这来自于在通过 xarray/cfgrib 打开后尝试将声明性绘图包应用于 grib2 文件。数据看起来健康,但实际温度数据似乎没有被传递和绘制。当我绘制它时,我得到一张空白地图。
我有下面的压缩代码,以及一些数据检查的打印输出,以表明数据似乎正常。
我错过了什么吗? (我确定我是,但我想知道什么?)
谢谢!
import matplotlib.pyplot as plt
import xarray as xr
import numpy as np
import pygrib
import cartopy.crs as ccrs
import cartopy.feature as cfeat
import cartopy
from datetime import datetime, timedelta
import io
from metpy.units import units
from metpy.plots import ImagePlot, MapPanel, PanelContainer
##Open GFS grib2 file, initialized 2021060700, and pull data from hPa level designation.
ds = xr.open_dataset('/fewxops/Tom/learn_python/data/grib2/gfs.t00z.pgrb2.0p25.f024', engine='cfgrib', filter_by_keys={'typeOfLevel': 'isobaricInhPa'})
##Select individual level (from designated 'type of level')
ds_z500=ds.sel(isobaricInhPa=500)
##Create base image via MetPy
img = ImagePlot()
img.data = ds_z500
img.field = 't'
img.colormap = 'plasma'
#Create map panel (e.g. subplot in matplotlib)
panel = MapPanel()
panel.area = 'us'
#panel.layers = ['states']
panel.title = 'GFS 500mb Temp Forecast Example'
panel.plots = [img]
##Create panel container (e.g. figure in matplotlib)
pc = PanelContainer()
pc.size = (10,8)
pc.panels = [panel]
pc.show()
*******************************
home/fewx/anaconda3/lib/python3.8/site-packages/metpy/xarray.py:349: UserWarning: More than one time coordinate present for variable "t".
warnings.warn('More than one ' + axis + ' coordinate present for variable'
Found valid latitude/longitude coordinates, assuming latitude_longitude for projection grid_mapping variable
print(ds_z500)
<xarray.Dataset>
Dimensions: (latitude: 721, longitude: 1440)
Coordinates:
time datetime64[ns] ...
step timedelta64[ns] ...
isobaricInhPa float64 500.0
* latitude (latitude) float64 90.0 89.75 89.5 ... -89.5 -89.75 -90.0
* longitude (longitude) float64 0.0 0.25 0.5 0.75 ... 359.2 359.5 359.8
valid_time datetime64[ns] ...
Data variables:
gh (latitude, longitude) float32 ...
t (latitude, longitude) float32 ...
r (latitude, longitude) float32 ...
q (latitude, longitude) float32 ...
w (latitude, longitude) float32 ...
wz (latitude, longitude) float32 ...
u (latitude, longitude) float32 ...
v (latitude, longitude) float32 ...
absv (latitude, longitude) float32 ...
o3mr (latitude, longitude) float32 ...
Attributes:
GRIB_edition: 2
GRIB_centre: kwbc
GRIB_centreDescription: US National Weather Service - NCEP
GRIB_subCentre: 0
Conventions: CF-1.7
institution: US National Weather Service - NCEP
history: 2021-06-15T08:05 GRIB to CDM+CF via cfgrib-0.9.9...
print(ds_z500['t'].values)
[[245.93057 245.93057 245.93057 ... 245.93057 245.93057 245.93057]
[245.85057 245.84056 245.84056 ... 245.85057 245.85057 245.85057]
[245.72057 245.72057 245.71057 ... 245.73056 245.73056 245.72057]
...
[226.94057 226.94057 226.94057 ... 226.94057 226.94057 226.94057]
[226.96057 226.96057 226.96057 ... 226.96057 226.96057 226.96057]
[226.88057 226.88057 226.88057 ... 226.88057 226.88057 226.88057]]
【问题讨论】: