npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

weacast-grib2json

v1.0.3

Published

Converts GRIB V2 files to JSON array

Downloads

444

Readme

weacast-grib2json

Build Status Code Climate Test Coverage Dependency Status Download Status FOSSA Status

A command line utility that decodes GRIB2 files as JSON.

This utility uses the netCDF-Java GRIB decoder, part of the THREDDS project by University Corporation for Atmospheric Research/Unidata.

It has been embedded in a NPM package and provides the same features as a Node.js CLI or module.

Installation

This requires Java 8 to be installed on your system and the JAVA_HOME environment variable to be positioned and point to your local Java root directory.

Java CLI

git clone <this project>

The project contains a bin folder with the latest version. The bin folder contains a grib2json CLI script for Linux-based and Windows-based OS, you should add this folder to your PATH.

Node.js CLI

npm install -g weacast-grib2json

Usage

As CLI

The grib2json CLI can be used similarly from the native OS CLI or from Node.

> grib2json --help (or node index.js --help)
Usage: grib2json (or node index.js) [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)
	[--precision -p value] : limit precision in output file using the given number of digits after the decimal point
    	[--verbose -v] : enable logging to stdout

For example, the following command outputs to stdout the records for parameter 2 (U-component_of_wind), with surface type 103 (Specified height level above ground), and surface value 10.0 meters from the GRIB2 file gfs.t18z.pgrbf00.2p5deg.grib2. Notice the optional inclusion of human-readable xyzName keys and the data array:

> grib2json --names --data --fp 2 --fs 103 --fv 10.0 gfs.t18z.pgrbf00.2p5deg.grib2

[
    {
        "header":{
            "discipline":0,
            "disciplineName":"Meteorological products",
            "gribEdition":2,
            "gribLength":27759,
            "center":7,
            "centerName":"US National Weather Service - NCEP(WMC)",
            "parameterNumber":2,
            "parameterNumberName":"U-component_of_wind",
            "parameterUnit":"m.s-1",
            "surface1Type":103,
            "surface1TypeName":"Specified height level above ground",
            "surface1Value":10.0,
            ...
        },
        "data":[
            -2.12,
            -2.27,
            -2.41,
            ...
        ]
    }
]

Using Node.js

The CLI version has in this case an additional option --bufferSize <value>, or -bs <value> in short, specifying the largest amount of data in bytes allowed on stdout (defaults to 8 MB). Indeed, because in this case the Java CLI version is called from the Node.js process using child_process, output is retrieved from stdout.

Using the Docker container

When using the tool as a Docker container the arguments to the CLI have to be provided through the ARGS environment variable, with the data volume required to make input accessible within the container and get output file back the previous example becomes:

docker run --name grib2json --rm -v /mnt/data:/usr/local/data -e "ARGS=--names --data --fp 2 --fs 103 --fv 10.0 --output /usr/local/data/output.json /usr/local/data/gfs.t18z.pgrbf00.2p5deg.grib2" weacast/grib2json

As module

Just call the grib2json default export function in your code:

const grib2json = require('weacast-grib2json')
// First arg is the input file path, second arg is CLI options as JS object
grib2json('gfs.grib', {
  data: true,
  output: 'output.json'
})
.then(function (json) {
  // Do whatever with the json data, same format as output of the CLI
})

Like with the CLI version you can use the additional bufferSize option to specify the largest amount of data in bytes allowed on stdout (defaults to 8 MB), notably if you deal with large files. You can also process data only in-memory without writing any file by omitting the output:

grib2json('gfs.grib', {
  data: true,
  bufferSize: 128 * 1024 * 1024 // 128 MB
})
.then(function (json) {
  // Do whatever with the json data, same format as output of the CLI
})

Build

This requires Maven to be installed on your system.

git clone <this project>
mvn package

This creates a .tar.gz in the target directory. Unzip and untar the package in a location of choice. The package contains a bin/lib folders that should be at the same hierarchical level (e.g. in /usr). The lib folder contains all dependent libraries and the execution script set it as current LIB_PATH before executing the main jar.

A single grib2json.jar file is also generated using the maven plugin for one-jar. This is the one used to provide the CLI as a stand-alone archive in the bin directory of the project. It is up to you to pick the one you prefer.

A Docker file is also provided to get the tool ready to work within a container, from the project root run:

docker build -t weacast/grib2json .

License

FOSSA Status