NWP | wgrib2 | grib_ls
wgrib2
wgrib2 is a widely-used, free, and open-source command-line utility designed for the management and manipulation of GRIB2 (GRIdded Binary) files, which are the standard data format for distributing gridded meteorological and oceanographic data, like numerical weather prediction (NWP) model output.
Developed primarily by the National Oceanic and Atmospheric Administration's (NOAA) National Centers for Environmental Prediction (NCEP), its main purpose is to:
- Read and Inspect GRIB2 Files: It can generate a verbose inventory (or index file) of the contents of a GRIB2 file, showing parameters, levels, forecast times, and more.
- Extract and Manipulate Data: Users can select, filter, or subset data based on various criteria (e.g., variable name, pressure level, time, geographic area).
- Output Conversion: It can convert GRIB2 data to
other formats, including:
- Binary (IEEE format)
- Text or CSV
- NetCDF
- Data Processing: It includes numerous options for calculations, regridding (interpolating data to a different grid), and creating new GRIB2 fields.
Essentially, wgrib2 is an indispensable tool for meteorologists and researchers who need to efficiently work with the often-large, complex binary files produced by weather and climate models. It also includes library interfaces for C, Fortran, and Python, allowing it to be integrated into other software applications.
Using wgrib2 (NCEP)
wgrib2 uses specific inventory flags (-s or
custom options) to output variable information. For GRIB2 files, it
often provides the variable abbreviation, description, and unit directly
in the inventory output.
Command Syntax
1 | |
1 | |
Standard Inventory (-s
or -v)
1 | |
-s: Prints a summary inventory. This output often includes the variable abbreviation, level, and forecast time, which is usually enough to identify the variable.-v: Prints a more verbose inventory, which often includes the unit.
grib_ls
grib_ls is a fundamental command-line
utility for inspecting and listing the content of GRIB (GRIdded Binary)
files, which are the international standard format for the exchange of
meteorological data.
It is part of the ecCodes package developed by the European Centre for Medium-Range Weather Forecasts (ECMWF), and is one of the core tools for interactive and batch processing of GRIB data.
Here is a summary of its key features and usage:
1. Primary Function
The main purpose of grib_ls is to list the
values of specified keys (metadata) from one or more GRIB
messages within a file, presenting the information in a
structured, column-based output.
2. Key Characteristics
- Inspection Tool: It's primarily a tool for quickly examining the header information of GRIB messages.
- Key/Value Approach: It operates on a key/value
system, where keys are used to access specific pieces of metadata (e.g.,
shortName,dataDate,stepRange,level). - Non-Failing: Unlike its counterpart
grib_get,grib_lsis designed to be more robust for interactive use. It does not fail or return an error code if a requested key is not found in a message; instead, it will typically print a blank or missing value.
3. Common Usage and Options
The basic syntax is:
1 | |
Some of the most useful options include:
| Option | Description | Example Usage |
|---|---|---|
-p |
Print Keys: Specifies a comma-separated list of keys to print. | grib_ls -p paramId,shortName,level file.grib |
-w |
Where Clause (Filter): Filters the messages to be processed, only showing those that match specified key/value constraints. | grib_ls -w shortName=t,level=850 file.grib |
-n |
Namespace: Prints all
keys belonging to a specific namespace (e.g., ls,
time, mars). |
grib_ls -n mars file.grib |
-l |
Nearest Neighbour: Finds and prints the data value(s) closest to a specified latitude/longitude point. | grib_ls -l 51.46,-1.33,1 -p dataDate,value file.grib |
-B |
Order By: Sorts the output based on one or more keys. | grib_ls -B 'dataDate asc,step:i desc' file.grib |
-j |
JSON Output: Prints the output in JSON format, useful for scripting. | grib_ls -j file.grib |
grib_ls is an essential tool for meteorologists and
developers working with GRIB data, offering a quick way to understand
the contents and structure of meteorological fields.