agwx_grids 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/agwx_grids/grid.rb +21 -12
- data/lib/agwx_grids/version.rb +1 -1
- data/test/grid_test.rb +15 -0
- metadata +69 -49
- checksums.yaml +0 -7
data/Rakefile
CHANGED
data/lib/agwx_grids/grid.rb
CHANGED
@@ -65,7 +65,7 @@ module AgwxGrids
|
|
65
65
|
|
66
66
|
def calcYIncr
|
67
67
|
if @yStart != nil && @yEnd != nil && @yDim != nil then
|
68
|
-
@yIncr = (@yEnd - @yStart) / @yDim
|
68
|
+
@yIncr = (@yEnd - @yStart) / (@yDim - 1)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -159,25 +159,34 @@ module AgwxGrids
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
+
# Find the nearest index to the given coord (params in real space, return is a zero-based index)
|
163
|
+
def nearest(coord,start,incr)
|
164
|
+
# convert coord to a lower-bound index (i.e. truncating integer conversion)
|
165
|
+
trunc = ((coord - start)/incr).to_i
|
166
|
+
# Does "trunc" the index of the closest real-space coord, or the next one up?
|
167
|
+
coord - (start + incr*trunc) > incr / 2.0 ? trunc + 1 : trunc
|
168
|
+
end
|
169
|
+
|
170
|
+
# Convert coordinates in real XY space to indices. Note that Z is sort-of a real-space coord, but
|
171
|
+
# represents a quantized there-or-not value like a DOY, not a scalar.
|
162
172
|
def realToIndex(x,y,z)
|
163
|
-
@
|
164
|
-
@
|
165
|
-
@
|
166
|
-
# puts "realToIndex: x #{x}, xStart #{@mD.xStart}, xIncr #{@mD.xIncr} myX #{@
|
167
|
-
[@
|
173
|
+
@my_ii = nearest(x,@mD.xStart,@mD.xIncr)
|
174
|
+
@my_jj = nearest(y,@mD.yStart,@mD.yIncr)
|
175
|
+
@my_doy = z
|
176
|
+
# puts "realToIndex: x #{x}, xStart #{@mD.xStart}, xIncr #{@mD.xIncr} myX #{@my_ii}; y #{y}, myY #{@my_jj} z #{z}, myZ #{@my_doy}"
|
177
|
+
[@my_ii,@my_jj,@my_doy]
|
168
178
|
end
|
169
179
|
|
170
180
|
def get(x,y,z)
|
171
181
|
# puts "get #{x},#{y},#{z}"
|
172
182
|
# puts "xStart=#{@mD.xStart}, yStart=#{@mD.yStart}, zStart=#{@mD.zStart}"
|
173
|
-
# note that this just truncates; it should round to center of cell!
|
174
183
|
realToIndex(x,y,z)
|
175
|
-
# puts "@
|
176
|
-
# puts "#{@layers[@
|
177
|
-
if @layers[@
|
184
|
+
# puts "@my_ii=#{@my_ii}, @my_jj=#{@my_jj}, @my_doy=#{@my_doy}"
|
185
|
+
# puts "#{@layers[@my_doy]}"
|
186
|
+
if @layers[@my_doy] == nil
|
178
187
|
nil
|
179
188
|
else
|
180
|
-
val = @layers[@
|
189
|
+
val = @layers[@my_doy].get(@my_ii,@my_jj)
|
181
190
|
val == mD.badVal ? nil : val
|
182
191
|
end
|
183
192
|
end
|
@@ -201,7 +210,7 @@ module AgwxGrids
|
|
201
210
|
if layer == nil
|
202
211
|
yield nil
|
203
212
|
else
|
204
|
-
val = layer.get(@
|
213
|
+
val = layer.get(@my_ii,@my_jj)
|
205
214
|
val = nil if val == mD.badVal
|
206
215
|
yield val
|
207
216
|
end
|
data/lib/agwx_grids/version.rb
CHANGED
data/test/grid_test.rb
CHANGED
@@ -49,6 +49,13 @@ class TestAgwxGrid < Test::Unit::TestCase
|
|
49
49
|
assert_in_delta(long_start + 3 * long_incr, @grid.longitude_for(3), 2 ** -20)
|
50
50
|
end
|
51
51
|
|
52
|
+
def test_by_long_lat
|
53
|
+
assert_equal(-17.03, @grid.get(-96.86,42.0,1))
|
54
|
+
assert_equal(-17.01, @grid.get(-96.45,42.0,1))
|
55
|
+
assert_equal(-16.85, @grid.get(-96.86,42.4,1))
|
56
|
+
assert_equal(-16.82, @grid.get(-96.45,42.4,1))
|
57
|
+
|
58
|
+
end
|
52
59
|
def test_each_with_doy
|
53
60
|
layers = []
|
54
61
|
doys = []
|
@@ -68,12 +75,20 @@ class TestAgwxGrid < Test::Unit::TestCase
|
|
68
75
|
end
|
69
76
|
|
70
77
|
def test_at_by_long_lat
|
78
|
+
assert_equal(0.4, @grid.mD.yIncr)
|
71
79
|
latitude = @grid.latitude_for(5)
|
80
|
+
assert_equal(44.0, latitude)
|
72
81
|
longitude = @grid.longitude_for(6)
|
82
|
+
assert_equal(-95.6, longitude)
|
73
83
|
vals = @grid.at_by_long_lat(longitude,latitude)
|
74
84
|
assert_equal(364, vals.keys.size)
|
75
85
|
assert_equal(-17.42, vals[1])
|
76
86
|
end
|
87
|
+
|
88
|
+
def test_nearest
|
89
|
+
assert_equal(0, @grid.nearest(-97.81,-98.0,0.4))
|
90
|
+
assert_equal(1, @grid.nearest(-97.79,-98.0,0.4))
|
91
|
+
end
|
77
92
|
end
|
78
93
|
# begin # test the Grid class
|
79
94
|
# puts "====== initializing a grid =========="
|
metadata
CHANGED
@@ -1,50 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: agwx_grids
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
5
11
|
platform: ruby
|
6
|
-
authors:
|
12
|
+
authors:
|
7
13
|
- RickWayne
|
8
14
|
autorequire:
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
|
18
|
+
date: 2013-12-11 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
14
21
|
name: bundler
|
15
|
-
|
16
|
-
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
17
25
|
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
|
20
|
-
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 9
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 3
|
31
|
+
version: "1.3"
|
21
32
|
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
33
|
type: :development
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
35
46
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
version: '0'
|
41
|
-
description: 'UW Soils Ag Weather grid data format (X by Y by DOY) '
|
42
|
-
email:
|
47
|
+
type: :development
|
48
|
+
requirement: *id002
|
49
|
+
description: "UW Soils Ag Weather grid data format (X by Y by DOY) "
|
50
|
+
email:
|
43
51
|
- fewayne@wisc.edu
|
44
52
|
executables: []
|
53
|
+
|
45
54
|
extensions: []
|
55
|
+
|
46
56
|
extra_rdoc_files: []
|
47
|
-
|
57
|
+
|
58
|
+
files:
|
48
59
|
- .gitignore
|
49
60
|
- Gemfile
|
50
61
|
- LICENSE.txt
|
@@ -56,30 +67,39 @@ files:
|
|
56
67
|
- lib/agwx_grids/version.rb
|
57
68
|
- test/grid_test.rb
|
58
69
|
- test/grids/WIMNTMin2002
|
59
|
-
homepage:
|
60
|
-
licenses:
|
70
|
+
homepage: ""
|
71
|
+
licenses:
|
61
72
|
- MIT
|
62
|
-
metadata: {}
|
63
73
|
post_install_message:
|
64
74
|
rdoc_options: []
|
65
|
-
|
75
|
+
|
76
|
+
require_paths:
|
66
77
|
- lib
|
67
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
77
96
|
requirements: []
|
97
|
+
|
78
98
|
rubyforge_project:
|
79
|
-
rubygems_version:
|
99
|
+
rubygems_version: 1.8.25
|
80
100
|
signing_key:
|
81
|
-
specification_version:
|
101
|
+
specification_version: 3
|
82
102
|
summary: UW Soils Ag Weather grid data format (X by Y by DOY)
|
83
|
-
test_files:
|
103
|
+
test_files:
|
84
104
|
- test/grid_test.rb
|
85
105
|
- test/grids/WIMNTMin2002
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 453daf831e0ba373d2a523988e4f27b064c33a53
|
4
|
-
data.tar.gz: 4b30eb84658a562f9a6667255fccb5dc60d3d73d
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: a5677ebe08bb872308098ae970b87efd4aa6c05c1a0bd9285dd9985d8d41db613cdb355264c70252b9492cd82d15c057c8b905cd84f8da925b475ab1d523ed75
|
7
|
-
data.tar.gz: 2e79c14ab75a481483fbad839778fe810ca48bbd1b9ec3f2abc41eadebb6468bafcc48a0b6f5a8fd7a2ad789189deb8fb7df1d508f55cc8a61ef00ebf4827b38
|