Project

knmi

0.0
No commit activity in last 3 years
No release in over 3 years
A set of methods to query the KNMI HTTP get form for daily climate data and select a variety of measured parameters, from available stations, in a json style array of hashes, and if necessary convert to csv.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.5.2
~> 0.8.3
>= 0
~> 2.11.3
~> 1.0.0.beta1

Runtime

~> 1.5.0
~> 0.7.7
 Project Readme

knmi

Ruby API to access Royal Netherlands Meteorological Institute daily climate data Access climatological data as provided by the Royal Netherlands Meteorological Institute through the http get forms for daily and hourly data

This gem was constructed using information from the KNMI climate data pages here.

Installation

Requires Ruby 1.9.2

gem install httparty
gem install geokit

gem install knmi

Example Usage

Launch console e.g. irb at the command line

Quick Script

require 'knmi'

station = KNMI.station_by_id(235)
parameters = KNMI.parameters(period = "daily", params = nil, categories = ["TEMP", "WIND"])
starts = Time.utc(2010, 6, 28) # 2010 June 28th
ends = Time.utc(2010, 6, 29) # 2010 June 29th
request = KNMI.get_data(station, parameters, starts, ends)
data = KNMI.convert(parameters, request)

Elaborated Script

require 'knmi'

# Get station object by station ID
station = KNMI.station_by_id(235)

station
#=> #<KNMI::Station:0x0000010133c938> # A struct object

# Available Instance Variables
station.instance_variables
#=> [:@id, :@name, :@elevation, :@photo, :@map, :@web, :@instrumentation, :@coordinates]
station.id
#=> 235
station.name
#=>"De kooy"
station.coordinates
#=> 52.924,4.785


# Get parameter object at the time interval you wish to use "hourly" or "daily"
# Params can be a single term or an array of terms such as "TG" or ["TG", TX]
# Categories can be a single term or an array of terms such as "WIND" or ["WIND", "TEMP"]
parameters = KNMI.parameters(period = "daily", params = nil, categories = ["TEMP", "WIND"])

parameters # returns an array of parameter objects
#=> [#<KNMI::Parameters:0x000001011387e0 @parameter="TX", @category="TEMP", @description="Maximum Temperature", @validate="n.integer?", @conversion="n / 10", @units="C", @period="daily">]

# Available Instance Variables
parameters[0].instance_variables
#=>[:@parameter, :@category, :@description, :@validate, :@conversion, :@units, :@period]

parameters[0].parameter
#=> "TX"


# Define Time period of interest
starts = Time.utc(2010, 6, 28) 	# 2010 June 28th
ends = Time.utc(2010, 7, 01) 		# 2010 June 29th

# Get Data using previously retrieved objects
request = KNMI.get_data(station, parameters, starts, ends)

# Available Instance Variables
request.instance_variables
#=> [:@query, :@data]

request.query
#=>["stns=235", "vars=TX", "start=20100628", "end=20100629"]

request.data
#=>[{:STN=>"235", :YYYYMMDD=>"20100628", :TX=>"263"}, {:STN=>"235", :YYYYMMDD=>"20100629", :TX=>"225"}]

request.data[0]
#=>{:STN=>"235", :YYYYMMDD=>"20100628", :TX=>"263"}


# Convert data from storage format to operating format
data = KNMI.convert(parameters, request)

Available Parameters

All available recorded parameters can be found in the file .data/data_key.yml This file contains the parameter name, category, description, a script to validate the data, a script to convert the data to to appropriate units, units, and the appropriate period.

Daily Data

Parameter Category Description
YYYYMMDD Time Stamp
DDVEC WIND Wind Direction
FHVEC WIND Vector Mean Wind Speed
FG WIND Daily Mean Wind Speed
FHX WIND Maximum Hourly Mean Windspeed
FHXH WIND Hourly Division at Which Maximum Wind Speed Was Measured
FHN WIND Minimum Hourly Mean Windspeed
FHNH WIND Hourly Division at Which Minimum Wind Speed Was Measured
FXX WIND Maximum Instantaneous Wind Speed
FXXH WIND Hourly Division at Which Maximum Instantaneous Wind Speed Was Measured
TG TEMP Daily Mean Temperature
TN TEMP Minimum Temperature
TNH TEMP Hourly Division in Which Minimum Temperature Was Measured
TX TEMP Maximum Temperature
TXH TEMP Hourly Division in Which Maximum Temperature Was Measured
T10N TEMP Minimum Temperature at 10 Cm Above Surface
T10NH TEMP Six Hourly Division at Which Minimum Temperature at 10 Cm Above Surface Was Measured
SQ RADT Sunshine Duration
SP RADT Percent of Maximum Sunshine Duration
Q RADT Global Radiation
DR PRCP Precipitation Duration
RH PRCP Daily Precipitation
RHX PRCP Maximum Hourly Precipitation
RHXH PRCP Hourly Division in Which Maximum Hourly Precipitation Was Measured
EV24 ATMS Potential Evapotranspiration
PG ATMS Daily Mean Sea Level Pressure
PX ATMS Maximum Hourly Sea Level Pressure
PXH ATMS Hourly Division on Which Maximum Hourly Sea Level Pressure Was Measured
PN ATMS Minimum Hourly Sea Level Pressure
PNH ATMS Hourly Division in Which Minimum Hourly Sea Level Pressure Was Measured
VVN VISB Minimum Visibility
VVNH VISB Hourly Division in Which Minimum Visibility Was Measured
VVX VISB Maximum Visibility
VVXH VISB Hourly Division in Which Maximum Visibility Was Measured
NG VISB Mean Daily Cloud Cover
UG ATMS Daily Mean Relative Humidity
UX ATMS Maximum Relative Humidity
UXH ATMS Hourly Division in Which Maximum Relative Humidity Was Measured
UN ATMS Minimum Relative Humidity
UNH ATMS Hourly Division in Which Minimum Relative Humidity Was Measured

Hourly Data

Parameter Category Description
YYYYMMDD Time Stamp
HH Hour
DD WIND Mean wind direction during the 10-minute period preceding the time of observation
FH WIND Hourly mean wind speed
FF WIND Mean wind speed
FX WIND Maximum wind gust
T TEMP Air Temperature at 1.5 m
T10N TEMP Minimum Air Temperature at 10 cm in the preceding 6 hours
TD TEMP Dew Point Temperature
SQ RDTN Sunshine Duration
Q RDTN Golbal Radiation
DR PRCP Precipitation Duration
RH PRCP Precipitation
P ATMS Air Pressure
VV VISB Visibility
N VISB Cloud Cover
U ATMS Relative Humidity
M WTHR Fog
R WTHR Rainfall
S WTHR Snow
O WTHR Thunder
Y WTHR Ice
WW WTHR Weather Code

TODO

Write unit tests for lib/calculations/calculations.rb

Please Note the license included in the header source header

# DEZE GEGEVENS MOGEN VRIJ WORDEN GEBRUIKT MITS DE VOLGENDE BRONVERMELDING WORDT GEGEVEN:
# KONINKLIJK NEDERLANDS METEOROLOGISCH INSTITUUT (KNMI)
#
# THESE DATA CAN BE USED FREELY PROVIDED THAT THE FOLLOWING SOURCE IS ACKNOWLEDGED:
# ROYAL NETHERLANDS METEOROLOGICAL INSTITUTE

Copyright

Copyright (c) 2011 Patrick Galvin Schmitz p.schmitz@gmail.com. See LICENSE.txt for further details.

Copyright (c) 2008 Mat Brown Portions of stations.rb were adapted from Mat Brown's https://github.com/outoftime/noaa