GRIB学习笔记:样例文件分析 - Section 3
本文通过分析一个GRIB2消息介绍GRIB2格式。
样例文件来自中国气象局数值预报中心GRAPES全球模式的预报结果,选用2019年5月26日00时次的000时次850hPa温度场。
Section 3: Grid Definition Section
定义数据的网格表面和几何形状,内容如下:
Octets | Key | Type | Content |
---|---|---|---|
1-4 | section3Length | unsigned | Length of section in octets (nn) |
5 | numberOfSection | unsigned | Number of section (3) |
6 | sourceOfGridDefinition | codetable | Source of grid definition (see Code Table 3.0 and Note 1) |
7-10 | numberOfDataPoints | unsigned | Number of data points |
11 | numberOfOctectsForNumberOfPoints | unsigned | Number of octets for optional list of numbers (see Note 2) |
12 | interpretationOfNumberOfPoints | codetable | Interpretation of list of numbers (see Code Table 3.11) |
13-14 | gridDefinitionTemplateNumber | codetable | Grid Definition Template Number (= N) (see Code Table 3.1) |
15-xx | Grid Definition Template (see Template 3.N, where N is the Grid Definition Template Number given in octets 13-14) | ||
[xx+1]-nn | Optional list of numbers defining number of points (see Notes 2, 3 and 4) |
用可选的格点列表来表示不规则的网格点,附加在规则网格模板点的后面。数值预报中心只用规则网格。
grib_dump示例
====================== SECTION_3 ( length=72, padding=0 ) ======================
1-4 section3Length = 72
5 numberOfSection = 3
6 sourceOfGridDefinition = 0 [Specified in Code table 3.1 (grib2/tables/4/3.0.table) ]
7-10 numberOfDataPoints = 1036800
11 numberOfOctectsForNumberOfPoints = 0
12 interpretationOfNumberOfPoints = 0 [There is no appended list (grib2/tables/4/3.11.table) ]
13-14 gridDefinitionTemplateNumber = 0 [Latitude/longitude (Also called equidistant cylindrical, or Plate Carree) (grib2/tables/4/3.1.table) ]
15 shapeOfTheEarth = 6 [Earth assumed spherical with radius of 6,371,229.0 m (grib2/tables/4/3.2.table) ]
16 scaleFactorOfRadiusOfSphericalEarth = 0
17-20 scaledValueOfRadiusOfSphericalEarth = 0
21 scaleFactorOfEarthMajorAxis = 0
22-25 scaledValueOfEarthMajorAxis = 0
26 scaleFactorOfEarthMinorAxis = 0
27-30 scaledValueOfEarthMinorAxis = 0
31-34 Ni = 1440
35-38 Nj = 720
39-42 basicAngleOfTheInitialProductionDomain = 0
43-46 subdivisionsOfBasicAngle = 0
47-50 latitudeOfFirstGridPoint = 89875000
51-54 longitudeOfFirstGridPoint = 0
55 resolutionAndComponentFlags = 48 [00110000]
56-59 latitudeOfLastGridPoint = -89875000
60-63 longitudeOfLastGridPoint = 359750000
64-67 iDirectionIncrement = 250000
68-71 jDirectionIncrement = 250000
72 scanningMode = 0 [00000000]
说明
样例文件Section 3由0x25开始。
1-4: section长度
5: section序号
section长度为0x48,序号为3。下一节起始位置在0x25 + 0x48 = 0x6d。
可以看到下一节为Section 4,长度为0x22。
6:网格定义的来源,由Code Table 3.0定义。
样例消息为0,表示使用Code table 3.1定义的网格。
如果不为0,后续11、12、[xx+1]-nn会定义额外的不规则点。数值预报中心尚未使用不规则点,所以暂不考虑。
7-10: 数据点个数
样例消息数据点个数为0xFD200=1036800,与模式分辨率一致(1440 * 720 = 1036800)
11: 附加列表每个点所占字节数,样例消息不用,直接赋零。
12:对附加列表的解释,样例消息没有附加列表,直接赋零(There is no appended list)。
13-14: 网格定义模板号,由Code table 3.1定义
样例文件为0x0,表示经纬度网格(Latitude/longitude Also called equidistant cylindrical, or Plate Carre)。
15-xx:网格定义模板。样例消息从octet 15开始到本节结束,都是该网格的模板。
经纬度网格
经纬度网格的模板为Template 3.0。
Octets | Key | Type | Content |
---|---|---|---|
15 | shapeOfTheEarth | codetable | Shape of the earth (see Code Table 3.2) |
16 | scaleFactorOfRadiusOfSphericalEarth | unsigned | Scale factor of radius of spherical earth |
17-20 | scaledValueOfRadiusOfSphericalEarth | unsigned | Scaled value of radius of spherical earth |
21 | scaleFactorOfEarthMajorAxis | unsigned | Scale factor of major axis of oblate spheroid earth |
22-25 | scaledValueOfEarthMajorAxis | unsigned | Scaled value of major axis of oblate spheroid earth |
26 | scaleFactorOfEarthMinorAxis | unsigned | Scale factor of minor axis of oblate spheroid earth |
27-30 | scaledValueOfEarthMinorAxis | unsigned | Scaled value of minor axis of oblate spheroid earth |
31-34 | Ni | unsigned | Ni - number of points along a parallel |
35-38 | Nj | unsigned | Nj - number of points along a meridian |
39-42 | basicAngleOfTheInitialProductionDomain | unsigned | Basic angle of the initial production domain (see Note 1) |
43-46 | subdivisionsOfBasicAngle | unsigned | Subdivisions of basic angle used to define extreme longitudes and latitudes, and direction increments (see Note 1) |
47-50 | latitudeOfFirstGridPoint | signed | La1 - latitude of first grid point (see Note 1) |
51-54 | longitudeOfFirstGridPoint | signed | Lo1 - longitude of first grid point (see Note 1) |
55 | resolutionAndComponentFlags | codeflag | Resolution and component flags (see Flag Table 3.3) |
56-59 | latitudeOfLastGridPoint | signed | La2 - latitude of last grid point (see Note 1) |
60-63 | longitudeOfLastGridPoint | signed | Lo2 - longitude of last grid point (see Note 1) |
64-67 | iDirectionIncrement | unsigned | Di - i direction increment (see Notes 1 and 5) |
68-71 | jDirectionIncrement | unsigned | Dj - j direction increment (see Notes 1 and 5) |
72 | scanningMode | codeflag | Scanning mode (flags - see Flag Table 3.4) |
73-nn | pl | unsigned | List of number of points along each meridian or parallel (These octets are only present for quasi-regular grids as described in notes 2 and 3) |
对于我这种门外汉,上面的描述比较专业。不过,可以参考ecCodes中Template 3.0的定义文件:
# Copyright 2005-2018 ECMWF.
# TEMPLATE 3.0, Latitude/longitude (or equidistant cylindrical, or Plate Carree)
include "grib2/template.3.shape_of_the_earth.def";
include "grib2/template.3.latlon.def";
可以看到,该模板分成两部分:地球形状(15-30)和经纬度网格(31-72)。
地球形状
地球形状与模式本身有关。对于数值预报中心的GRAPES系统模式系统,地球形状是固定的。
15: 地球形状,由Code Table 3.2定义。
样例文件的地球形状为球形(Earth assumed spherical with radius of 6,371,229.0 m)。
16-30: 定义具体的参数,不知道实际的含义,样例文件均为0,不再说明。
经纬度网格
说明数据区域范围和模式分辨率,Section 3中最重要的部分。
31-34: 纬度方向格点数
样例文件为0x5A0 = 1440。
35-38: 经度方向格点数
样例文件为0x2D0 = 720。
上述两者相乘 1440 * 720 = 1036800,正好是7-10位置记录的总格点数。
39-42: basicAngleOfTheInitialProductionDomain
43-46: subdivisionsOfBasicAngle
如果默认的单位(\( 10^{-6} \)度)无法满足要求,需要设置这两个值。数值预报中心的模式产品不使用这两个值,均为0。
47-50: 第一个格点的纬度,默认的单位为\( 10^{-6} \)度。
样例文件为0x55B6238 = 89875000,即北纬89.875度。
51-54:第一个格点的经度,默认的单位为\( 10^{-6} \)度。
样例文件为0x0 = 0,即经度为0度。
55: 分辨率和分量标志,由Flag Table 3.3确定。
Bit | Value | Meaning |
---|---|---|
1-2 | Reserved | |
3 | 0 | i direction increments not given |
3 | 1 | i direction increments given |
4 | 0 | j direction increments not given |
4 | 1 | j direction increments given |
5 | 0 | Resolved u- and v- components of vector quantities relative to easterly and northerly directions |
5 | 1 | Resolved u- and v- components of vector quantities relative to the defined grid in the direction of increasing x and y (or i and j) coordinates respectively |
6-8 | Reserved - set to zero |
样例文件为0x30,即00110000
,表示:
Bit | Value | Meaning |
---|---|---|
3 | 1 | 已设置纬线方向(i方向)增量 |
4 | 1 | 已设置经线方向(j方向)增量 |
5 | 0 | 矢量的u、v分量相对于东风向和北风向 |
56-59: 最后一个格点的纬度,默认的单位为\( 10^{-6} \)度。
样例文件为0x855B6238 = -89875000(32位有符号整数的补码),即纬度为南纬89.875度。
60-63: 最后一个格点的经度,默认的单位为\( 10^{-6} \)度。
样例文件为0x15715970 = 359750000,即经度为359.75度。
64-67: 纬线方向(i方向)增量,纬线上相邻两个格点的距离。
样例文件为0x3D090 = 250,000,即纬线方向增量为0.25度。
68-71: 经线方向(j方向)增量,经线上相邻两个格点的距离。
样例文件为0x3D090 = 250,000,即经线方向增量为0.25度。
72: 扫描模式,与经纬度网格点数据排列顺序有关,由Flag Table 3.4定义。
样例文件为0x0,含义如下:
位 | 值 | 含义 |
---|---|---|
1 | 0 | 第一行或列沿+i(+x)方向扫描 |
2 | 0 | 第一行或列沿-j(-y)方向扫描 |
3 | 0 | i(x)方向相邻的格点是连续存储的 |
4 | 0 | 所有行沿相同方向扫描 |
下面的图形说明数据是如何存储的。
1122334499101011111212556677881313141415151616i(x) 纬线方向i(x) 纬线方向-y(-j)经线方向-y(-j)经线方向00359.75359.7589.87589.875-89.875-89.875
73-nn: 样例文件中没有该数据,数值预报中心的GRIB2数据不使用该字段。