title: 参数数据库

weight: 5

GRIB 1 参数(WMO 编码)

10 metre U wind component

indicatorOfParameter = 33 [u-compoment of wind (m/s)]

table2Version = 3

indicatorOfTypeOfLevel = 105 [Specified height level above ground (m)]

level = 10

GRIB 2 参数(WMO 编码)

10 metre U wind component

discipline = 0 [Meteorological products]

parameterCategory = 2 [Monmentum]

parameterNumber = 2 [u-component of wind (m s-1)]

typeOfFirstFixedSurface = 103 [Specified height level above ground (m)]

scaleFactorOfFirstFixedSurface = 0

scaledValueOfFirstFixedSurface = 10

GRIB 1 参数(ECMWF 本地编码)

10 metre U wind component

indicatorOfParameter =165 [10 metere u-compoment of wind (m/s)]

table2Version = 128

ecCodes 的解决方案

有多种编码变量的方法。

ecCodes 使用一个虚拟的 key(计算key)来解耦用户层和编码层。

用户代码获取/设置一个虚拟 key,ecCodes 获取/设置实际编码的 key。

本地配置用于处理本地编码。

ecCodes 变量

ecCodes 提供一些版本无关的 key 用于定义变量:

  • paramId
  • shortName
  • name
  • units
  • centre

GRIB 1 使用如下 key:

  • centre
  • table2Version
  • indicatorOfParameter
  • levelType
  • level

GRIB 2 使用如下 key:

  • discipline
  • parameterCategory
  • parameterNumber
  • typeOfFirstFixedSurface
  • scaleFactorOfFirstFixedSurface
  • scaledValueOfFirstFixedSurface
  • typeOfSecondFixedSurface
  • scaleFactorOfSecondFixedSurface
  • scaledValueOfSecondFixedSurface

概念

之前的章节中介绍过 ecCodes 的架构:

参数数据库 - 图1

下面介绍几个与变量有关的重要概念。

shortName

GRIB 2:

  1. '2t' = {
  2. discipline=0;
  3. parameterCategory=0;
  4. parameterNumber=0;
  5. typeOfFirstFixedSurface=103;
  6. scaleFactorOfFirstFixedSurface=0;
  7. scaledValueOfFirstFixedSurface=2;
  8. }

GRIB 1:

  1. '2t' = {
  2. indicatorOfParameter=11;
  3. table2Version=3;
  4. levelType=105;
  5. level=2;
  6. }

GRIB 1 ECMWF 本地编码:

  1. '2t' = {
  2. indicatorOfParameter=167;
  3. table2Version=128;
  4. }

paramId

GRIB 2:

  1. 167 = {
  2. discipline=0;
  3. parameterCategory=0;
  4. parameterNumber=0;
  5. typeOfFirstFixedSurface=103;
  6. scaleFactorOfFirstFixedSurface=0;
  7. scaledValueOfFirstFixedSurface=2;
  8. }

GRIB 1:

  1. 167 = {
  2. indicatorOfParameter=11;
  3. table2Version=3;
  4. levelType=105;
  5. level=2;
  6. }

GRIB 1 ECMWF 本地编码:

  1. 167 = {
  2. indicatorOfParameter=167;
  3. table2Version=128;
  4. }

ecCodes 使用的 GRIB 参数

访问如下网址,查询参数数据库:

http://apps.ecmwf.int/codes/grib/param-db/

练习

  1. 创建两个文件

    1. #include <iostream>
    2. #include <eccodes.h>
    3. using namespace std;
    4. int main(int argc, char** argv)
    5. {
    6. if(argc < 3)
    7. {
    8. cout<<"Usage: "<<argv[0]<<" grib1_path grib2_path";
    9. return 1;
    10. }
    11. const char* grib1_path = argv[1];
    12. const char* grib2_path = argv[2];
    13. const char* sample_filename = "regular_ll_pl_grib2";
    14. int err = 0;
    15. codes_handle *h = codes_grib_handle_new_from_samples(nullptr, sample_filename);
    16. if(h == nullptr)
    17. {
    18. cout<<"ERROR: unable to create handle from sample "<<sample_filename<<endl;
    19. return 1;
    20. }
    21. size_t short_name_size;
    22. codes_get_size(h, "shortName", &short_name_size);
    23. codes_set_string(h, "shortName", "10u", &short_name_size);
    24. size_t value_size;
    25. codes_get_size(h, "values", &value_size);
    26. auto values = new double[value_size];
    27. double v = 0;
    28. for(auto i=0; i<value_size; i++)
    29. {
    30. values[i] = v;
    31. v++;
    32. }
    33. // codes_set_long(h, "bitsPerValue", 16);
    34. codes_set_double_array(h, "values", values, value_size);
    35. codes_write_message(h, grib2_path, "wb");
    36. codes_set_long(h, "edition", 1);
    37. codes_write_message(h, grib1_path, "wb");
    38. delete [] values;
    39. codes_handle_delete(h);
    40. return 0;
    41. }
  2. 使用 grib_ls -n parameter p.grib1 p.grib2 查看有何不同。

    1. $ grib_ls -n parameter p.grib1 p.grib2
    2. p.grib1
    3. centre paramId units name shortName
    4. ecmf 130 K Temperature t
    5. 1 of 1 messages in p.grib1
    6. p.grib2
    7. ecmf 130 K Temperature t
    8. 1 of 1 messages in p.grib2
    9. 2 of 2 total messages in 2 files
  3. 使用 grib_dump -o 比较两个文件不同。

    查看 GRIB 1 文件 p.grib1

    1. $ grib_dump -O p.grib1
    2. ***** FILE: p.grib1
    3. #============== MESSAGE 1 ( length=1596 ) ==============
    4. 1-4 identifier = GRIB
    5. 5-7 totalLength = 1596
    6. 8 editionNumber = 1
    7. ====================== SECTION_1 ( length=52, padding=0 ) ======================
    8. 1-3 section1Length = 52
    9. 4 table2Version = 128
    10. 5 centre = 98 [European Centre for Medium-Range Weather Forecasts (common/c-1.table) ]
    11. 6 generatingProcessIdentifier = 128
    12. 7 gridDefinition = 255
    13. 8 section1Flags = 128 [10000000]
    14. 9 indicatorOfParameter = 165 [10 metre U wind component (m s**-1) (grib1/2.98.128.table) ]
    15. 10 indicatorOfTypeOfLevel = 105 [Fixed height above ground height in meters (2 octets) (grib1/local/ecmf/3.table , grib1/3.table) ]
    16. 11-12 level = 10
    17. 13 yearOfCentury = 7
    18. 14 month = 3
    19. 15 day = 23
    20. 16 hour = 12
    21. 17 minute = 0
    22. 18 unitOfTimeRange = 1 [Hour (grib1/4.table) ]
    23. 19 P1 = 0
    24. 20 P2 = 0
    25. 21 timeRangeIndicator = 0 [Forecast product valid at reference time + P1 (P1>0) (grib1/local/ecmf/5.table , grib1/5.table) ]
    26. 22-23 numberIncludedInAverage = 0
    27. 24 numberMissingFromAveragesOrAccumulations = 0
    28. 25 centuryOfReferenceTimeOfData = 21
    29. 26 subCentre = 0 [Unknown code table entry (grib1/0.ecmf.table) ]
    30. 27-28 decimalScaleFactor = 0
    31. 29-40 reservedNeedNotBePresent = 12 {
    32. 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
    33. } # pad reservedNeedNotBePresent
    34. 41 localDefinitionNumber = 1 [MARS labelling or ensemble forecast data (grib1/localDefinitionNumber.98.table) ]
    35. 42 marsClass = 1 [Operational archive (mars/class.table) ]
    36. 43 marsType = 2 [Analysis (mars/type.table) ]
    37. 44-45 marsStream = 1025 [Atmospheric model (mars/stream.table) ]
    38. 46-49 experimentVersionNumber = 0001
    39. 50 perturbationNumber = 0
    40. 51 numberOfForecastsInEnsemble = 0
    41. 52 padding_local1_1 = 1 {
    42. 00
    43. } # pad padding_local1_1
    44. ====================== SECTION_2 ( length=32, padding=0 ) ======================
    45. 1-3 section2Length = 32
    46. 4 numberOfVerticalCoordinateValues = 0
    47. 5 pvlLocation = 255
    48. 6 dataRepresentationType = 0 [Latitude/Longitude Grid (grib1/6.table) ]
    49. 7-8 Ni = 16
    50. 9-10 Nj = 31
    51. 11-13 latitudeOfFirstGridPoint = 60000
    52. 14-16 longitudeOfFirstGridPoint = 0
    53. 17 resolutionAndComponentFlags = 128 [10000000]
    54. 18-20 latitudeOfLastGridPoint = 0
    55. 21-23 longitudeOfLastGridPoint = 30000
    56. 24-25 iDirectionIncrement = 2000
    57. 26-27 jDirectionIncrement = 2000
    58. 28 scanningMode = 0 [00000000]
    59. 29-32 zero =
    60. ====================== SECTION_4 ( length=1500, padding=0 ) ======================
    61. 1-3 section4Length = 1500
    62. 4 dataFlag = 8 [00001000]
    63. 5-6 binaryScaleFactor = -15
    64. 7-10 referenceValue = 0
    65. 11 bitsPerValue = 24
    66. 12-1500 values = (496,1489) {
    67. ...
    68. } # data_g1simple_packing values
    69. ====================== SECTION_5 ( length=4, padding=0 ) ======================
    70. 1-4 7777 = 7777

    查看 GRIB 2 文件 p.grib2

    1. $ grib_dump -O p.grib2
    2. ***** FILE: p.grib2
    3. #============== MESSAGE 1 ( length=1667 ) ==============
    4. 1-4 identifier = GRIB
    5. 5-6 reserved = MISSING
    6. 7 discipline = 0 [Meteorological products (grib2/tables/4/0.0.table) ]
    7. 8 editionNumber = 2
    8. 9-16 totalLength = 1667
    9. ====================== SECTION_1 ( length=21, padding=0 ) ======================
    10. 1-4 section1Length = 21
    11. 5 numberOfSection = 1
    12. 6-7 centre = 98 [European Centre for Medium-Range Weather Forecasts (common/c-11.table) ]
    13. 8-9 subCentre = 0
    14. 10 tablesVersion = 4 [Version implemented on 7 November 2007 (grib2/tables/1.0.table) ]
    15. 11 localTablesVersion = 0 [Local tables not used (grib2/tables/4/1.1.table) ]
    16. 12 significanceOfReferenceTime = 1 [Start of forecast (grib2/tables/4/1.2.table) ]
    17. 13-14 year = 2007
    18. 15 month = 3
    19. 16 day = 23
    20. 17 hour = 12
    21. 18 minute = 0
    22. 19 second = 0
    23. 20 productionStatusOfProcessedData = 0 [Operational products (grib2/tables/4/1.3.table) ]
    24. 21 typeOfProcessedData = 2 [Analysis and forecast products (grib2/tables/4/1.4.table) ]
    25. ====================== SECTION_3 ( length=72, padding=0 ) ======================
    26. 1-4 section3Length = 72
    27. 5 numberOfSection = 3
    28. 6 sourceOfGridDefinition = 0 [Specified in Code table 3.1 (grib2/tables/4/3.0.table) ]
    29. 7-10 numberOfDataPoints = 496
    30. 11 numberOfOctectsForNumberOfPoints = 0
    31. 12 interpretationOfNumberOfPoints = 0 [There is no appended list (grib2/tables/4/3.11.table) ]
    32. 13-14 gridDefinitionTemplateNumber = 0 [Latitude/longitude (Also called equidistant cylindrical, or Plate Carree) (grib2/tables/4/3.1.table) ]
    33. 15 shapeOfTheEarth = 6 [Earth assumed spherical with radius of 6,371,229.0 m (grib2/tables/4/3.2.table) ]
    34. 16 scaleFactorOfRadiusOfSphericalEarth = MISSING
    35. 17-20 scaledValueOfRadiusOfSphericalEarth = MISSING
    36. 21 scaleFactorOfEarthMajorAxis = MISSING
    37. 22-25 scaledValueOfEarthMajorAxis = MISSING
    38. 26 scaleFactorOfEarthMinorAxis = MISSING
    39. 27-30 scaledValueOfEarthMinorAxis = MISSING
    40. 31-34 Ni = 16
    41. 35-38 Nj = 31
    42. 39-42 basicAngleOfTheInitialProductionDomain = 0
    43. 43-46 subdivisionsOfBasicAngle = MISSING
    44. 47-50 latitudeOfFirstGridPoint = 60000000
    45. 51-54 longitudeOfFirstGridPoint = 0
    46. 55 resolutionAndComponentFlags = 48 [00110000]
    47. 56-59 latitudeOfLastGridPoint = 0
    48. 60-63 longitudeOfLastGridPoint = 30000000
    49. 64-67 iDirectionIncrement = 2000000
    50. 68-71 jDirectionIncrement = 2000000
    51. 72 scanningMode = 0 [00000000]
    52. ====================== SECTION_4 ( length=34, padding=0 ) ======================
    53. 1-4 section4Length = 34
    54. 5 numberOfSection = 4
    55. 6-7 NV = 0
    56. 8-9 productDefinitionTemplateNumber = 0 [Analysis or forecast at a horizontal level or in a horizontal layer at a point in time (grib2/tables/4/4.0.table) ]
    57. 10 parameterCategory = 2 [Momentum (grib2/tables/4/4.1.0.table) ]
    58. 11 parameterNumber = 2 [u-component of wind (m s-1) (grib2/tables/4/4.2.0.2.table) ]
    59. 12 typeOfGeneratingProcess = 0 [Analysis (grib2/tables/4/4.3.table) ]
    60. 13 backgroundProcess = 255
    61. 14 generatingProcessIdentifier = 128
    62. 15-16 hoursAfterDataCutoff = 0
    63. 17 minutesAfterDataCutoff = 0
    64. 18 indicatorOfUnitOfTimeRange = 1 [Hour (grib2/tables/4/4.4.table) ]
    65. 19-22 forecastTime = 0
    66. 23 typeOfFirstFixedSurface = 103 [Specified height level above ground (m) (grib2/tables/4/4.5.table) ]
    67. 24 scaleFactorOfFirstFixedSurface = 0
    68. 25-28 scaledValueOfFirstFixedSurface = 10
    69. 29 typeOfSecondFixedSurface = 255 [Missing (grib2/tables/4/4.5.table) ]
    70. 30 scaleFactorOfSecondFixedSurface = MISSING
    71. 31-34 scaledValueOfSecondFixedSurface = MISSING
    72. ====================== SECTION_5 ( length=21, padding=0 ) ======================
    73. 1-4 section5Length = 21
    74. 5 numberOfSection = 5
    75. 6-9 numberOfValues = 496
    76. 10-11 dataRepresentationTemplateNumber = 0 [Grid point data - simple packing (grib2/tables/4/5.0.table) ]
    77. 12-15 referenceValue = 0
    78. 16-17 binaryScaleFactor = -15
    79. 18-19 decimalScaleFactor = 0
    80. 20 bitsPerValue = 24
    81. 21 typeOfOriginalFieldValues = 0 [Floating point (grib2/tables/4/5.1.table) ]
    82. ====================== SECTION_6 ( length=6, padding=0 ) ======================
    83. 1-4 section6Length = 6
    84. 5 numberOfSection = 6
    85. 6 bitMapIndicator = 255 [A bit map does not apply to this product (grib2/tables/4/6.0.table) ]
    86. ====================== SECTION_7 ( length=1493, padding=0 ) ======================
    87. 1-4 section7Length = 1493
    88. 5 numberOfSection = 7
    89. 6-1493 codedValues = (496,1488) {
    90. ...
    91. } # data_g2simple_packing codedValues
    92. ====================== SECTION_8 ( length=4, padding=0 ) ======================
    93. 1-4 7777 = 7777