0.3.2 • Published 6 years ago

dwd-grib-helper v0.3.2

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

dwd-grib-helper

dwd-grib-helper is a tiny helper package to extract timeseries data from grib files that have been downloaded by the dwd_data_crawler service.

The package is being developed and maintained by the Chair of Automation and Energy Systems at the Saarland University.

LICENSE

dwd-grib-helper is released under the ISC license.

Installation

$ npm install dwd-grib-helper

Usage

The dwd-grib-helper package exposes two functions

deriveGrib2DirectoryPath

  • purpose: derive the path to a specific directory holding .grib2.lz4 files (lz4 compressed grib2 files)
  • arguments:
      1. (String): path to the grib directory within the folder structure generated by dwd_data_crawler
      1. (Number): reference timestamp of the forecast run as UNIX EPOCH in ms resolution

extractTimeseriesDataFromGrib2Directory

  • purpose: asynchronously extract a timeseries from a given directory
  • arguments:
    1. (String): path to the directory holding the .grib2.lz4 files (lz4 compressed grib2 files) of a single foreacast run for a single
    2. (Object): location in terms of latitude and longitude of the point of interest (will automatically be rounded to grid accuracy)
  • returns (Object):
    • location: the location in terms of latitude and longitude of the actual location on the grid, stored in the grib2 files, that has been used to exract the timeseries data.
    • timeseriesData: the actual timeseries data (in terms of raw data) as Array of Object. Each Object in the Array has two attributes:
      • timestamp (Number): the timestamp of as UNIX EPOCH in ms resolution
      • value (Number): the value (invalid values are encoded as null)

Full example

const {
  deriveGrib2DirectoryPath,
  extractTimeseriesDataFromGrib2Directory
} = require('dwd-grib-helper')

async function main () {

  // derive path of directory where data is stored
  const directoryPath = deriveGrib2DirectoryPath(
    '/mnt/data/weather/cosmo-d2/grib', // must be adopted to the correct path
    1529377200000,                     // UNIX EPOCH in ms resolution for 2018-06-19 03:00 UTC
    't_2m'                             // id for temperature of air in 2m height above ground
  )

  // load and extrat timeseries data from directory
  let ts
  try {
    ts = await extractTimeseriesDataFromGrib2Directory(
      directoryPath,
      {                 // location of Saarland University
        lat: 49.256138, // 49.256138 °N
        lon: 7.041273   //  7.041273 °E
      }
    )
  } catch (error) {
    console.error('something went wrong while loading the timeseries')
    console.error(error)
    return
  }
  
  console.log('data has been loaded for location: ' + ts.location.lat ' °N, ' + ts.location.lon + '°E')
  console.log(ts.timeseriesData)
}

main()