iris#
本节介绍如何使用 iris 加载 GRIB2 要素场,并使用 cedarkit-maps 绘图。
安装#
使用 conda 安装 iris 和 iris-grib
conda install -c conda-forge iris iris-grib
准备#
导入需要的包
import xarray as xr
import pandas as pd
import iris
设置绘图的数据参数,使用 CMA-MESO 2024 年 4 月 1 日 00 时次 024 时效数据。
system_name = "CMA-MESO"
data_type = "cma_meso_3km/grib2/orig"
start_time = pd.to_datetime("2024-04-01 00:00:00")
forecast_time = pd.to_timedelta("24h")
加载数据#
设置 GRIB2 数据文件路径
注:可以使用 reki 库查找本地文件路径
file_path = '/g3/COMMONDATA/OPER/CEMC/MESO_3KM/Prod-grib/2024040100/ORIG/rmf.hgra.2024040100024.grb2'
file_path
'/g3/COMMONDATA/OPER/CEMC/MESO_3KM/Prod-grib/2024040100/ORIG/rmf.hgra.2024040100024.grb2'
注:可以使用 reki 库查找本地文件路径
Show code cell source
from reki.data_finder import find_local_file
file_path_use_reki = find_local_file(
data_type,
start_time=start_time,
forecast_time=forecast_time,
)
file_path_use_reki
Show code cell output
PosixPath('/g3/COMMONDATA/OPER/CEMC/MESO_3KM/Prod-grib/2024040100/ORIG/rmf.hgra.2024040100024.grb2')
使用 iris 加载温度要素场
cubes = iris.load(file_path, "air_temperature")
print(cubes)
0: air_temperature / (K) (latitude: 1671; longitude: 2501)
1: air_temperature / (K) (latitude: 1671; longitude: 2501)
2: air_temperature / (K) (pressure: 21; latitude: 1671; longitude: 2501)
3: air_temperature / (K) (unknown: 4; latitude: 1671; longitude: 2501)
选择 2 米温度要素场
t_2m_cube = cubes[1]
t_2m_cube
Air Temperature (K) | latitude | longitude |
---|---|---|
Shape | 1671 | 2501 |
Dimension coordinates | ||
latitude | x | - |
longitude | - | x |
Scalar coordinates | ||
forecast_period | 24.0 hours | |
forecast_reference_time | 2024-04-01 00:00:00 | |
height | 2.0 m | |
time | 2024-04-02 00:00:00 | |
Attributes | ||
GRIB_PARAM | GRIB2:d000c000n000 |
将 iris.cube.Cube
转为 xarray.DataArray
t_2m_field = xr.DataArray.from_iris(t_2m_cube) - 273.15
t_2m_field
<xarray.DataArray 'air_temperature' (latitude: 1671, longitude: 2501)> Size: 33MB dask.array<sub, shape=(1671, 2501), dtype=float64, chunksize=(1671, 2501), chunktype=numpy.ndarray> Coordinates: * latitude (latitude) float64 13kB 60.1 60.07 ... 10.03 10.0 * longitude (longitude) float64 20kB 70.0 70.03 ... 145.0 145.0 forecast_period timedelta64[ns] 8B ... forecast_reference_time datetime64[ns] 8B ... height float64 8B ... time datetime64[ns] 8B ...
绘图#
使用 cedarkit-maps 绘制 2 米温度填充图
Show code cell source
from cedarkit.maps.style import ContourStyle
from cedarkit.maps.chart import Panel
from cedarkit.maps.domains import EastAsiaMapDomain
from cedarkit.maps.colormap import get_ncl_colormap
t_2m_level = [-24, -20, -16, -12, -8, -4, 0, 4, 8, 12, 16, 20, 24, 28, 32]
color_index = [2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 102, 112, 122, 132, 142, 152]
t_2m_color_map = get_ncl_colormap("BlAqGrYeOrReVi200", index=color_index)
t_2m_style = ContourStyle(
colors=t_2m_color_map,
levels=t_2m_level,
fill=True,
)
domain = EastAsiaMapDomain()
panel = Panel(domain=domain)
panel.plot(t_2m_field, style=t_2m_style)
domain.set_title(
panel=panel,
graph_name="2m Temperature (C)",
system_name=system_name,
start_time=start_time,
forecast_time=forecast_time,
)
domain.add_colorbar(panel=panel, style=t_2m_style)
panel.show()