GithubHelp home page GithubHelp logo

udsaes / dwd-csv-helper Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 1.0 247 KB

Helper package for parsing .csv- and .kmz-files provided by DWD and downloaded by dwd_data_crawler

License: ISC License

JavaScript 100.00%

dwd-csv-helper's Introduction

dwd-csv-helper

dwd-csv-helper is a tiny helper package to extract timeseries data from .csv- and .kmz-files that have been downloaded by the microservice dwd_data_crawler.

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

LICENSE

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

Installation

$ npm install dwd-csv-helper

Compatibility

Due to changes in the name and unit of some variables provided as part of the MOSMIX-forecast, the output of readTimeseriesDataMosmix was changed; this requires an update of dwd_data_access (compare the commit message)!

Usage

The dwd-csv-helper package exposes two functions.

readTimeseriesDataReport

  • Purpose: asynchronously extract a timeseries of measurement data for a given station id within a given time interval
  • Arguments:
    1. (String): path to the directory comprising the directories for the individual days of measurement data (e.g. 'SOME_PATH/weather/weather_reports/poi')
    2. (Number): inclusive start timestamp for the timeseries to be extracted as UNIX EPOCH in ms resolution (e.g. 1529280000000 for 2018-06-18 00:00 UTC)
    3. (Number): exclusive end timestamp for the timeseries to be extracted as UNIX EPOCH in ms resolution (e.g. 1529366400000 for 2018-06-19 00:00 UTC)
    4. (String): the identifier of the weather station for which to extract the timeseries (e.g. '10708' for weather station in Saarbrücken)
  • Returns (Object): a map of all timeseries items extracted.
    • The keys of the Object refer to the values in the first line of the csv files
    • The value behind the key is an Array of Object with the following attributes:
      • timestamp: the timestamp of the measurement value as UNIX EPOCH in ms resolution
      • value: the measurement value as raw value (no unit conversion)
const {
  readTimeseriesDataReport
} = require('dwd-csv-helper')

async function main () {

  // load and extrat timeseries
  let tsCollection
  try {
    tsCollection = await readTimeseriesDataReport(
      '/mnt/data/weather/weather_reports/poi', // must be adopted to the correct path
      1529280000000,                           // inclusive start timestamp: 2018-06-18 00:00 UTC
      1529366400000,                           // exclusive end timestamp: 2018-06-19 00:00 UTC
      '10708'                                  // weather station Saarbrücken
    )
  } catch (error) {
    console.error('something went wrong while extracting the timeseries')
    console.error(error)
    return
  }

  // display extracted timeseries data
  const keys = Object.keys(ts)
  for (let i = 0; i < keys.length; i++) {
    const timeseries = tsCollection[keys[i]]
    console.log(keys[i], timeseries)
  }
}

main()

readTimeseriesDataMosmix

  • Purpose:
  • Arguments:
    1. (String): path to the directory comprising the directories for the individual forecasts (e.g. 'SOME_PATH/weather/local_forecasts/poi')
    2. (Number): the reference timestamp of the forecast timeseries to be extracted as UNIX EPOCH in ms resolution (e.g. 1529301600000 for 2018-06-18 06:00 UTC)
    3. (String): the identifier of the weather station for which to extract the timeseries (e.g. '10708' for weather station in Saarbrücken)
  • Returns (Object): a map of all timeseries items extracted
    • The keys of the Object refer to the values in the first line of the csv files
    • The value behind the key is an Array of Object with the following attributes:
      • timestamp: the timestamp of the measurement value as UNIX EPOCH in ms resolution
      • value: the measurement value as raw value (no unit conversion)
const {
  readTimeseriesDataReport
} = require('dwd-csv-helper')

async function main () {

  // load and extract timeseries data for a certain forecast
  let tsCollection
  try {
    tsCollection = await readTimeseriesDataMosmix(
      '/mnt/data/weather/local_forecasts/poi', // must be adopted to the correct path
      1529301600000,                           // inclusive start timestamp: 2018-06-18 06:00 UTC
      '10708'                                  // weather station Saarbrücken
    )
  } catch (error) {
    console.error('something went wrong while extracting the timeseries')
    console.error(error)
    return
  }

  // display extracted timeseries data
  const keys = Object.keys(ts)
  for (let i = 0; i < keys.length; i++) {
    const timeseries = tsCollection[keys[i]]
    console.log(keys[i], timeseries)
  }
}

main()

Development

There are some unit tests defined in index.spec.js. They mainly check whether the output of the major functions matches some expected output, i.e. their purpose is regression testing. The necessary test data is provided in ./test/data, the expected output is stored in ./test/expected, organized using directories matching the unit tests' structure. Note that, as a consequence, unit tests that pass do not guarantee that the function actually works as intended -- passing tests just indicate that "everything works as before".

dwd-csv-helper's People

Contributors

moritzstueber avatar florianwagner avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

Forkers

knut0815

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.