风场图

风场图#

本节介绍如何使用 cedarkit-maps 绘制 850 hPa 风场图。

首先导入需要使用的包。包括:

  • 数据结构:numpy, pandas

  • 可视化:matplotlib

  • cedarkit 工具套件

    • 数据准备:reki

      • 数据查找函数: find_local_file

      • GRIB2文件要素加载函数:load_field_from_file

    • 气象可视化:cedarkit.maps

      • 绘图板:Panel

      • 底图布局:EastAsiaMapDomain

      • 绘图样式:BarbStyle

import pandas as pd

from reki.data_finder import find_local_file
from reki.format.grib.eccodes import load_field_from_file

from cedarkit.maps.style import BarbStyle
from cedarkit.maps.chart import Panel
from cedarkit.maps.domains import EastAsiaMapDomain

设置绘图的数据参数,使用 CMA-GFS 2024 年 4 月 1 日 00 时次 024 时效数据。

system_name = "CMA-GFS"
data_type = "cma_gfs_gmf/grib2/orig"
start_time = pd.to_datetime("2024-04-01 00:00:00")
forecast_time = pd.to_timedelta("24h")

加载数据#

获取 GRIB2 数据路径

file_path = find_local_file(
    data_type,
    start_time=start_time,
    forecast_time=forecast_time,
)
file_path
PosixPath('/g3/COMMONDATA/OPER/CEMC/GFS_GMF/Prod-grib/2024040100/ORIG/gmf.gra.2024040100024.grb2')

加载 850 hPa 风场。风场在 ecCodes 的内置要素名为 uv

u_850_field = load_field_from_file(
    file_path,
    parameter="u",
    level_type="pl",
    level=850
)
v_850_field = load_field_from_file(
    file_path,
    parameter="v",
    level_type="pl",
    level=850
)
v_850_field
<xarray.DataArray 'v' (latitude: 1440, longitude: 2880)> Size: 33MB
array([[ 8.80414551,  8.79414551,  8.77414551, ...,  8.83414551,
         8.82414551,  8.81414551],
       [ 7.98414551,  7.97414551,  7.95414551, ...,  8.02414551,
         8.00414551,  7.99414551],
       [ 7.62414551,  7.61414551,  7.59414551, ...,  7.66414551,
         7.65414551,  7.63414551],
       ...,
       [-5.68585449, -5.69585449, -5.70585449, ..., -5.69585449,
        -5.68585449, -5.68585449],
       [-5.25585449, -5.26585449, -5.26585449, ..., -5.27585449,
        -5.25585449, -5.24585449],
       [-4.25585449, -4.25585449, -4.25585449, ..., -4.25585449,
        -4.24585449, -4.24585449]])
Coordinates:
    time        datetime64[ns] 8B 2024-04-01
    step        timedelta64[ns] 8B 1 days
    valid_time  datetime64[ns] 8B 2024-04-02
    pl          float64 8B 850.0
  * latitude    (latitude) float64 12kB 89.94 89.81 89.69 ... -89.81 -89.94
  * longitude   (longitude) float64 23kB 0.0 0.125 0.25 ... 359.6 359.8 359.9
Attributes: (12/17)
    GRIB_edition:             2
    GRIB_centre:              babj
    GRIB_subCentre:           0
    GRIB_tablesVersion:       4
    GRIB_localTablesVersion:  0
    GRIB_dataType:            fc
    ...                       ...
    GRIB_stepType:            instant
    GRIB_stepUnits:           1
    GRIB_stepRange:           24
    GRIB_endStep:             24
    GRIB_count:               189
    long_name:                discipline=0 parmcat=2 parm=3

配置#

定义风场图样式 (BarbStyle)

wind_barb_style = BarbStyle(
    barbcolor="red",
    flagcolor="red",
    linewidth=0.3,
)

绘制#

创建中国区域底图布局

domain = EastAsiaMapDomain()

绘图风场图,设置标题。

注:这里将风场稀疏化后再绘图,并只在主区域(第 1 层)绘图,即 layer=[0]

panel = Panel(domain=domain)
panel.plot([[u_850_field[::14, ::14], v_850_field[::14, ::14]]], style=wind_barb_style, layer=[0])

domain.set_title(
    panel=panel,
    graph_name="850 hPa WIND (m/s) windbarb",
    system_name=system_name,
    start_time=start_time,
    forecast_time=forecast_time,
)
../../_images/64385dfa687c2efaf68464b69f89c2d6eca2a22d07f8497aa5236b20e5922d46.png