knmi 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +43 -0
  2. data/VERSION +1 -1
  3. data/knmi.gemspec +2 -2
  4. data/lib/knmi.rb +27 -7
  5. metadata +3 -3
@@ -25,6 +25,49 @@ Please Note the disclaimer included in the header!
25
25
  = Dependancies
26
26
  * httparty >= 0.7.4
27
27
 
28
+ = Data
29
+ Please note that the data must be converted from fixnum to float, I will include a method to take care of this in my next version.
30
+
31
+ YYYYMMDD = Date (YYYY=year MM=month DD=day)
32
+ DDVEC = Vector mean wind direction in degrees (360=north, 90=east, 180=south, 270=west, 0=calm/variable)
33
+ FHVEC = Vector mean windspeed (in 0.1 m/s)
34
+ FG = Daily mean windspeed (in 0.1 m/s)
35
+ FHX = Maximum hourly mean windspeed (in 0.1 m/s)
36
+ FHXH = Hourly division in which FHX was measured
37
+ FHN = Minimum hourly mean windspeed (in 0.1 m/s)
38
+ FHNH = Hourly division in which FHN was measured
39
+ FXX = Maximum wind gust (in 0.1 m/s)
40
+ FXXH = Hourly division in which FXX was measured
41
+ TG = Daily mean temperature in (0.1 degrees Celsius)
42
+ TN = Minimum temperature (in 0.1 degrees Celsius)
43
+ TNH = Hourly division in which TN was measured
44
+ TX = Maximum temperature (in 0.1 degrees Celsius)
45
+ TXH = Hourly division in which TX was measured
46
+ T10N = Minimum temperature at 10 cm above surface (in 0.1 degrees Celsius)
47
+ T10NH = 6-hourly division in which T10N was measured; 6=0-6 UT, 12=6-12 UT, 18=12-18 UT, 24=18-24
48
+ SQ = Sunshine duration (in 0.1 hour) calculated from global radiation (-1 for <0.05 hour)
49
+ SP = Percentage of maximum potential sunshine duration
50
+ Q = Global radiation (in J/cm2)
51
+ DR = Precipitation duration (in 0.1 hour)
52
+ RH = Daily precipitation amount (in 0.1 mm) (-1 for <0.05 mm)
53
+ RHX = Maximum hourly precipitation amount (in 0.1 mm) (-1 for <0.05 mm)
54
+ RHXH = Hourly division in which RHX was measured
55
+ PG = Daily mean sea level pressure (in 0.1 hPa) calculated from 24 hourly values
56
+ PX = Maximum hourly sea level pressure (in 0.1 hPa)
57
+ PXH = Hourly division in which PX was measured
58
+ PN = Minimum hourly sea level pressure (in 0.1 hPa)
59
+ PNH = Hourly division in which PN was measured
60
+ VVN = Minimum visibility; 0: <100 m, 1:100-200 m, 2:200-300 m,..., 49:4900-5000 m, 50:5-6 km, 56:6-7 km, 57:7-8 km,..., 79:29-30 km, 80:30-35 km, 81:35-40 km,..., 89: >70 k
61
+ VVNH = Hourly division in which VVN was measured
62
+ VVX = Maximum visibility; 0: <100 m, 1:100-200 m, 2:200-300 m,..., 49:4900-5000 m, 50:5-6 km, 56:6-7 km, 57:7-8 km,..., 79:29-30 km, 80:30-35 km, 81:35-40 km,..., 89: >70 k
63
+ VVXH = Hourly division in which VVX was measured
64
+ NG = Mean daily cloud cover (in octants, 9=sky invisible)
65
+ UG = Daily mean relative atmospheric humidity (in percents)
66
+ UX = Maximum relative atmospheric humidity (in percents)
67
+ UXH = Hourly division in which UX was measured
68
+ UN = Minimum relative atmospheric humidity (in percents)
69
+ UNH = Hourly division in which UN was measured
70
+ EV24 = Potential evapotranspiration (Makkink) (in 0.1 mm
28
71
 
29
72
  = List of Recorded Parameters and group name
30
73
  When entering parameters in method call use groupname for collection of variables of use individual parameter names
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knmi}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
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-04-28}
12
+ s.date = %q{2011-05-02}
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 = [
@@ -101,18 +101,35 @@ class KNMI
101
101
  #varlist = res[(7+nstn)..(6 + nstn + nvars)]
102
102
  #colheader = res[(8 + nstn + nvars)]
103
103
  #header = res[0..(9 + nstn + nvars)]
104
- #stations = res[5..(4+nstn)]
105
- #stations = stations.join.tr("\s+", "")
106
- #stations = stations.tr("#", "")
107
- #stations = stations.tr(":", "")
108
- #stations = CSV.parse( stations, {:col_sep => "\t"} )
109
104
  def parse(response, station_number, vars)
110
105
  # Line Index Numbers
111
106
  nstn = [station_number].flatten.length
112
107
  vars, nvars = check_variables(vars)
113
-
114
- # Clean Data remove unecessary chars
108
+
109
+ # Split lines into array
115
110
  response = response.split(/\n/)
111
+
112
+ # Get Station Details
113
+ stations = response[5..(4+nstn)]
114
+ stations = stations.join.tr("\t", "\s")
115
+ stations = stations.tr("#", "")
116
+ stations = stations.tr(":", "")
117
+ stations = CSV.parse( stations, {:col_sep => "\s"} )
118
+ stations = stations.map {|row| row.map {|cell| cell.to_s } }
119
+ st_header = [:station_code, :lng, :lat, :elev, :name]
120
+ stations = stations.map {|row| Hash[*st_header.zip(row).flatten] }
121
+
122
+ # Get Variable Details
123
+ varlist = response[(7+nstn)..(6 + nstn + nvars)]
124
+ varlist = varlist.join
125
+ varlist = varlist.gsub(/# /, "")
126
+ varlist = varlist.gsub(/\s{2,}/, "")
127
+ varlist = varlist.gsub(/;/, "\r")
128
+ varlist = CSV.parse( varlist, {:col_sep => "= "} )
129
+ vr_header = [:var, :description]
130
+ varlist = varlist.map {|row| Hash[*vr_header.zip(row).flatten] }
131
+
132
+ # Get and clean data
116
133
  response = response[(8 + nstn + nvars)..response.length]
117
134
  response = response.join.tr("\s+", "")
118
135
  response = response.tr("#", "")
@@ -123,6 +140,7 @@ class KNMI
123
140
  string_data = response.map {|row| row.map {|cell| cell.to_s } }
124
141
  data = string_data.map {|row| Hash[*header.zip(row).flatten] }
125
142
 
143
+ return {:stations => stations, :variables => varlist, :data => data}
126
144
  end
127
145
  end # End Private
128
146
 
@@ -133,6 +151,7 @@ class KNMI
133
151
  # station_number = [210, 212]
134
152
  # vars = "TG"
135
153
  # res = KNMIdaily.get_station( station_number, vars )
154
+ # output {:stations => {:}}
136
155
  def self.get_station(station_number, vars = "")
137
156
  query = station(station_number) + "&" + variables(vars)
138
157
  puts query
@@ -172,6 +191,7 @@ class KNMI
172
191
 
173
192
  def self.to_csv(filename, response)
174
193
  CSV.open(filename, "wb") do |csv|
194
+ response[:data]
175
195
  csv << response[0].keys
176
196
  response[(1..(response.length - 1))].each do |line|
177
197
  csv << line.values
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knmi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.1.4
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-04-28 00:00:00 Z
13
+ date: 2011-05-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: shoulda
@@ -101,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
- hash: -3006710400801568516
104
+ hash: -3374246845192166730
105
105
  segments:
106
106
  - 0
107
107
  version: "0"