14.01.2015 Views

Introduction

Introduction

Introduction

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

GRIB API<br />

Enrico Fucile<br />

Data & Services Section<br />

Slide 1<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 1


Overview<br />

•GRIB 1 vs. 2<br />

•GRIBEX vs. GRIB API<br />

•Available interfaces<br />

•Plans<br />

Slide 2<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 2


GRIB 1 vs. 2<br />

GRIB (GRIdded Binary) is a binary format to exchange and store<br />

general regularly-distributed information.<br />

Slide 3<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 3


GRIB 1 vs. 2<br />

• Two different versions of the coding standard are available at<br />

the moment (edition 1 and 2).<br />

• The coding principles in both editions are similar, but their<br />

implementation is very different.<br />

Slide 4<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 4


GRIB 1 vs. 2<br />

• Different structure. They both have sections (with different<br />

meaning).<br />

• GRIB 2 is more flexible because of its template/tables structure.<br />

• In GRIB 2 several variables are defined with more precision (e.g.<br />

angles are in micro-degrees)<br />

• In GRIB 2 the description of the data (parameter, time,<br />

statistics,…) is more complex and is template/table based (prone<br />

to became even more complex)<br />

Slide 5<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 5


GRIB 1 vs. 2: Different Structure<br />

GRIB 1<br />

SECTION 0 Indicator<br />

SECTION 1 Product definition<br />

SECTION 2 Grid Description<br />

SECTION 3 Bitmap<br />

SECTION 4 Binary Data<br />

SECTION 5 End (7777)<br />

repeat<br />

Slide 6<br />

GRIB 2<br />

SECTION 0 Indicator<br />

SECTION 1 Identification<br />

SECTION 2 Local Use<br />

SECTION 3 Grid Definition<br />

SECTION 4 Product Definition<br />

SECTION 5 Data Representation<br />

SECTION 6 Bitmap<br />

SECTION 7 Binary Data<br />

SECTION 8 End (7777)<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 6


GRIB 1 vs. 2: GRIB 2 Templates<br />

====================== SECTION 3 ( length=200, padding=0 ) ======================<br />

1-4 section3Length = 200<br />

5 numberOfSection = 3<br />

6 sourceOfGridDefinition = 0 [Specified in Code table 3.1 ]<br />

7-10 numberOfDataPoints = 6114<br />

11 numberOfOctetsForOptionalListOfNumbersDefiningNumberOfPoints = 2<br />

12 interpretationOfListOfNumbersDefiningNumberOfPoints = 1 [Numbers<br />

13-14<br />

define number of points corresponding to full coordinate circles ]<br />

gridDefinitionTemplateNumber = 40 [Gaussian latitude/longitude]<br />

15 shapeOfTheEarth = 0 [Earth assumed spherical with radius=6,367,470 m]<br />

16 scaleFactorOfRadiusOfSphericalEarth = MISSING<br />

17-20 scaledValueOfRadiusOfSphericalEarth = MISSING<br />

21 scaleFactorOfMajorAxisOfOblateSpheroidEarth = MISSING<br />

22-25 scaledValueOfMajorAxisOfOblateSpheroidEarth = MISSING<br />

26 scaleFactorOfMinorAxisOfOblateSpheroidEarth = MISSING<br />

27-30 scaledValueOfMinorAxisOfOblateSpheroidEarth = MISSING<br />

31-34 numberOfPointsAlongAParallel = MISSING<br />

35-38 numberOfPointsAlongAMeridian = 64<br />

39-42 basicAngleOfTheInitialProductionDomain = 0<br />

43-46 subdivisionsOfBasicAngle = MISSING<br />

47-50 latitudeOfFirstGridPoint = 87864000<br />

51-54 longitudeOfFirstGridPoint = 0<br />

55 resolutionAndComponentFlags = 0<br />

56-59 latitudeOfLastGridPoint = -87864000<br />

60-63 longitudeOfLastGridPoint = 357188000<br />

64-67 iDirectionIncrement = MISSING<br />

68-71 numberOfParallelsBetweenAPoleAndTheEquator = 32<br />

72 scanningMode = 0<br />

73-200 pl = (64,128) {2.0000000000e+01, 2.7000000000e+01, Slide 7 ...}<br />

======================================================================================<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 7


GRIB 1 vs. 2: GRIB 2 Templates<br />

====================== SECTION_4 ( length=770, padding=0 ) ======================<br />

1-4 section4Length = 770<br />

5 numberOfSection = 4<br />

6-7 numberOfVerticalCoordinateValues = 184<br />

8-9 productDefinitionTemplateNumber = 0<br />

[Analysis or forecast at a horizontal<br />

level or in a horizontal layer at a point in time]<br />

10 parameterCategory = 0 [Temperature (grib2/4.1.0.table) ]<br />

11 parameterNumber = 0 [Temperature (K) (grib2/4.2.0.0.table) ]<br />

12 typeOfGeneratingProcess = 0 [Analysis (grib2/4.3.table) ]<br />

13 backgroundGeneratingProcessIdentifier = 255<br />

14 generatingProcessIdentifier = 130<br />

15-16 hoursAfterReferenceTimeOfDataCutoff = 0<br />

17 minutesAfterReferenceTimeOfDataCutoff = 0<br />

18 indicatorOfUnitOfTimeRange = 1 [Hour (grib2/4.4.table) ]<br />

19-22 forecastTime = 0<br />

23 typeOfFirstFixedSurface = 100 [Isobaric surface (Pa) (grib2/4.5.table) ]<br />

24 scaleFactorOfFirstFixedSurface = 0<br />

25-28 scaledValueOfFirstFixedSurface = 0<br />

29 typeOfSecondFixedSurface = 255 [Missing (grib2/4.5.table) ]<br />

30 scaleFactorOfSecondFixedSurface = MISSING<br />

31-34 scaledValueOfSecondFixedSurface = MISSING<br />

35-770 pv = (184,736) {0.0000000000e+00, 2.0000400543e+00,...}<br />

=====================================================================================<br />

Slide 8<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 8


GRIB 1 vs. 2: different units<br />

GRIB 1<br />

• LatitudeOfFirstGridPoint is<br />

in milli-degrees<br />

GRIB 2<br />

• LatitudeOfFirstGridPoint is<br />

in micro-degrees<br />

or in an arbitrary unit<br />

defined by the fraction of<br />

two parameters:<br />

basicAngleOfTheInitialProductionDomain/<br />

subdivisionsOfBasicAngle<br />

Slide 9<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 9


GRIB 1 vs. 2<br />

HOW TOGRIB SQUARE API VIEW THE CIRCLE<br />

GRIB 1<br />

GRIB<br />

GRIB 2<br />

Slide 10<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 10


GRIB 1 vs. 2<br />

GRIB API VIEW<br />

GRIB 21<br />

Slide 11<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 11


GRIBEX vs. GRIB API<br />

•GRIBEX provides an array based access to the GRIB<br />

message.<br />

- ksec2(2) => Number of points along a parallel<br />

- Ksec2(3) => Number of points along a meridian<br />

- …<br />

•GRIB API provides a key/value based approach<br />

- NumberOfPointsAlongAParallel => Number of points along a<br />

parallel<br />

- NumberOfPointsAlongAMeridan => Number of points along a<br />

meridian<br />

- …<br />

Slide 13<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 13


GRIB API - Design<br />

Client Software<br />

(C/C++, FORTRAN, Perl …)<br />

set and get<br />

key / values<br />

Command line tools<br />

GRIB 1<br />

GRIB_API<br />

Definition<br />

Files<br />

Definition files are external text files<br />

describing the decoding rules.<br />

Slide 14<br />

New decoding rules can be added<br />

without rebuilding the grib_api<br />

GRIB 2<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 14


GRIB 1 vs. 2<br />

COMPUTED<br />

latitudeOfFirstGridPointInDegrees=40<br />

CODED<br />

latitudeOfFirstGridPoint=40000<br />

CODED<br />

latitudeOfFirstGridPoint=40000000<br />

Slide 15<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 15


GRIB 1 vs. 2<br />

COMPUTED<br />

gridType=reduced_gg<br />

CODED<br />

CODED<br />

dataRepresentationType=4<br />

numberOfPointAlongAParallel=MISSING<br />

ijDirectionIncrementGiven=0<br />

pl ={…}<br />

gridDefinitionTemplateNumber=40<br />

numberOfPointsAlongAParallel=MISSING<br />

iDirectionIncrementGiven=0<br />

iDirectionIncrement=MISSING<br />

Slide 16<br />

pl={…}<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 16


GRIB 1 vs. 2<br />

numberOfPoints<br />

numberOfValues<br />

numberOfMissingValues<br />

<br />

<br />

Slide 17<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 17


GRIB API: available interfaces<br />

•C native interface exposes all the functionalities in an<br />

object oriented style.<br />

•Fortran 77 is maintained for compatibility reasons with<br />

the gribex software.<br />

•Fortran 90 is the Fortran suggested interface and<br />

provides an easy access to the main functionalities of<br />

the library.<br />

•GRIB tools provide a command line interface of the API<br />

•Perl is still under development and will be tested and<br />

verified in the next releases.<br />

•All the interfaces provide a way to set/get the same set of<br />

Slide 18<br />

keys.<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 18


GRIB API: available interfaces ( C )<br />

grib_handle* h=NULL;<br />

double latitudeOfFirstGridPointInDegrees;<br />

char* date=“20080212”;<br />

long centre;<br />

grib_context* context=grib_context_get_default();<br />

in = fopen(filename,"r");<br />

h = grib_handle_new_from_file(context,in,&err);<br />

grib_get_double(h,"latitudeOfFirstGridPointInDegrees",<br />

&latitudeOfFirstGridPointInDegrees);<br />

grib_set_long(h,"centre",centre);<br />

grib_set_string(h,“date",date,&len);<br />

Slide 19<br />

grib_handle_delete(h);<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 19


GRIB API: available interfaces (Fortran 90)<br />

integer :: ifile, igrib, iret, centre<br />

real(8) :: latitudeOfFirstPointInDegrees<br />

call grib_open_file(ifile,'regular_latlon_surface.grib1','r')<br />

call grib_new_from_file(ifile,igrib,iret)<br />

call grib_get(igrib,'latitudeOfFirstGridPointInDegrees',<br />

&<br />

latitudeOfFirstPointInDegrees)<br />

call grib_set(igrib,'centre',centre)<br />

call grib_set(igrib, ‘date',’20070212’)<br />

call grib_release(igrib)<br />

call grib_close_file(infile)<br />

Slide 20<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 20


GRIB API: available interfaces (tools)<br />

grib_get –p latitudeOfFirstGridPointInDegrees regular_latlon_surface.grib1<br />

grib_set –s centre=ecmf,date=20070212 regular_latlon_surface.grib1 out.grib1<br />

Slide 21<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 21


GRIB API: available interfaces (tools)<br />

•grib_ls, grib_get (quick listing of the content of a file)<br />

•grib_dump (detailed views of the grib messages)<br />

•grib_get_data (latitude/longitude/value list )<br />

•grib_set, grib_convert (to change header values)<br />

•grib_copy (to copy selected messages)<br />

•grib_filter (to set and write to different files)<br />

•grib_compare (to compare two grib files)<br />

•grib_keys (to get a list of available keys)<br />

Slide 22<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 22


GRIB Tools:<br />

options<br />

A set of options common to all the tools is provided.<br />

• -p key[:{s/d/l}],key[:{s/d/l}],...<br />

Declaration of keys to print. For each key a string<br />

(key:s) or a float (key:d) or a integer (key:l) value is<br />

printed. Default type is string.<br />

• -w key[:{s/d/l}]{=/!=}value,key[:{s/d/l}]{=/!=}value,...<br />

Where clause. Grib messages are processed only if<br />

they match all the key/value constraints. A valid<br />

constraint is of type key=value or key!=value. For<br />

each key a string (key:s) or a double (key:d) or a long<br />

Slide 23<br />

(key:l) type can be specified. Default type is string.<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 23


GRIB Tools:<br />

options<br />

grib_ls –w levelType=sfc sample.grib<br />

grib_copy –w levelType=sfc sample.grib sfc.grib<br />

grib_set –w levelType=sfc –s packingType=jpeg<br />

sample.grib2 sfc_jpeg.grib2<br />

Slide 24<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 24


GRIB Tools:<br />

options<br />

grib_ls –B”step,param desc,levelType”x.grib<br />

grib_copy –B”step,param desc,levelType”x.grib order.grib<br />

Slide 25<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 25


GRIB TOOLS: grib_ls<br />

grib_ls –p step,short_name –l40/11 reduced_gg.grib<br />

step shortName value1 value2 value3 value4<br />

0 2T 291.57 291.88 291.92 291.61<br />

0 TP 0.00 0.00 0.00 0.00<br />

12 2T 292.19 292.08 292.21 291.69<br />

12 TP 0.00 0.00 -0.00 -0.00<br />

Input Point: latitude=40.00 longitude=11.00<br />

Grid Points<br />

- 1 - index=39302 latitude=39.78 longitude=11.25 distance=32.86 (Km)<br />

- 2 - index=39301 latitude=39.78 longitude=10.69 distance=36.54 (Km)<br />

- 3 - index=38662 latitude=40.22 longitude=11.25 Slide 26 distance=32.80 (Km)<br />

- 4 - index=38661 latitude=40.22 longitude=10.69 distance=36.47 (Km)<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 26


GRIB TOOLS: grib_ls<br />

grib_ls –p step,short_name –Bparam,step –l40/11 reduced_gg.grib<br />

step shortName value1 value2 value3 value4<br />

0 2T 291.57 291.88 291.92 291.61<br />

12 2T 292.19 292.08 292.21 291.69<br />

0 TP 0.00 0.00 0.00 0.00<br />

12 TP 0.00 0.00 -0.00 -0.00<br />

Input Point: latitude=40.00 longitude=11.00<br />

Grid Points<br />

- 1 - index=39302 latitude=39.78 longitude=11.25 distance=32.86 (Km)<br />

- 2 - index=39301 latitude=39.78 longitude=10.69 distance=36.54 (Km)<br />

- 3 - index=38662 latitude=40.22 longitude=11.25 Slide 27 distance=32.80 (Km)<br />

- 4 - index=38661 latitude=40.22 longitude=10.69 distance=36.47 (Km)<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 27


GRIB TOOLS: grib_ls<br />

grib_ls –p step,shortName –Bparam,step –l40/11/1 reduced_gg.grib<br />

step shortName value<br />

0 2T 291.92<br />

12 2T 292.21<br />

0 TP 0.00<br />

12 TP -0.00<br />

Input Point: latitude=40.00 longitude=11.00<br />

Grid Point index=38662 latitude=40.22 longitude=11.25 distance=32.80<br />

(Km)<br />

Slide 28<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 28


GRIB TOOLS: grib_ls<br />

grib_ls –p step,shortName –Bparam,step -i 38662 reduced_gg.grib<br />

step shortName value(38662)<br />

0 2T 291.92<br />

12 2T 292.21<br />

0 TP 0.00<br />

12 TP -0.00<br />

Slide 29<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 29


GRIB Tools:<br />

grib_filter<br />

grib_filter filter.rules x.grib<br />

filter.rules<br />

if ( step


Roadmap.<br />

•Improvement of the performance of the packing<br />

algorithms. At this stage the performance of the packing<br />

algorithm is worse than gribex of several times. It is<br />

planned to rewrite the packing algorithms in the next<br />

two/three months.<br />

•Memory management. Allocation/deallocation is a critical<br />

activity.<br />

•Thread safety. Not available in GRIBEX.<br />

•New indexing algorithms.<br />

•New fieldset compute.<br />

•New interfaces. Perl released, Matlab, Python, Java.<br />

Slide 31<br />

•Graphical User Interface. Wxwidgets<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 31


GRIB API future (version 2.0)<br />

Fieldsets<br />

Fieldsets<br />

DB<br />

Order<br />

Compute<br />

Files<br />

Files<br />

Filter<br />

CMA<br />

ECMWF<br />

JMA<br />

Slide 32<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 32


GRIB API future (version 2.0)<br />

•Where condition<br />

•Order by<br />

•Formula<br />

grib_compute -s”u((shortName==u), step asc, number desc), v<br />

((shortName==v), step asc, number desc)”-f “sqrt( u*u+v*v)”<br />

Slide 33<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 33


GRIB API future (version 2.0)<br />

•Where condition<br />

•Order by<br />

•Formula<br />

grib_compute -s”tp(((centre==babj) or (centre==ecmf)) and<br />

(shortName==tp), step,number,centre)”<br />

-f freq( tp ,number,


Distribution<br />

•GRIB API & TOOLS: 1.0 released in April 2007,<br />

release 1.4 available now with new features and<br />

several improvements.<br />

•Version 2.0 will be released soon with the full set of<br />

compute and fieldset new features.<br />

•Lesser General Public License.<br />

•Download<br />

http://www.ecmwf.int/products/data/software/downlo<br />

ad/grib_api.html<br />

•Support Software.Services@ecmwf.int<br />

Slide 35<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 35


Questions <br />

Slide 36<br />

COM GRIB API, ECMWF 13-14 Feb. 2008<br />

Slide 36

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!