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.
dwd-grib-helper
is released under the ISC license.
$ npm install dwd-grib-helper
The dwd-grib-helper
package exposes two functions
- purpose: derive the path to a specific directory holding .grib2.lz4 files (lz4 compressed grib2 files)
- arguments:
-
- (
String
): path to the grib directory within the folder structure generated bydwd_data_crawler
- (
-
- (
Number
): reference timestamp of the forecast run as UNIX EPOCH in ms resolution
- (
-
- purpose: asynchronously extract a timeseries from a given directory
- arguments:
- (
String
): path to the directory holding the .grib2.lz4 files (lz4 compressed grib2 files) of a single foreacast run for a single - (
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 ofObject
. EachObject
in the Array has two attributes:timestamp
(Number
): the timestamp of as UNIX EPOCH in ms resolutionvalue
(Number
): the value (invalid values are encoded as null)
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()