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

grib2-simple

v1.1.1

Published

Tiny node.js library to parse the content of grib2 files provided by DWD

Downloads

19

Readme

grib2-simple

grib2-simple is a tiny node.js library to parse the content of grib2 files. It is implemented in plain JavaScript (and thus is not a wrapper for a C library or Java program).

grib2-simple is being developed as part of the Designetz project and only covers the functionality that is needed to parse grib2 files provided by the open data project of DWD (Deutscher Wetter Dienst). There are currently no plans to extend the library to cover the full functionality of grib2 files. This might change in the future, though.

Set of logos

License

See the LICENSE file for license rights and limitations (MIT).

Install

npm install grib2-simple

Usage

The grib2-simple project exposes a single function which parses the content of a grib2 file given as a Buffer. The result given is Array of objects as follows

[
  {
    referenceTimestamp: <<Integer>>, // the reference time as UNIX timestamp in ms,
    forecastTimestamp: <<1500001000000>>, // the forecast time as UNIX timestamp in ms,
    getValue: function(lon, lat) {...}, // a function to retrieve a value
    sections: <<Object>> // an object that contains the information of the sections
  },
  ...
]

Each Array element represents a grib2 record, whereby a grib2 file contains one or more grib2 records.

The function getValue is used to retrieve a value for given longitude and latitude in °.

Example

const grib2 = require('./index')
const fs = require('fs-extra')

async function test() {

    // load file content
  const fileContentBuffer = await fs.readFile('./sample_data/COSMODE_single_level_elements_PS_2018020500_000.grib2')

  // parse file content (this is a synchronous operation)
  // the result is an array, as multiple grib2 files can be concatenated to a single
  const grib2Array = grib2(fileContentBuffer)

  // get value at predefined coordinate
  // first parameter is longitude (East is positiv, West is negative)
  // second parameter is latitude (North is positive, South is negative)
  const value = grib2Array[0].getValue(7.13, 48.628)
  
  console.log("Reference time: " + grib2Array[0].referenceTimestamp)
  console.log("Forecast time: " + grib2Array[0].forecastTimestamp)
  console.log("Value at longitude 48.628 °N and 7.13 °E: " + value)
}

test()