grib2json Documentation

repository·master·Indexed 18 days ago

https://github.com/cambecc/grib2json

A command-line utility that decodes GRIB2 files into JSON format using the netCDF-Java GRIB decoder. It supports filtering meteorological records by parameterNumber, surface1Type, and surface1Value, and allows for batch processing via recipe files.

Tokens
1.5K
Snippets
8
Records
8
Agent score
64%

What's inside grib2json

  1. Use the grib2json CLI

    master

    The grib2json launch script is located in the bin directory. To run it, you must have the JAVA_HOME environment variable defined in your system.

    # Ensure JAVA_HOME is set, then run from the bin directory
    ./bin/grib2json [options] FILE
  2. Install grib2json

    master

    To install grib2json, clone the repository and build it using Maven. This will generate a .tar.gz package in the target directory. You can then unzip and untar this package in your preferred location.

    git clone <this project>
    mvn package
  3. Use a recipe file for batch processing

    master

    The grib2json utility supports batch processing using a "recipe" file. A recipe file allows you to define multiple sets of command-line arguments, one per line.

    When a recipe file is provided via the --recipe option:

    1. The utility reads the recipe file line by line.
    2. For each line, it merges the arguments found in that line with the original command-line arguments passed to the application.
    3. Each resulting set of arguments is parsed as a distinct group of Options.
    4. The Grib2Json converter then processes all these groups.

    Each line in the recipe file should contain the specific arguments for that processing group, which are then combined with the global arguments (like the recipe file path itself).

    # Example recipe file content (recipe.txt)
    --option1 --option2
    --option3 --option4
    
    # Command to run using the recipe
    java -cp grib2json.jar net.nullschool.grib2json.Launcher --recipe recipe.txt <input_file>
  4. Filter and extract GRIB2 records to JSON

    master

    You can use grib2json to extract specific meteorological records from a GRIB2 file by filtering on numeric parameters such as parameterNumber (--fp), surface1Type (--fs), or surface1Value (--fv).

    Using the --names flag includes human-readable names for numeric codes (e.g., parameterNumberName), and the --data flag includes the actual data array in the JSON output.

    grib2json --names --data --fp 2 --fs 103 --fv 10.0 gfs.t18z.pgrbf00.2p5deg.grib2
  5. Reference grib2json CLI options

    master

    The grib2json utility accepts several options to control output formatting, filtering, and metadata display. Use --help or -h to view the full list of available flags.

    Usage: grib2json [options] FILE
    	[--compact -c] : enable compact Json formatting
    	[--data -d] : print GRIB record data
    	[--filter.category --fc value] : select records with this numeric category
    	[--filter.parameter --fp value] : select records with this numeric parameter
    	[--filter.surface --fs value] : select records with this numeric surface type
    	[--filter.value --fv value] : select records with this numeric surface value
    	[--help -h] : display this help
    	[--names -n] : print names of numeric codes
    	[--output -o value] : write output to the specified file (default is stdout)
    	[--verbose -v] : enable logging to stdout
  6. Run the grib2json CLI

    master

    The grib2json utility is a command-line tool executed via a shell script. It requires a Java runtime environment (JAVA_HOME) to be configured on your system. The script locates the appropriate grib2json-*.jar file in the relative ../lib directory and executes it with a default maximum heap size of 512MB (-Xmx512M).

    To use the tool, ensure the grib2json script is in your path or call it directly, passing any necessary arguments or flags required by the underlying JAR.

    #!/bin/sh
    $JAVA_HOME/bin/java -Xmx512M -jar $LIB_DIR/grib2json-*.jar$@
  7. Run grib2json via the Windows command script

    master

    On Windows, you can execute the grib2json utility using the grib2json.cmd batch script. This script automatically locates the required JAR file in the lib directory and executes it using your system's JAVA_HOME environment variable. The script allocates a maximum heap size of 512MB (-Xmx512M) for the Java process. You can pass any standard CLI arguments directly to the script, which are then forwarded to the underlying Java application.

    grib2json.cmd [arguments]
  8. Run the grib2json utility via CLI

    master

    The grib2json utility is a command-line tool used to convert GRIB2 files to JSON. It is invoked via the main method in the Launcher class.

    Basic execution requires providing a GRIB2 file. If no file is provided, or if the --help flag is used, the application prints usage instructions and exits.

    Key behaviors:

    • Logging: Logging can be enabled or disabled via command-line options. If disabled, the LoggerContext is stopped.
    • Error Handling:
      • Invalid arguments or usage errors result in an exit code of 1 and a print of the usage message.
      • Unexpected internal errors result in an exit code of 2 and a stack trace.
    // Example conceptual invocation via CLI
    java -cp grib2json.jar net.nullschool.grib2json.Launcher <path_to_grib2_file>