knmi 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mkdn +193 -0
- data/VERSION +1 -1
- data/knmi.gemspec +7 -6
- data/lib/knmi.rb +86 -23
- data/lib/knmi/calculations.rb +185 -0
- data/lib/knmi/httpservice.rb +39 -14
- data/lib/knmi/parameters.rb +27 -16
- data/lib/knmi/station.rb +29 -14
- data/test/test_calculations.rb +5 -0
- data/test/test_httpservice.rb +5 -5
- data/test/test_knmi.rb +33 -13
- metadata +8 -7
- data/.DS_Store +0 -0
- data/README.rdoc +0 -132
- data/lib/.DS_Store +0 -0
data/README.mkdn
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
knmi
|
2
|
+
====
|
3
|
+
|
4
|
+
Ruby API to access Royal Netherlands Meteorological Institute daily climate data
|
5
|
+
Access climatological data as provided by the Royal Netherlands Meteorological Institute through the http get forms for daily and hourly data
|
6
|
+
|
7
|
+
* http://www.knmi.nl/climatology/daily_data/getdata_day.cgi
|
8
|
+
* http://www.knmi.nl/klimatologie/uurgegevens/getdata_uur.cgi
|
9
|
+
|
10
|
+
This gem was constructed using information from the KNMI climate data pages here.
|
11
|
+
|
12
|
+
* Hourly data (Dutch) - http://www.knmi.nl/klimatologie/uurgegevens/scriptxs-nl.html#uur
|
13
|
+
* Daily data (English) - http://www.knmi.nl/climatology/daily_data/scriptxs-en.html
|
14
|
+
* Select Data with a form, listed below are links to metadata about each station http://www.knmi.nl/climatology/daily_data/selection.cgi
|
15
|
+
|
16
|
+
Installation
|
17
|
+
------------
|
18
|
+
gem install httparty
|
19
|
+
gem install geokit
|
20
|
+
|
21
|
+
gem install knmi
|
22
|
+
|
23
|
+
Example Usage
|
24
|
+
-------------
|
25
|
+
|
26
|
+
# Quick Script
|
27
|
+
|
28
|
+
require 'knmi'
|
29
|
+
|
30
|
+
station = KNMI.station_by_id(235)
|
31
|
+
parameter = KNMI.parameters(period = "daily", params = nil, categories = ["TEMP", "WIND"])
|
32
|
+
starts = Time.utc(2010, 6, 28) # 2010 April 28th
|
33
|
+
ends = Time.utc(2010, 6, 29) # 2010 April 29th
|
34
|
+
request = KNMI.get_data(station, parameter, starts, ends)
|
35
|
+
data = KNMI::Calculations.convert(request.data)
|
36
|
+
|
37
|
+
# Elaborated Script
|
38
|
+
|
39
|
+
require 'knmi'
|
40
|
+
|
41
|
+
# Get station object by station ID
|
42
|
+
station = KNMI.station_by_id(235)
|
43
|
+
|
44
|
+
station
|
45
|
+
#=> #<KNMI::Station:0x0000010133c938> # A struct object
|
46
|
+
|
47
|
+
# Available Instance Variables
|
48
|
+
station.instance_variables
|
49
|
+
#=> [:@id, :@name, :@elevation, :@photo, :@map, :@web, :@instrumentation, :@coordinates]
|
50
|
+
station.id
|
51
|
+
#=> 235
|
52
|
+
station.name
|
53
|
+
#=>"De kooy"
|
54
|
+
station.coordinates
|
55
|
+
#=> 52.924,4.785
|
56
|
+
|
57
|
+
|
58
|
+
# Get parameter object at the time interval you wish to use "hourly" or "daily"
|
59
|
+
# Params can be a single term or an array of terms such as "TG" or ["TG", TX]
|
60
|
+
# Categories can be a single term or an array of terms such as "WIND" or ["WIND", "TEMP"]
|
61
|
+
parameters = KNMI.parameters(period = "daily", params = nil, categories = ["TEMP", "WIND"])
|
62
|
+
|
63
|
+
parameters # returns an array of parameter objects
|
64
|
+
#=> [#<KNMI::Parameters:0x000001011387e0 @parameter="TX", @category="TEMP", @description="Maximum Temperature", @validate="n.integer?", @conversion="n / 10", @units="C", @period="daily">]
|
65
|
+
|
66
|
+
# Available Instance Variables
|
67
|
+
parameters[0].instance_variables
|
68
|
+
#=>[:@parameter, :@category, :@description, :@validate, :@conversion, :@units, :@period]
|
69
|
+
|
70
|
+
parameters[0].parameter
|
71
|
+
#=> "TX"
|
72
|
+
|
73
|
+
|
74
|
+
# Define Time period of interest
|
75
|
+
starts = Time.utc(2010, 6, 28) # 2010 April 28th
|
76
|
+
ends = Time.utc(2010, 7, 01) # 2010 April 29th
|
77
|
+
|
78
|
+
# Get Data using previously retrieved objects
|
79
|
+
request = KNMI.get_data(station, parameters, starts, ends)
|
80
|
+
|
81
|
+
# Available Instance Variables
|
82
|
+
request.instance_variables
|
83
|
+
#=> [:@query, :@data]
|
84
|
+
|
85
|
+
request.query
|
86
|
+
#=>["stns=235", "vars=TX", "start=20100628", "end=20100629"]
|
87
|
+
|
88
|
+
request.data
|
89
|
+
#=>[{:STN=>"235", :YYYYMMDD=>"20100628", :TX=>"263"}, {:STN=>"235", :YYYYMMDD=>"20100629", :TX=>"225"}]
|
90
|
+
|
91
|
+
request.data[0]
|
92
|
+
#=>{:STN=>"235", :YYYYMMDD=>"20100628", :TX=>"263"}
|
93
|
+
|
94
|
+
|
95
|
+
# Convert data from storage format to operating format
|
96
|
+
data = KNMI.convert(parameters, request)
|
97
|
+
|
98
|
+
Available Parameters
|
99
|
+
--------------------
|
100
|
+
All available recorded parameters can be found in the file .data/data_key.yml
|
101
|
+
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.
|
102
|
+
|
103
|
+
Daily Data
|
104
|
+
----------
|
105
|
+
|Parameter|Category|Description|
|
106
|
+
|:--------|:-------|:----------|
|
107
|
+
|YYYYMMDD | | Time Stamp|
|
108
|
+
|DDVEC |WIND | Wind Direction |
|
109
|
+
|FHVEC |WIND | Vector Mean Wind Speed|
|
110
|
+
|FG |WIND | Daily Mean Wind Speed|
|
111
|
+
|FHX |WIND | Maximum Hourly Mean Windspeed|
|
112
|
+
|FHXH |WIND | Hourly Division at Which Maximum Wind Speed Was Measured|
|
113
|
+
|FHN |WIND | Minimum Hourly Mean Windspeed|
|
114
|
+
|FHNH |WIND | Hourly Division at Which Minimum Wind Speed Was Measured|
|
115
|
+
|FXX |WIND | Maximum Instantaneous Wind Speed|
|
116
|
+
|FXXH |WIND | Hourly Division at Which Maximum Instantaneous Wind Speed Was Measured|
|
117
|
+
|TG |TEMP | Daily Mean Temperature|
|
118
|
+
|TN |TEMP | Minimum Temperature|
|
119
|
+
|TNH |TEMP | Hourly Division in Which Minimum Temperature Was Measured|
|
120
|
+
|TX |TEMP | Maximum Temperature|
|
121
|
+
|TXH |TEMP | Hourly Division in Which Maximum Temperature Was Measured|
|
122
|
+
|T10N |TEMP | Minimum Temperature at 10 Cm Above Surface|
|
123
|
+
|T10NH |TEMP | Six Hourly Division at Which Minimum Temperature at 10 Cm Above Surface Was Measured|
|
124
|
+
|SQ |RADT | Sunshine Duration|
|
125
|
+
|SP |RADT | Percent of Maximum Sunshine Duration|
|
126
|
+
|Q |RADT | Global Radiation|
|
127
|
+
|DR |PRCP | Precipitation Duration|
|
128
|
+
|RH |PRCP | Daily Precipitation|
|
129
|
+
|RHX |PRCP | Maximum Hourly Precipitation|
|
130
|
+
|RHXH |PRCP | Hourly Division in Which Maximum Hourly Precipitation Was Measured|
|
131
|
+
|EV24 |ATMS | Potential Evapotranspiration|
|
132
|
+
|PG |ATMS | Daily Mean Sea Level Pressure|
|
133
|
+
|PX |ATMS | Maximum Hourly Sea Level Pressure|
|
134
|
+
|PXH |ATMS | Hourly Division on Which Maximum Hourly Sea Level Pressure Was Measured|
|
135
|
+
|PN |ATMS | Minimum Hourly Sea Level Pressure|
|
136
|
+
|PNH |ATMS | Hourly Division in Which Minimum Hourly Sea Level Pressure Was Measured|
|
137
|
+
|VVN |VISB | Minimum Visibility|
|
138
|
+
|VVNH |VISB | Hourly Division in Which Minimum Visibility Was Measured|
|
139
|
+
|VVX |VISB | Maximum Visibility|
|
140
|
+
|VVXH |VISB | Hourly Division in Which Maximum Visibility Was Measured|
|
141
|
+
|NG |VISB | Mean Daily Cloud Cover|
|
142
|
+
|UG |ATMS | Daily Mean Relative Humidity|
|
143
|
+
|UX |ATMS | Maximum Relative Humidity|
|
144
|
+
|UXH |ATMS | Hourly Division in Which Maximum Relative Humidity Was Measured|
|
145
|
+
|UN |ATMS | Minimum Relative Humidity|
|
146
|
+
|UNH |ATMS | Hourly Division in Which Minimum Relative Humidity Was Measured|
|
147
|
+
|
148
|
+
Hourly Data
|
149
|
+
-----------
|
150
|
+
|Parameter|Category|Description|
|
151
|
+
|:--------|:-------|:----------|
|
152
|
+
|YYYYMMDD | | Time Stamp|
|
153
|
+
|HH | |Hour |
|
154
|
+
|DD |WIND | Mean wind direction during the 10-minute period preceding the time of observation|
|
155
|
+
|FH |WIND | Hourly mean wind speed|
|
156
|
+
|FF |WIND | Mean wind speed|
|
157
|
+
|FX |WIND | Maximum wind gust|
|
158
|
+
|T |TEMP | Air Temperature at 1.5 m|
|
159
|
+
|T10N |TEMP | Minimum Air Temperature at 10 cm in the preceding 6 hours|
|
160
|
+
|TD |TEMP | Dew Point Temperature|
|
161
|
+
|SQ |RDTN | Sunshine Duration|
|
162
|
+
|Q |RDTN | Golbal Radiation|
|
163
|
+
|DR |PRCP | Precipitation Duration|
|
164
|
+
|RH |PRCP | Precipitation|
|
165
|
+
|P |ATMS | Air Pressure|
|
166
|
+
|VV |VISB | Visibility|
|
167
|
+
|N |VISB | Cloud Cover|
|
168
|
+
|U |ATMS | Relative Humidity|
|
169
|
+
|M |WTHR | Fog|
|
170
|
+
|R |WTHR | Rainfall|
|
171
|
+
|S |WTHR | Snow|
|
172
|
+
|O |WTHR | Thunder|
|
173
|
+
|Y |WTHR | Ice|
|
174
|
+
|WW |WTHR | Weather Code|
|
175
|
+
|
176
|
+
TODO
|
177
|
+
----
|
178
|
+
|
179
|
+
Write unit tests for lib/calculations/calculations.rb
|
180
|
+
|
181
|
+
Please Note the license included in the header source header
|
182
|
+
---------------------------------------------------------------
|
183
|
+
# DEZE GEGEVENS MOGEN VRIJ WORDEN GEBRUIKT MITS DE VOLGENDE BRONVERMELDING WORDT GEGEVEN:
|
184
|
+
# KONINKLIJK NEDERLANDS METEOROLOGISCH INSTITUUT (KNMI)
|
185
|
+
#
|
186
|
+
# THESE DATA CAN BE USED FREELY PROVIDED THAT THE FOLLOWING SOURCE IS ACKNOWLEDGED:
|
187
|
+
# ROYAL NETHERLANDS METEOROLOGICAL INSTITUTE
|
188
|
+
|
189
|
+
Copyright
|
190
|
+
---------
|
191
|
+
|
192
|
+
Copyright (c) 2011 Patrick Galvin Schmitz p.schmitz@gmail.com. See LICENSE.txt for
|
193
|
+
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/knmi.gemspec
CHANGED
@@ -5,24 +5,23 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{knmi}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["bullfight"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-19}
|
13
13
|
s.description = %q{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.}
|
14
14
|
s.email = %q{p.schmitz@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.mkdn"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
".DS_Store",
|
21
20
|
".document",
|
22
21
|
"Gemfile",
|
23
22
|
"Gemfile.lock",
|
24
23
|
"LICENSE.txt",
|
25
|
-
"README.
|
24
|
+
"README.mkdn",
|
26
25
|
"Rakefile",
|
27
26
|
"VERSION",
|
28
27
|
"data/current_stations.yml",
|
@@ -30,12 +29,13 @@ Gem::Specification.new do |s|
|
|
30
29
|
"data/data_key.yml",
|
31
30
|
"data/hourly_data_key.yml",
|
32
31
|
"knmi.gemspec",
|
33
|
-
"lib/.DS_Store",
|
34
32
|
"lib/knmi.rb",
|
33
|
+
"lib/knmi/calculations.rb",
|
35
34
|
"lib/knmi/httpservice.rb",
|
36
35
|
"lib/knmi/parameters.rb",
|
37
36
|
"lib/knmi/station.rb",
|
38
37
|
"test/helper.rb",
|
38
|
+
"test/test_calculations.rb",
|
39
39
|
"test/test_httpservice.rb",
|
40
40
|
"test/test_knmi.rb",
|
41
41
|
"test/test_parameters.rb",
|
@@ -48,6 +48,7 @@ Gem::Specification.new do |s|
|
|
48
48
|
s.summary = %q{Ruby API to access daily climate data from the Royal Netherlands Meteorological Institute}
|
49
49
|
s.test_files = [
|
50
50
|
"test/helper.rb",
|
51
|
+
"test/test_calculations.rb",
|
51
52
|
"test/test_httpservice.rb",
|
52
53
|
"test/test_knmi.rb",
|
53
54
|
"test/test_parameters.rb",
|
data/lib/knmi.rb
CHANGED
@@ -8,41 +8,79 @@ rescue LoadError => e
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
%w(station parameters httpservice).each { |file| require File.join(File.dirname(__FILE__), 'knmi', file) }
|
11
|
+
%w(station parameters httpservice calculations).each { |file| require File.join(File.dirname(__FILE__), 'knmi', file) }
|
12
12
|
|
13
13
|
module KNMI
|
14
14
|
|
15
15
|
class << self
|
16
16
|
|
17
|
-
#
|
18
17
|
# Get nearest station by lat lng
|
19
|
-
#
|
18
|
+
#
|
19
|
+
# @param lat [Numeric] - latitude e.g. 52.165
|
20
|
+
# @param lng [Numeric] - longitude e.g. 52.165
|
21
|
+
# @param [Array] [] - [lat, lng] e.g. [52.165, 4,419] *eqivalent to (lat, lng)*
|
22
|
+
# @param [GeoKit::LatLng] - Geokit object e.g. GeoKit::LatLng.new(52.165, 4.419) *eqivalent to (lat, lng)*
|
23
|
+
# @return [KNMI::Station] - Object with details about the station nearest to the requested lat/lng
|
24
|
+
#
|
25
|
+
# @example Get nearest station by lat, lng
|
26
|
+
# KNMI.station_by_location(52.165, 52.165)
|
27
|
+
#
|
28
|
+
# @example Get nearest station by [lat, lng]
|
29
|
+
# KNMI.station_by_location([52.165, 52.165])
|
30
|
+
#
|
31
|
+
# @example Get nearest station with GeoKit object
|
32
|
+
# KNMI.station_by_location(GeoKit::LatLng.new(52.165, 4.419))
|
33
|
+
#
|
20
34
|
def station_by_location(lat, lng)
|
21
35
|
Station.closest_to(lat, lng)
|
22
36
|
end
|
23
37
|
|
24
|
-
#
|
25
38
|
# Get station object by station ID
|
26
|
-
#
|
39
|
+
#
|
40
|
+
# @param station_id [String, Numeric] - number of station of interest, station_ids can be found in
|
41
|
+
# @return [KNMI::Station] - Object with details about the requested station
|
42
|
+
#
|
43
|
+
# @example Get station by ID
|
44
|
+
# KNMI.station_by_id(210)
|
45
|
+
#
|
27
46
|
def station_by_id(station_id)
|
28
47
|
Station.find(station_id)
|
29
48
|
end
|
30
49
|
|
50
|
+
# Get an array of parameter objects
|
31
51
|
#
|
32
|
-
# Generate array of unique daily or hourly parameter objects
|
33
52
|
# All details in daily_data_key.yml and hourly_data_key.yml
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
53
|
+
# @param [string] period - "daily" or "hourly"
|
54
|
+
# @param [Array<string>] params - array of parameters e.g ["TX", "TG"]
|
55
|
+
# @param [Array<string>] categories - array of categories e.g. ["WIND", "TEMP"]
|
56
|
+
# @return [Array<KNMI::Parameters>] - array of KNMI::Parameters objects
|
57
|
+
#
|
58
|
+
# @example Get daily station data and a single parameter
|
59
|
+
# KNMI.parameters("daily", "TX")
|
60
|
+
#
|
61
|
+
# @example Get hourly station data and a multiple parameters
|
62
|
+
# KNMI.parameters("hourly", ["TX", "TG"])
|
63
|
+
#
|
64
|
+
# @example Get hourly station data and a multiple categories
|
65
|
+
# KNMI.parameters("daily", nil, ["WIND", "TEMP"])
|
66
|
+
#
|
67
|
+
def parameters(period, params = nil, categories = nil)
|
68
|
+
if params.nil? and categories.nil?
|
69
|
+
|
41
70
|
list = Parameters.all(period)
|
42
|
-
|
43
|
-
|
71
|
+
|
72
|
+
elsif categories.nil?
|
44
73
|
|
74
|
+
# Parameters by name
|
75
|
+
list = []
|
76
|
+
params = unique_params(params, list) #ensure params are unique to list
|
77
|
+
list << Parameters.find(period, params)
|
78
|
+
list.flatten!
|
79
|
+
list.compact!
|
80
|
+
else
|
81
|
+
|
45
82
|
# Parameters by category
|
83
|
+
list = []
|
46
84
|
list << Parameters.category(period, categories)
|
47
85
|
list.flatten!
|
48
86
|
|
@@ -55,17 +93,42 @@ module KNMI
|
|
55
93
|
return list
|
56
94
|
end
|
57
95
|
|
96
|
+
# Retrieve climate data from a weather station
|
97
|
+
#
|
98
|
+
# @param station [KNMI::Station] - station object retrieved with KNMI.station_by_id() or KNMI.station_by_location()
|
99
|
+
# @param parameters [Array<KNMI::Parameters>] - parameters object retrieved with KNMI.parameters()
|
100
|
+
# @param starts [Time] - Time object e.g. Time.utc(2010, 6, 28)
|
101
|
+
# @param ends [Time] - Time object e.g. Time.utc(2010, 6, 29)
|
102
|
+
# @param seasonal [Boolean]
|
58
103
|
#
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
elsif
|
66
|
-
HttpService.get_hourly(
|
104
|
+
# @return [KNMI::HttpService]
|
105
|
+
def get_data(station, parameters, starts = nil, ends = nil, seasonal = false)
|
106
|
+
|
107
|
+
if parameters[0].period == "daily"
|
108
|
+
HttpService.get_daily(station, parameters, starts, ends, seasonal)
|
109
|
+
|
110
|
+
elsif parameters[0].period == "hourly"
|
111
|
+
HttpService.get_hourly(station, parameters, starts, ends, seasonal)
|
112
|
+
|
67
113
|
end
|
68
114
|
end
|
115
|
+
|
116
|
+
# Input data request object and return array of hashes converted from storage to operable units.
|
117
|
+
#
|
118
|
+
# @param parameters [KNMI::Stations] - Parameters object
|
119
|
+
# @param request [KNMI:HttpService] - Data object from HttpRequest
|
120
|
+
#
|
121
|
+
# @return [Hash] - Hash containing climate data in operable units
|
122
|
+
def convert(parameters, request)
|
123
|
+
|
124
|
+
if parameters[0].period == "daily"
|
125
|
+
KNMI::Calculations.convert_daily(request.data)
|
126
|
+
|
127
|
+
elsif parameters[0].period == "hourly"
|
128
|
+
KNMI::Calculations.convert_hourly(request.data)
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
69
132
|
|
70
133
|
|
71
134
|
private
|
@@ -0,0 +1,185 @@
|
|
1
|
+
module KNMI
|
2
|
+
class Calculations
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# Converts Daily KNMI.get_data().data from storage to operable units
|
6
|
+
#
|
7
|
+
# @param [Array<Hash>] array - in storage format (integers)
|
8
|
+
# @return [Array<Hash>] - in operable format (Float, Integer, Time)
|
9
|
+
def convert_daily(array)
|
10
|
+
x = []
|
11
|
+
|
12
|
+
array.each_with_index do |a, index|
|
13
|
+
x[index] = {}
|
14
|
+
x[index][:stn] = a
|
15
|
+
a.each_pair { |key,value| x[index].merge!( {key => converts_daily(key, value)} ) }
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
return x
|
20
|
+
end
|
21
|
+
|
22
|
+
# Converts Hourly KNMI.get_data().data from storage to operable units
|
23
|
+
#
|
24
|
+
# @param [Array<Hash>] array - Array of hashes, in storage format (integers)
|
25
|
+
# @return [Array<Hash>] - Array of hashes, in operable format (Float, Integer, Time)
|
26
|
+
def convert_hourly(array)
|
27
|
+
x = []
|
28
|
+
|
29
|
+
array.each_with_index do |a, index|
|
30
|
+
x[index] = {}
|
31
|
+
a.each_pair { |key,value| x[index].merge!( {key => converts_daily(key, value)} ) }
|
32
|
+
x[index][:Time] = x[index][:YYYYMMDD] + x[index][:HH]
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
return x
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def converts_daily( key, n )
|
42
|
+
if key == :STN
|
43
|
+
n
|
44
|
+
elsif [:FHVEC, :FG, :FHX, :FHN, :FXX, :TG, :TN, :TX, :T10N, :RH, :EV24, :PG, :PX, :PN].include?(key)
|
45
|
+
|
46
|
+
n.integer? ? n.to_f / 10 : nil
|
47
|
+
|
48
|
+
elsif [:FHXH, :FHNH, :FXXH, :TNH, :TXH, :RHXH, :PXH, :PNH, :VVNH, :VVXH, :UXH, :UNH].include?(key)
|
49
|
+
|
50
|
+
(1..24).include?(n) ? n : nil
|
51
|
+
|
52
|
+
elsif [:SP, :UG, :UX, :UN].include?(key)
|
53
|
+
|
54
|
+
(0..100).include?(n) ? n : nil
|
55
|
+
|
56
|
+
elsif [:RHX].include?(key)
|
57
|
+
|
58
|
+
n = n.integer? ? n : nil
|
59
|
+
return n == -1 ? 0.05 : n.to_f / 10
|
60
|
+
|
61
|
+
elsif [:Q].include?(key)
|
62
|
+
|
63
|
+
n.integer? ? n : nil
|
64
|
+
|
65
|
+
elsif [:DR].include?(key)
|
66
|
+
|
67
|
+
(0..6).include?(n) ? (n.to_f / 10) * 60 : nil
|
68
|
+
|
69
|
+
elsif [:DDVEC].include?(key)
|
70
|
+
|
71
|
+
(0..360).include?(n) ? n : nil
|
72
|
+
|
73
|
+
elsif [:SQ].include?(key)
|
74
|
+
|
75
|
+
n = (-1..6).include?(n) ? n : nil
|
76
|
+
return n == -1 ? 0.05 : (n.to_f / 10) * 60
|
77
|
+
|
78
|
+
elsif [:T10NH].include?(key)
|
79
|
+
|
80
|
+
(6..24).step(6).include?(n) ? n : nil
|
81
|
+
|
82
|
+
elsif [:NG].include?(key)
|
83
|
+
|
84
|
+
(0..9).include?(n) ? n : nil
|
85
|
+
|
86
|
+
elsif [:YYYYMMDD].include?(key)
|
87
|
+
|
88
|
+
Time.utc(
|
89
|
+
year = n.to_s[(0..3)],
|
90
|
+
month = n.to_s[(4..5)],
|
91
|
+
day = n.to_s[(6..7)]
|
92
|
+
)
|
93
|
+
|
94
|
+
elsif [:VVN, :VVX].include?(key)
|
95
|
+
|
96
|
+
if n == 0
|
97
|
+
'< 100 meters'
|
98
|
+
elsif (1..49).include?(n)
|
99
|
+
(n * 100).to_s + '-' + ((n+1) * 100).to_s + ' meters'
|
100
|
+
elsif n == 50
|
101
|
+
'5-6 kilometers'
|
102
|
+
elsif (56..79).include?(n)
|
103
|
+
(n - 50).to_s + '-' + (n - 49).to_s + ' kilometers'
|
104
|
+
elsif (80..88).include?(n)
|
105
|
+
(n - 50).to_s + '-' + (n - 45).to_s + ' kilometers'
|
106
|
+
elsif n == 89
|
107
|
+
'> 70 kilometers'
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def converts_hourly( key, n )
|
115
|
+
if key == :STN
|
116
|
+
|
117
|
+
n
|
118
|
+
|
119
|
+
elsif [:FH, :FF, :FX, :T, :T10N, :TD, :RH, :P].include?(key)
|
120
|
+
|
121
|
+
n.integer? ? n.to_f / 10 : nil
|
122
|
+
|
123
|
+
elsif [:M, :R, :S, :O, :Y].include?(key)
|
124
|
+
|
125
|
+
(0..1).include?(n) ? n : nil
|
126
|
+
|
127
|
+
elsif key == :SQ
|
128
|
+
|
129
|
+
(-1..240).include?(n) ? n : nil
|
130
|
+
return n == -1 ? 0.05 : (n / 10) * 60
|
131
|
+
|
132
|
+
elsif key == :U
|
133
|
+
|
134
|
+
(0..100).include?(n) ? n : nil
|
135
|
+
|
136
|
+
elsif key == :DR
|
137
|
+
|
138
|
+
(0..240).include?(n) ? (n / 10) * 60 : nil
|
139
|
+
|
140
|
+
elsif key == :DD
|
141
|
+
|
142
|
+
(0..360).to_a.push(990).include?(n) ? n : nil
|
143
|
+
|
144
|
+
elsif key == :N
|
145
|
+
|
146
|
+
(0..9).include?(n) ? n : nil
|
147
|
+
|
148
|
+
elsif key == :WW
|
149
|
+
|
150
|
+
(0..99).include?(n) ? n : nil
|
151
|
+
|
152
|
+
elsif key == :HH
|
153
|
+
|
154
|
+
(1..24).include?(n) ? n : nil
|
155
|
+
|
156
|
+
elsif [:YYYYMMDD].include?(key)
|
157
|
+
|
158
|
+
Time.utc(
|
159
|
+
year = n.to_s[(0..3)],
|
160
|
+
month = n.to_s[(4..5)],
|
161
|
+
day = n.to_s[(6..7)]
|
162
|
+
)
|
163
|
+
|
164
|
+
elsif [:VVN, :VVX].include?(key)
|
165
|
+
|
166
|
+
if n == 0
|
167
|
+
'< 100 meters'
|
168
|
+
elsif (1..49).include?(n)
|
169
|
+
(n * 100).to_s + '-' + ((n+1) * 100).to_s + ' meters'
|
170
|
+
elsif n == 50
|
171
|
+
'5-6 kilometers'
|
172
|
+
elsif (56..79).include?(n)
|
173
|
+
(n - 50).to_s + '-' + (n - 49).to_s + ' kilometers'
|
174
|
+
elsif (80..88).include?(n)
|
175
|
+
(n - 50).to_s + '-' + (n - 45).to_s + ' kilometers'
|
176
|
+
elsif n == 89
|
177
|
+
'> 70 kilometers'
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
data/lib/knmi/httpservice.rb
CHANGED
@@ -5,25 +5,43 @@ module KNMI
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
|
8
|
-
|
8
|
+
# Requests Daily data
|
9
|
+
#
|
10
|
+
# @param station_object [KNMI::Station] - Station Object
|
11
|
+
# @param parameter_object [KNMI::Parameters] - Parameter Object
|
12
|
+
# @param starts [Time] - Time Object
|
13
|
+
# @param ends [Time] - Time Object
|
14
|
+
# @param seasonal [Boolean]
|
15
|
+
# @return [KNMI::HttpService]
|
16
|
+
#
|
17
|
+
def get_daily(station_object, parameters_object, starts = nil, ends = nil, seasonal = false)
|
9
18
|
# select YYYYMMDD (drops hour term)
|
10
|
-
query = [station(station_object), parameters(
|
11
|
-
start_date(
|
19
|
+
query = [station(station_object), parameters(parameters_object),
|
20
|
+
start_date(starts)[0..13], end_date(ends)[0..11],
|
12
21
|
seasonal(seasonal)].compact
|
13
22
|
result = get('http://www.knmi.nl/climatology/daily_data/getdata_day.cgi', { :query => "#{query * "&"}" } )
|
14
23
|
|
15
|
-
data = parse(station_object,
|
24
|
+
data = parse(station_object, parameters_object, result)
|
16
25
|
|
17
26
|
return new({"query" => query, "data" => data})
|
18
27
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
28
|
+
|
29
|
+
# Requests Hourly data
|
30
|
+
#
|
31
|
+
# @param station_object [KNMI::Station] - Station Object
|
32
|
+
# @param parameter_object [KNMI::Parameters] - Parameter Object
|
33
|
+
# @param starts [Time] - Time Object
|
34
|
+
# @param ends [Time] - Time Object
|
35
|
+
# @param seasonal [Boolean]
|
36
|
+
# @return [KNMI::HttpService]
|
37
|
+
#
|
38
|
+
def get_hourly(station_object, parameters_object, starts = nil, ends = nil, seasonal = false)
|
39
|
+
query = [station(station_object), parameters(parameters_object),
|
40
|
+
start_date(starts), end_date(ends),
|
23
41
|
seasonal(seasonal)].compact
|
24
42
|
result = get('http://www.knmi.nl/klimatologie/uurgegevens/getdata_uur.cgi', { :query => "#{query * "&"}" } )
|
25
43
|
|
26
|
-
data = parse(station_object,
|
44
|
+
data = parse(station_object, parameters_object, result)
|
27
45
|
|
28
46
|
return new({"query" => query, "data" => data})
|
29
47
|
end
|
@@ -98,7 +116,7 @@ module KNMI
|
|
98
116
|
# Parse into array and then hash with var name
|
99
117
|
data = CSV.parse(data, {:skip_blanks => true})
|
100
118
|
header = data.shift.map {|i| i.to_s.intern }
|
101
|
-
string_data = data.map {|row| row.map {|cell| cell.
|
119
|
+
string_data = data.map {|row| row.map {|cell| cell.to_i } }
|
102
120
|
data = string_data.map {|row| Hash[*header.zip(row).flatten] }
|
103
121
|
|
104
122
|
return data
|
@@ -106,14 +124,21 @@ module KNMI
|
|
106
124
|
|
107
125
|
end
|
108
126
|
|
109
|
-
#
|
110
127
|
# Returns query string used in HTTP get request
|
111
|
-
#
|
128
|
+
#
|
129
|
+
# @return [Array<string>] - array of strings which contains the components used in the HTTP request
|
130
|
+
#
|
131
|
+
# @example
|
132
|
+
# KNMI::HttpService.get_daily(station, parameter).query
|
133
|
+
# =>[ "stns=210", "vars=ALL", "start=2011051500", "end=2011051613"]
|
112
134
|
attr_reader :query
|
113
135
|
|
114
|
-
#
|
115
136
|
# Parsed HTTP request
|
116
|
-
#
|
137
|
+
#
|
138
|
+
# @return [Array<Hash>] - array of hashes which contains climate data in storage(integer) format
|
139
|
+
# @example
|
140
|
+
# KNMI::HttpService.get_daily(station, parameter).data
|
141
|
+
# =>[{:STN=>"235", :YYYYMMDD=>"20100628", :TX=>"263"}, {:STN=>"235", :YYYYMMDD=>"20100629", :TX=>"225"}]
|
117
142
|
attr_reader :data
|
118
143
|
|
119
144
|
def initialize(properties)
|
data/lib/knmi/parameters.rb
CHANGED
@@ -3,11 +3,16 @@ module KNMI
|
|
3
3
|
class << self
|
4
4
|
attr_writer :keys_file
|
5
5
|
|
6
|
+
# Retrieve Parameter Object by named parameter
|
6
7
|
#
|
7
|
-
#
|
8
|
+
# @param period [String] - "daily" or "hourly"
|
9
|
+
# @param parameter [Array, String] - Array of strings or string of parameter name
|
10
|
+
# @return [Array<KNMI::Parameters>] - array of parameter objects
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# KNMI::Parameter.find(period = "daily", "TA")
|
14
|
+
# KNMI::Parameter.find(period = "daily", ["TG", "TX"])
|
8
15
|
#
|
9
|
-
# KNMI::Parameter.find(period = "daily", "TA") #=> KNMI::Parameter object for TG (Daily Max temperature)
|
10
|
-
# KNMI::Parameter.find(period = "daily", ["TG", "TX"]) #=> KNMI::Parameter array of objects TG (Daily Mean temperature) and TX (Daily Max Temperature)
|
11
16
|
def find(period, parameter)
|
12
17
|
parameter = [parameter].flatten
|
13
18
|
|
@@ -19,12 +24,16 @@ module KNMI
|
|
19
24
|
return list
|
20
25
|
end
|
21
26
|
|
27
|
+
# Retrieve Parameter Object by named parameter
|
28
|
+
#
|
29
|
+
# @param period [String] - "daily" or "hourly"
|
30
|
+
# @param category [Array, String] - Array of strings or string of category name
|
31
|
+
# @return [Array<KNMI::Parameters>] - array of parameter objects
|
22
32
|
#
|
23
|
-
#
|
24
|
-
#
|
33
|
+
# @example
|
34
|
+
# KNMI.Parameter.category(period = "daily, ""WIND")
|
35
|
+
# KNMI.Parameter.category(period = "daily, ["WIND", "TEMP"])
|
25
36
|
#
|
26
|
-
# KNMI.Parameter.category(period = "daily, ""WIND") #=> [#<Parameter:0x00000100b433f8 @parameter="SQ", @category="RADT", @description="Sunshine Duration", @validate="(-1..6).include?(n)", @conversion="n == -1 ? 0.05 : (n / 10) * 60", @units="minutes">, #<Daily:0x00000100b43290 @parameter="SP", @category="RADT", @description="Percent of Maximum Sunshine Duration", @validate="(0..100).include?(n)", @conversion=nil, @units="%">, #<Daily:0x00000100b43128 @parameter="Q", @category="RADT", @description="Global Radiation", @validate="n.integer?", @conversion=nil, @units="J/cm^2">]
|
27
|
-
# KNMI.Parameter.category(period = "daily, ["WIND", "TEMP"])
|
28
37
|
def category(period, category)
|
29
38
|
category = [category].flatten
|
30
39
|
|
@@ -36,9 +45,10 @@ module KNMI
|
|
36
45
|
return list.flatten!
|
37
46
|
end
|
38
47
|
|
39
|
-
#
|
40
48
|
# Retrieve all Parameters
|
41
|
-
#
|
49
|
+
# @param period [String] - "daily" or "hourly"
|
50
|
+
# @return [Array<KNMI::Parameters>] - array of parameter objects
|
51
|
+
#
|
42
52
|
def all(period)
|
43
53
|
list = []
|
44
54
|
list << keys.select { |k| k.period == period }
|
@@ -61,25 +71,25 @@ module KNMI
|
|
61
71
|
|
62
72
|
end
|
63
73
|
|
64
|
-
# Paramter shortname
|
74
|
+
# @return [String] - Paramter shortname
|
65
75
|
attr_reader :parameter
|
66
76
|
|
67
|
-
# Categories grouping parameters
|
77
|
+
# @return [String] - Categories grouping parameters
|
68
78
|
attr_reader :category
|
69
79
|
|
70
|
-
# Description of parameter
|
80
|
+
# @return [String] - Description of parameter
|
71
81
|
attr_reader :description
|
72
82
|
|
73
|
-
#
|
83
|
+
# @return [String] - example code to validate data as accurate
|
74
84
|
attr_reader :validate
|
75
85
|
|
76
|
-
#
|
86
|
+
# @return [String] - example code to convert data into appropriate format/units for operation
|
77
87
|
attr_reader :conversion
|
78
88
|
|
79
|
-
# Unit of converted format
|
89
|
+
# @return [String] - Unit of converted format
|
80
90
|
attr_reader :units
|
81
91
|
|
82
|
-
# Time Period
|
92
|
+
# @return [String] - Time Period "daily" or "hourly"
|
83
93
|
attr_reader :period
|
84
94
|
|
85
95
|
def initialize(properties)
|
@@ -88,6 +98,7 @@ module KNMI
|
|
88
98
|
end
|
89
99
|
end
|
90
100
|
|
101
|
+
# @return [Hash] - Hash containing important details about parameters object
|
91
102
|
def detail
|
92
103
|
{:parameter => @parameter, :category => @category,
|
93
104
|
:description => @description, :validate => @validate,
|
data/lib/knmi/station.rb
CHANGED
@@ -1,23 +1,35 @@
|
|
1
1
|
module KNMI
|
2
2
|
class Station
|
3
3
|
class <<self
|
4
|
-
attr_writer :stations_file
|
4
|
+
attr_writer :stations_file
|
5
5
|
|
6
|
+
# Retrieve station object by id
|
6
7
|
#
|
7
|
-
#
|
8
|
+
# @param id [Numeric, String] - Station id
|
9
|
+
# @return [KNMI::Station]
|
10
|
+
#
|
11
|
+
# @example Retrieve Station object for Valkenburg
|
12
|
+
# KNMI::Station.find(210)
|
8
13
|
#
|
9
|
-
# KNMI::Station.find(210) #=> KNMI::Station object for Valkenburg
|
10
14
|
def find(id)
|
11
15
|
stations.find { |station| station.id == id }
|
12
16
|
end
|
13
17
|
|
14
|
-
#
|
15
18
|
# Find the station closest to a given location. Can accept arguments in any of the following
|
16
19
|
# three forms (all are equivalent):
|
17
20
|
#
|
21
|
+
# @param *args [String, Array, Geokit::LatLLng]
|
22
|
+
# @return [KNMI::Station] - Object with details about the station nearest to the requested lat/lng
|
23
|
+
#
|
24
|
+
# @example Retrieve Station by lat, lng
|
18
25
|
# KNMI::Station.closest_to(52.165, 4.419)
|
26
|
+
#
|
27
|
+
# @example Retrieve Station by [lat, lng]
|
19
28
|
# KNMI::Station.closest_to([52.165, 4.419])
|
29
|
+
#
|
30
|
+
# @example Retrieve Station with GeoKit object
|
20
31
|
# KNMI::Station.closest_to(GeoKit::LatLng.new(52.165, 4.419))
|
32
|
+
#
|
21
33
|
def closest_to(*args)
|
22
34
|
if args.length == 1
|
23
35
|
if args.first.respond_to?(:distance_to)
|
@@ -59,31 +71,32 @@ module KNMI
|
|
59
71
|
@stations_file ||= File.join(File.dirname(__FILE__), '..', '..', 'data', 'current_stations.yml')
|
60
72
|
end
|
61
73
|
end
|
62
|
-
|
63
|
-
# GeoKit::LatLng containing the station's coordinates
|
74
|
+
|
75
|
+
# @return [GeoKit::LatLng] - object containing the station's coordinates
|
64
76
|
attr_reader :coordinates
|
65
77
|
|
66
|
-
# Station ID (e.g., 210)
|
78
|
+
# @return [String] - Station ID (e.g., 210)
|
67
79
|
attr_reader :id
|
68
80
|
|
69
|
-
# Station name (e.g., "Valkenburg")
|
81
|
+
# @return [String] - Station name (e.g., "Valkenburg")
|
70
82
|
attr_reader :name
|
71
83
|
|
72
|
-
# Station Elevation
|
84
|
+
# @return [String] - Station Elevation
|
73
85
|
attr_reader :elevation
|
74
86
|
alias_method :elev, :elevation
|
75
87
|
alias_method :altitude, :elevation
|
76
88
|
alias_method :alt, :elevation
|
77
89
|
|
78
|
-
# Link to Station Photo
|
90
|
+
# @return [String] - Link to Station Photo {http://www.knmi.nl/klimatologie/metadata/210_valkenburg_big.jpg Station 210 - Valkenburg Station Photo}
|
79
91
|
attr_reader :photo
|
80
92
|
|
81
|
-
# Link to map of station location
|
93
|
+
# @return [String] - Link to map of station location {http://www.knmi.nl/klimatologie/metadata/stn_210.gif Station 210 - Valkenburg Station Map}
|
82
94
|
attr_reader :map
|
83
95
|
|
84
|
-
# Link to Metadata page listing
|
96
|
+
# @return [String] - Link to Metadata page listing http://www.knmi.nl/klimatologie/metadata/valkenburg.html {Station 210 - Valkenburg Station MetaData page}
|
85
97
|
attr_reader :web
|
86
98
|
|
99
|
+
# @return [Hash<Array>] - Hash containing arrays with detail about historical and current instrumentation at station
|
87
100
|
attr_reader :instrumentation
|
88
101
|
|
89
102
|
def initialize(properties)
|
@@ -93,19 +106,21 @@ module KNMI
|
|
93
106
|
@coordinates = GeoKit::LatLng.new(properties['lat'], properties['lng'])
|
94
107
|
end
|
95
108
|
|
96
|
-
# Latitude of station
|
109
|
+
# @return [Float] - Latitude of station
|
97
110
|
def latitude
|
98
111
|
@coordinates.lat
|
99
112
|
end
|
100
113
|
alias_method :lat, :latitude
|
101
114
|
|
102
|
-
# Longitude of station
|
115
|
+
# @return [Float] - Longitude of station
|
103
116
|
def longitude
|
104
117
|
@coordinates.lng
|
105
118
|
end
|
106
119
|
alias_method :lng, :longitude
|
107
120
|
alias_method :lon, :longitude
|
108
121
|
|
122
|
+
|
123
|
+
# @return [Hash] - contains a has with detail about the station
|
109
124
|
def detail
|
110
125
|
{:id => @id, :name => @name, :elev => @elevation, :lat => latitude, :lng => longitude}
|
111
126
|
end
|
data/test/test_httpservice.rb
CHANGED
@@ -20,7 +20,7 @@ class TestHttpService < KNMI::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
should "have result" do
|
23
|
-
assert_equal @response.data, [{:STN=>
|
23
|
+
assert_equal @response.data, [{:STN=>235, :YYYYMMDD=>20100628, :TX=>263}, {:STN=>235, :YYYYMMDD=>20100629, :TX=>225}]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -43,10 +43,10 @@ class TestHttpService < KNMI::TestCase
|
|
43
43
|
end
|
44
44
|
|
45
45
|
should "have result" do
|
46
|
-
assert_equal @response.data, [
|
47
|
-
{:STN=>
|
48
|
-
{:STN=>
|
49
|
-
{:STN=>
|
46
|
+
assert_equal @response.data, [
|
47
|
+
{:STN=>235, :YYYYMMDD=>20100427, :HH=>1, :T=>88},
|
48
|
+
{:STN=>235, :YYYYMMDD=>20100427, :HH=>2, :T=>79},
|
49
|
+
{:STN=>235, :YYYYMMDD=>20100427, :HH=>3, :T=>73} ]
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
data/test/test_knmi.rb
CHANGED
@@ -122,26 +122,46 @@ class TestKNMI < KNMI::TestCase
|
|
122
122
|
|
123
123
|
context "get data over daily timestep" do
|
124
124
|
setup do
|
125
|
-
station = KNMI.station_by_location(52.165, 4.419)
|
126
|
-
params = KNMI.parameters(period = "daily", "TX")
|
127
|
-
|
128
|
-
|
129
|
-
@
|
125
|
+
@station = KNMI.station_by_location(52.165, 4.419).freeze
|
126
|
+
@params = KNMI.parameters(period = "daily", "TX").freeze
|
127
|
+
@starts = Time.utc(2010, 6, 28)
|
128
|
+
@ends = Time.utc(2010, 6, 29)
|
129
|
+
@request = KNMI.get_data(@station, @params, @starts, @ends)
|
130
|
+
@data = KNMI.convert(@params, @request)
|
130
131
|
end
|
131
132
|
|
132
133
|
should "have HTTParty::Response class" do
|
133
|
-
assert_equal @
|
134
|
+
assert_equal @request.class, KNMI::HttpService
|
134
135
|
end
|
135
136
|
|
136
|
-
should "have query" do
|
137
|
-
assert_equal @
|
137
|
+
should "request should have query" do
|
138
|
+
assert_equal @request.query, ["stns=210", "vars=TX", "start=20100628", "end=20100629"]
|
138
139
|
end
|
139
140
|
|
140
|
-
should "have result" do
|
141
|
-
assert_equal @
|
142
|
-
|
143
|
-
|
144
|
-
|
141
|
+
should "request should have result" do
|
142
|
+
assert_equal @request.data, [{:STN=>210, :YYYYMMDD=>20100628, :TX=>268},
|
143
|
+
{:STN=>210, :YYYYMMDD=>20100629, :TX=>239}]
|
144
|
+
end
|
145
|
+
|
146
|
+
should "data should have class array" do
|
147
|
+
assert_equal @data.class, Array
|
148
|
+
end
|
149
|
+
|
150
|
+
should "data[0] should have class Hash" do
|
151
|
+
assert_equal @data[0].class, Hash
|
152
|
+
end
|
153
|
+
|
154
|
+
should "data[0] should have station" do
|
155
|
+
assert_equal @data[0][:STN], 210
|
156
|
+
end
|
157
|
+
|
158
|
+
should "data[0] should have result" do
|
159
|
+
assert_equal @data[0][:TX], 26.8
|
160
|
+
end
|
161
|
+
|
162
|
+
should "data[0] should have time class" do
|
163
|
+
assert_equal @data[0][:YYYYMMDD].class, Time
|
164
|
+
end
|
145
165
|
end
|
146
166
|
|
147
167
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: knmi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- bullfight
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-19 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -119,14 +119,13 @@ extensions: []
|
|
119
119
|
|
120
120
|
extra_rdoc_files:
|
121
121
|
- LICENSE.txt
|
122
|
-
- README.
|
122
|
+
- README.mkdn
|
123
123
|
files:
|
124
|
-
- .DS_Store
|
125
124
|
- .document
|
126
125
|
- Gemfile
|
127
126
|
- Gemfile.lock
|
128
127
|
- LICENSE.txt
|
129
|
-
- README.
|
128
|
+
- README.mkdn
|
130
129
|
- Rakefile
|
131
130
|
- VERSION
|
132
131
|
- data/current_stations.yml
|
@@ -134,12 +133,13 @@ files:
|
|
134
133
|
- data/data_key.yml
|
135
134
|
- data/hourly_data_key.yml
|
136
135
|
- knmi.gemspec
|
137
|
-
- lib/.DS_Store
|
138
136
|
- lib/knmi.rb
|
137
|
+
- lib/knmi/calculations.rb
|
139
138
|
- lib/knmi/httpservice.rb
|
140
139
|
- lib/knmi/parameters.rb
|
141
140
|
- lib/knmi/station.rb
|
142
141
|
- test/helper.rb
|
142
|
+
- test/test_calculations.rb
|
143
143
|
- test/test_httpservice.rb
|
144
144
|
- test/test_knmi.rb
|
145
145
|
- test/test_parameters.rb
|
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
hash:
|
160
|
+
hash: 3402158507789262008
|
161
161
|
segments:
|
162
162
|
- 0
|
163
163
|
version: "0"
|
@@ -176,6 +176,7 @@ specification_version: 3
|
|
176
176
|
summary: Ruby API to access daily climate data from the Royal Netherlands Meteorological Institute
|
177
177
|
test_files:
|
178
178
|
- test/helper.rb
|
179
|
+
- test/test_calculations.rb
|
179
180
|
- test/test_httpservice.rb
|
180
181
|
- test/test_knmi.rb
|
181
182
|
- test/test_parameters.rb
|
data/.DS_Store
DELETED
Binary file
|
data/README.rdoc
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
= knmi
|
2
|
-
|
3
|
-
Ruby API to access Royal Netherlands Meteorological Institute daily climate data
|
4
|
-
|
5
|
-
Access climatological data as provided by the Royal Netherlands Meteorological Institute through the http get forms for daily and hourly data
|
6
|
-
http://www.knmi.nl/climatology/daily_data/getdata_day.cgi
|
7
|
-
http://www.knmi.nl/klimatologie/uurgegevens/getdata_uur.cgi
|
8
|
-
|
9
|
-
Details
|
10
|
-
* Hourly data (Dutch) - http://www.knmi.nl/klimatologie/uurgegevens/scriptxs-nl.html#uur
|
11
|
-
* Daily data (English) - http://www.knmi.nl/climatology/daily_data/scriptxs-en.html
|
12
|
-
* Select Data with a form, listed below are links to metadata about each station http://www.knmi.nl/climatology/daily_data/selection.cgi
|
13
|
-
|
14
|
-
|
15
|
-
= Installation
|
16
|
-
gem install httparty
|
17
|
-
gem install geokit
|
18
|
-
|
19
|
-
gem install knmi
|
20
|
-
|
21
|
-
= Dependancies
|
22
|
-
* "httparty", "~> 0.7.7"
|
23
|
-
* "geokit", "~> 1.5.0"
|
24
|
-
|
25
|
-
= Example Usage
|
26
|
-
# Get station object by station ID
|
27
|
-
station = KNMI.station_by_id(235)
|
28
|
-
|
29
|
-
# Get parameter object at the time interval you wish to use "hourly" or "daily"
|
30
|
-
# Params can be a single term or an array of terms such as "TG" or ["TG", TX]
|
31
|
-
# Categories can be a single term or an array of terms such as "WIND" or ["WIND", "TEMP"]
|
32
|
-
|
33
|
-
parameter = KNMI.parameters(period = "daily", params = "TX", categories = "")
|
34
|
-
|
35
|
-
# Define Time period of interest
|
36
|
-
start_at = Time.utc(2010, 6, 28) # 2010 April 28th
|
37
|
-
end_at = Time.utc(2010, 6, 29) # 2010 April 29th
|
38
|
-
|
39
|
-
# Get Data using previously retrieved objects
|
40
|
-
data = KNMI.get_data(station, parameter, start_at, end_at)
|
41
|
-
|
42
|
-
= TODO
|
43
|
-
* function validate data at each time step using associated parameterobject.validate
|
44
|
-
* function to convert data at each time step using associated parameterobject.conversion
|
45
|
-
|
46
|
-
= Available Data
|
47
|
-
All available recorded parameters can be found in the file
|
48
|
-
.data/data_key.yml
|
49
|
-
|
50
|
-
= Daily Data
|
51
|
-
Parameter Category Description
|
52
|
-
YYYYMMDD Time Stamp
|
53
|
-
DDVEC WIND Wind Direction
|
54
|
-
FHVEC WIND Vector Mean Wind Speed
|
55
|
-
FG WIND Daily Mean Wind Speed
|
56
|
-
FHX WIND Maximum Hourly Mean Windspeed
|
57
|
-
FHXH WIND Hourly Division at Which Maximum Wind Speed Was Measured
|
58
|
-
FHN WIND Minimum Hourly Mean Windspeed
|
59
|
-
FHNH WIND Hourly Division at Which Minimum Wind Speed Was Measured
|
60
|
-
FXX WIND Maximum Instantaneous Wind Speed
|
61
|
-
FXXH WIND Hourly Division at Which Maximum Instantaneous Wind Speed Was Measured
|
62
|
-
TG TEMP Daily Mean Temperature
|
63
|
-
TN TEMP Minimum Temperature
|
64
|
-
TNH TEMP Hourly Division in Which Minimum Temperature Was Measured
|
65
|
-
TX TEMP Maximum Temperature
|
66
|
-
TXH TEMP Hourly Division in Which Maximum Temperature Was Measured
|
67
|
-
T10N TEMP Minimum Temperature at 10 Cm Above Surface
|
68
|
-
T10NH TEMP Six Hourly Division at Which Minimum Temperature at 10 Cm Above Surface Was Measured
|
69
|
-
SQ RADT Sunshine Duration
|
70
|
-
SP RADT Percent of Maximum Sunshine Duration
|
71
|
-
Q RADT Global Radiation
|
72
|
-
DR PRCP Precipitation Duration
|
73
|
-
RH PRCP Daily Precipitation
|
74
|
-
RHX PRCP Maximum Hourly Precipitation
|
75
|
-
RHXH PRCP Hourly Division in Which Maximum Hourly Precipitation Was Measured
|
76
|
-
EV24 ATMS Potential Evapotranspiration
|
77
|
-
PG ATMS Daily Mean Sea Level Pressure
|
78
|
-
PX ATMS Maximum Hourly Sea Level Pressure
|
79
|
-
PXH ATMS Hourly Division on Which Maximum Hourly Sea Level Pressure Was Measured
|
80
|
-
PN ATMS Minimum Hourly Sea Level Pressure
|
81
|
-
PNH ATMS Hourly Division in Which Minimum Hourly Sea Level Pressure Was Measured
|
82
|
-
VVN VISB Minimum Visibility
|
83
|
-
VVNH VISB Hourly Division in Which Minimum Visibility Was Measured
|
84
|
-
VVX VISB Maximum Visibility
|
85
|
-
VVXH VISB Hourly Division in Which Maximum Visibility Was Measured
|
86
|
-
NG VISB Mean Daily Cloud Cover
|
87
|
-
UG ATMS Daily Mean Relative Humidity
|
88
|
-
UX ATMS Maximum Relative Humidity
|
89
|
-
UXH ATMS Hourly Division in Which Maximum Relative Humidity Was Measured
|
90
|
-
UN ATMS Minimum Relative Humidity
|
91
|
-
UNH ATMS Hourly Division in Which Minimum Relative Humidity Was Measured
|
92
|
-
|
93
|
-
= Hourly Data
|
94
|
-
Parameter Category Description
|
95
|
-
YYYYMMDD Time Stamp
|
96
|
-
HH Hour
|
97
|
-
DD WIND Mean wind direction during the 10-minute period preceding the time of observation
|
98
|
-
FH WIND Hourly mean wind speed
|
99
|
-
FF WIND Mean wind speed
|
100
|
-
FX WIND Maximum wind gust
|
101
|
-
T TEMP Air Temperature at 1.5 m
|
102
|
-
T10N TEMP Minimum Air Temperature at 10 cm in the preceding 6 hours
|
103
|
-
TD TEMP Dew Point Temperature
|
104
|
-
SQ RDTN Sunshine Duration
|
105
|
-
Q RDTN Golbal Radiation
|
106
|
-
DR PRCP Precipitation Duration
|
107
|
-
RH PRCP Precipitation
|
108
|
-
P ATMS Air Pressure
|
109
|
-
VV VISB Visibility
|
110
|
-
N VISB Cloud Cover
|
111
|
-
U ATMS Relative Humidity
|
112
|
-
M WTHR Fog
|
113
|
-
R WTHR Rainfall
|
114
|
-
S WTHR Snow
|
115
|
-
O WTHR Thunder
|
116
|
-
Y WTHR Ice
|
117
|
-
WW WTHR Weather Code
|
118
|
-
|
119
|
-
|
120
|
-
= Please Note the disclaimer included in the header source header
|
121
|
-
# DEZE GEGEVENS MOGEN VRIJ WORDEN GEBRUIKT MITS DE VOLGENDE BRONVERMELDING WORDT GEGEVEN:
|
122
|
-
# KONINKLIJK NEDERLANDS METEOROLOGISCH INSTITUUT (KNMI)
|
123
|
-
#
|
124
|
-
# THESE DATA CAN BE USED FREELY PROVIDED THAT THE FOLLOWING SOURCE IS ACKNOWLEDGED:
|
125
|
-
# ROYAL NETHERLANDS METEOROLOGICAL INSTITUTE
|
126
|
-
|
127
|
-
|
128
|
-
== Copyright
|
129
|
-
|
130
|
-
Copyright (c) 2011 Patrick Galvin Schmitz p.schmitz@gmail.com. See LICENSE.txt for
|
131
|
-
further details.
|
132
|
-
|
data/lib/.DS_Store
DELETED
Binary file
|