rb-grib 0.1.4 → 0.2.0

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.
@@ -0,0 +1,12 @@
1
+ def_path = File.join(File.expand_path(File.dirname(__FILE__)),"grib","definitions")
2
+ if File.exist?(def_path)
3
+ env_name = 'GRIB_DEFINITION_PATH'
4
+ if gdp = ENV[env_name]
5
+ ENV[env_name] = "#{gdp}:#{def_path}"
6
+ else
7
+ path = `grib_info -d`
8
+ if File.exist?(path)
9
+ ENV[env_name] = "#{path}:#{def_path}"
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module NumRu
2
2
  class Grib
3
- VERSION = "0.1.4"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/rb-grib.gemspec CHANGED
@@ -21,5 +21,6 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # specify any dependencies here; for example:
23
23
  s.add_development_dependency "rspec"
24
- # s.add_runtime_dependency "rest-client"
24
+ s.add_runtime_dependency "narray"
25
+ s.add_runtime_dependency "narray_miss"
25
26
  end
@@ -1,83 +1,104 @@
1
1
  require File.expand_path(File.join('.','spec_helper'), File.dirname(__FILE__))
2
2
 
3
3
  dir = File.expand_path(File.join('..','data'), File.dirname(__FILE__))
4
- fname_reg_gaus_surf_g1 = File.join(dir, 'regular_gaussian_surface.grib1')
5
- fname_reg_gaus_surf_g2 = File.join(dir, 'regular_gaussian_surface.grib2')
6
- fname_reg_gaus_ml_g1 = File.join(dir, 'regular_gaussian_model_level.grib1')
7
- fname_reg_gaus_ml_g2 = File.join(dir, 'regular_gaussian_model_level.grib2')
8
- fname_reg_gaus_pl_g1 = File.join(dir, 'regular_gaussian_pressure_level.grib1')
9
- fname_reg_gaus_pl_g2 = File.join(dir, 'regular_gaussian_pressure_level.grib2')
10
- fname_reg_gaus_pl_const_g1 = File.join(dir, 'regular_gaussian_pressure_level_constant.grib1')
11
- fname_reg_gaus_pl_const_g2 = File.join(dir, 'regular_gaussian_pressure_level_constant.grib2')
12
- fname_reg_ll_surf_g1 = File.join(dir, 'regular_latlon_surface.grib1')
13
- fname_reg_ll_surf_g2 = File.join(dir, 'regular_latlon_surface.grib2')
14
- fname_reg_ll_surf_const_g1 = File.join(dir, 'regular_latlon_surface_constant.grib1')
15
- fname_reg_ll_surf_const_g2 = File.join(dir, 'regular_latlon_surface_constant.grib2')
4
+ GribData = {
5
+ File.join(dir, 'regular_gaussian_surface.grib1') =>
6
+ {"2t"=>{:dims=>["lon","lat"], :shape=>[128,64], :val=>{[0,0]=>2.4552479553e2}}
7
+ },
8
+ File.join(dir, 'regular_gaussian_surface.grib2') =>
9
+ {"2t"=>{:dims=>["lon","lat"], :shape=>[128,64], :val=>{[0,0]=>2.4552479553e2}}
10
+ },
11
+ File.join(dir, 'regular_gaussian_model_level.grib1') =>
12
+ {"t"=>{:dims=>["lon","lat"], :shape=>[128,64], :val=>{[0,0]=>1.9907820129e2}}
13
+ },
14
+ File.join(dir, 'regular_gaussian_model_level.grib2') =>
15
+ {"t"=>{:dims=>["lon","lat"], :shape=>[128,64], :val=>{[0,0]=>1.9907820129e2}}
16
+ },
17
+ File.join(dir, 'regular_gaussian_pressure_level.grib1') =>
18
+ {"t"=>{:dims=>["lon","lat"], :shape=>[128,64], :val=>{[0,0]=>2.4746011353e2}}
19
+ },
20
+ File.join(dir, 'regular_gaussian_pressure_level.grib2') =>
21
+ {"t"=>{:dims=>["lon","lat"], :shape=>[128,64], :val=>{[0,0]=>2.4746011353e2}}
22
+ },
23
+ File.join(dir, 'regular_gaussian_pressure_level_constant.grib1') =>
24
+ {"t"=>{:dims=>["lon","lat"], :shape=>[128,64], :val=>{[0,0]=>1.0}}
25
+ },
26
+ File.join(dir, 'regular_gaussian_pressure_level_constant.grib2') =>
27
+ {"t"=>{:dims=>["lon","lat"], :shape=>[128,64], :val=>{[0,0]=>1.0}}
28
+ },
29
+ File.join(dir, 'regular_latlon_surface.grib1') =>
30
+ {"2t"=>{:dims=>["lon","lat"], :shape=>[16,31], :val=>{[0,0]=>279.0}}
31
+ },
32
+ File.join(dir, 'regular_latlon_surface.grib2') =>
33
+ {"2t"=>{:dims=>["lon","lat"], :shape=>[16,31], :val=>{[0,0]=>279.0}}
34
+ },
35
+ File.join(dir, 'regular_latlon_surface_constant.grib1') =>
36
+ {"2t"=>{:dims=>["lon","lat"], :shape=>[16,31], :val=>{[0,0]=>1.0}}
37
+ },
38
+ File.join(dir, 'regular_latlon_surface_constant.grib2') =>
39
+ {"2t"=>{:dims=>["lon","lat"], :shape=>[16,31], :val=>{[0,0]=>1.0}}
40
+ },
41
+ File.join(dir, 'tp_ecmwf.grib') =>
42
+ {"tp"=>{:dims=>["lon","lat","step"], :shape=>[16,31,4], :val=>{[0,0,0]=>2.0546913147e-3}}
43
+ }
44
+ }
16
45
  fname_not_exist = 'not_exist'
17
- fnames = [
18
- fname_reg_gaus_surf_g1,
19
- fname_reg_gaus_surf_g2,
20
- fname_reg_gaus_ml_g1,
21
- fname_reg_gaus_ml_g2,
22
- fname_reg_gaus_pl_g1,
23
- fname_reg_gaus_pl_g2,
24
- fname_reg_gaus_pl_const_g1,
25
- fname_reg_gaus_pl_const_g2,
26
- fname_reg_ll_surf_g1,
27
- fname_reg_ll_surf_g2,
28
- fname_reg_ll_surf_const_g1
29
- ]
30
46
 
31
47
  describe NumRu::Grib do
32
48
  describe 'Grib.is_a_Grib?' do
33
49
  it 'returns whether the specific file is a GRIB1/2 file' do
34
- NumRu::Grib.is_a_Grib?(fname_reg_gaus_surf_g1).should be_true
35
- NumRu::Grib.is_a_Grib?(fname_reg_gaus_surf_g2).should be_true
50
+ GribData.each do |fname, hash|
51
+ NumRu::Grib.is_a_Grib?(fname).should be_true
52
+ end
36
53
  end
37
54
  end
38
55
 
39
56
  describe 'Grib.open' do
40
- context 'specified a file name' do
41
- describe 'grib1' do
42
- it 'returns Grib object' do
43
- (@file = NumRu::Grib.open(fname_reg_gaus_surf_g1)).should be_a_kind_of(NumRu::Grib)
44
- end
45
- after { @file.close if @file }
46
- end
47
- describe 'grib2' do
48
- it 'returns Grib object' do
49
- (@file = NumRu::Grib.open(fname_reg_gaus_surf_g2)).should be_a_kind_of(NumRu::Grib)
50
- end
51
- after { @file.close if @file }
57
+ before { @files = [] }
58
+ after { @files.each{|file| file.close} }
59
+ it 'returns Grib object' do
60
+ GribData.each do |fname, hash|
61
+ file = NumRu::Grib.open(fname)
62
+ file.should be_a_kind_of(NumRu::Grib)
63
+ @files.push file
52
64
  end
53
65
  end
54
- context 'specified a file name which does not exist' do
55
- it { proc { NumRu::Grib.open(fname_not_exist)}.should raise_error }
66
+ it 'raise exception when file name which does not exist is given' do
67
+ proc { NumRu::Grib.open(fname_not_exist)}.should raise_error
56
68
  end
57
69
  end
58
70
 
59
71
  describe '#close' do
60
- file = NumRu::Grib.open(fname_reg_gaus_surf_g1)
61
- it { file.close }
72
+ before do
73
+ @files = []
74
+ GribData.each{|fname,hash| @files.push NumRu::Grib.open(fname) }
75
+ end
76
+ it do
77
+ @files.each do |file|
78
+ proc {file.close}.should_not raise_error
79
+ end
80
+ end
62
81
  end
63
82
 
64
83
  describe 'instance methods' do
65
84
  before do
66
- @files = fnames.map{|fname| NumRu::Grib.open(fname)}
85
+ @files = {}
86
+ GribData.each{|fname,hash| @files[fname] = NumRu::Grib.open(fname) }
67
87
  end
68
88
  after do
69
- @files.each{|file| file.close}
89
+ @files.each{|fname,file| file.close}
70
90
  end
71
91
  it '#path returns path' do
72
- @files.each {|file| file.path.should be_a_kind_of(String)}
92
+ @files.each {|fname,file| file.path.should == fname}
73
93
  end
74
94
  it '#var_names returns Array of variable names' do
75
- @files.each {|file| file.var_names.should be_a_kind_of(Array)}
95
+ @files.each {|fname, file| file.var_names.should == GribData[fname].keys}
76
96
  end
77
97
  it '#var returns GribVar object' do
78
- @files.each do |file|
79
- vname = file.var_names[0]
80
- file.var(vname).should be_a_kind_of NumRu::GribVar
98
+ @files.each do |fname, file|
99
+ GribData[fname].each do |vname, hash|
100
+ file.var(vname).should be_a_kind_of NumRu::GribVar
101
+ end
81
102
  end
82
103
  end
83
104
  end
@@ -85,63 +106,68 @@ end
85
106
 
86
107
  describe NumRu::GribVar do
87
108
  before do
88
- @vars = []
89
109
  @files = []
90
- fnames.each do |fname|
110
+ @vars = Hash.new
111
+ GribData.each do |fname,vars|
91
112
  file = NumRu::Grib.open(fname)
92
113
  @files.push file
93
- file.var_names.each{|vname| @vars.push file.var(vname)}
114
+ vars.each{|vname, hash| @vars[file.var(vname)] = hash}
94
115
  end
95
116
  end
96
- after do
97
- @files.each{|file| file.close}
98
- end
117
+ after { @files.each{|file| file.close}}
99
118
  it '#rank returns rank' do
100
- @vars.each{|var| var.rank.should be_a_kind_of Fixnum}
119
+ @vars.each{|var,hash| var.rank.should == hash[:shape].length}
101
120
  end
102
121
  it '#total returns total length' do
103
- @vars.each{|var| var.total.should be_a_kind_of Fixnum}
122
+ @vars.each{|var,hash| var.total.should == hash[:shape].inject(1,:*)}
104
123
  end
105
124
  it '#dim_names returns Array of dimension names' do
106
- @vars.each{|var| var.dim_names.should be_a_kind_of Array}
125
+ @vars.each{|var,hash| var.dim_names.should == hash[:dims]}
107
126
  end
108
127
  it '#shape returns Array of shape' do
109
- @vars.each{|var| var.shape.should be_a_kind_of Array}
128
+ @vars.each{|var,hash| var.shape.should == hash[:shape]}
110
129
  end
111
130
  it '#dim returns GribDim' do
112
- @vars.each do |var|
113
- var.dim_names.each{|dname| var.dim(dname).should be_a_kind_of NumRu::GribDim}
131
+ @vars.each do |var,hash|
132
+ hash[:dims].each{|dname| var.dim(dname).should be_a_kind_of NumRu::GribDim}
114
133
  end
115
134
  end
116
135
  it '#att_names returns Array of attribute names' do
117
- @vars.each{|var| var.att_names.should be_a_kind_of Array}
136
+ @vars.each{|var,hash| var.att_names.should be_a_kind_of Array}
118
137
  end
119
138
  it '#att returns attribute value' do
120
- @vars.each do |var|
139
+ @vars.each do |var,hash|
121
140
  var.att_names.each{|aname| var.att(aname).should_not == nil }
122
141
  end
123
142
  end
124
143
  it '#typecode returns type code' do
125
- @vars.each{|var| var.typecode.should be_a_kind_of Fixnum}
144
+ @vars.each{|var,hash| var.typecode.should be_a_kind_of Fixnum}
126
145
  end
127
146
  it '#missing_value returns missing value' do
128
- @vars.each{|var| var.missing_value.should be_a_kind_of Numeric}
147
+ @vars.each{|var,hash| var.missing_value.should be_a_kind_of Numeric}
129
148
  end
130
149
  it '#get returns value' do
131
- @vars.each{|var| var.get.should be_a_kind_of NArrayMiss}
150
+ @vars.each do |var,hash|
151
+ hash[:val].each do |idx,val|
152
+ v = var.get[*idx]
153
+ ((v-val).abs/((v+val)/2)).should < 1e-10
154
+ end
155
+ end
132
156
  end
133
157
  end
134
158
 
135
159
  describe NumRu::GribDim do
136
160
  before do
137
- @dims = []
138
161
  @files = []
139
- fnames.each do |fname|
162
+ @dims = Hash.new
163
+ GribData.each do |fname, vars|
140
164
  file = NumRu::Grib.open(fname)
141
165
  @files.push file
142
- file.var_names.each do |vname|
166
+ vars.each do |vname, hash|
143
167
  var = file.var(vname)
144
- var.dim_names{|dname| @dims.push var.dim(dname)}
168
+ hash[:dims].each_with_index do |dname,i|
169
+ @dims[var.dim(dname)] = hash[:shape][i]
170
+ end
145
171
  end
146
172
  end
147
173
  end
@@ -149,19 +175,22 @@ describe NumRu::GribDim do
149
175
  @files.each{|file| file.close}
150
176
  end
151
177
  it '#length returns length' do
152
- @dims.each{|dim| dim.length.should be_a_kind_of Integer}
178
+ @dims.each{|dim,len| dim.length.should == len}
153
179
  end
154
180
  it '#val returns value' do
155
- @dims.each{|dim| dim.val.should be_a_kind_of NArray}
181
+ @dims.each do |dim,len|
182
+ dim.val.should be_a_kind_of NArray
183
+ dim.val.length.should == len
184
+ end
156
185
  end
157
186
  it '#typecode returns typecode' do
158
- @dims.each{|dim| dim.typecode.should be_a_kind_of Fixnum}
187
+ @dims.each{|dim,len| dim.typecode.should be_a_kind_of Fixnum}
159
188
  end
160
189
  it '#att_names returns Array of attribute names' do
161
- @dims.each{|dim| dim.att_names.should be_a_kind_of Array}
190
+ @dims.each{|dim,len| dim.att_names.should be_a_kind_of Array}
162
191
  end
163
192
  it '#att returns attributes value' do
164
- @dims.each do |dim|
193
+ @dims.each do |dim,len|
165
194
  dim.att_names.each{|aname| dim.att(aname).should_not == nil }
166
195
  end
167
196
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-grib
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
4
+ hash: 23
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seiya Nishizawa
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-29 00:00:00 Z
18
+ date: 2011-12-15 00:00:00 +09:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
@@ -31,6 +32,34 @@ dependencies:
31
32
  version: "0"
32
33
  type: :development
33
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: narray
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: narray_miss
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
34
63
  description: This class library enable you to handle GRIB file.
35
64
  email:
36
65
  - seiya@gfd-dennou.org
@@ -42,6 +71,7 @@ extra_rdoc_files: []
42
71
 
43
72
  files:
44
73
  - .gitignore
74
+ - BSDL
45
75
  - Gemfile
46
76
  - LICENSE.txt
47
77
  - README.rdoc
@@ -59,14 +89,25 @@ files:
59
89
  - data/regular_latlon_surface_constant.grib1
60
90
  - data/regular_latlon_surface_constant.grib2
61
91
  - data/regular_latlon_surface_prec.grib1
92
+ - data/tp_ecmwf.grib
62
93
  - ext/extconf.rb
63
94
  - ext/grib.c
64
95
  - lib/numru/grib.rb
96
+ - lib/numru/grib/definitions/grib1/localConcepts/kwbc/name.def
97
+ - lib/numru/grib/definitions/grib1/localConcepts/kwbc/paramId.def
98
+ - lib/numru/grib/definitions/grib1/localConcepts/kwbc/shortName.def
99
+ - lib/numru/grib/definitions/grib1/localConcepts/kwbc/units.def
100
+ - lib/numru/grib/definitions/grib2/localConcepts/rjtd/name.def
101
+ - lib/numru/grib/definitions/grib2/localConcepts/rjtd/paramId.def
102
+ - lib/numru/grib/definitions/grib2/localConcepts/rjtd/shortName.def
103
+ - lib/numru/grib/definitions/grib2/localConcepts/rjtd/units.def
65
104
  - lib/numru/grib/grib.rb
105
+ - lib/numru/grib/setenv.rb
66
106
  - lib/numru/grib/version.rb
67
107
  - rb-grib.gemspec
68
108
  - spec/grib_read_spec.rb
69
109
  - spec/spec_helper.rb
110
+ has_rdoc: true
70
111
  homepage: http://ruby.gfd-dennou.org/products/rb-grib/
71
112
  licenses: []
72
113
 
@@ -96,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
137
  requirements: []
97
138
 
98
139
  rubyforge_project: rb-grib
99
- rubygems_version: 1.8.10
140
+ rubygems_version: 1.3.7
100
141
  signing_key:
101
142
  specification_version: 3
102
143
  summary: Ruby class library to hanlde GRIB file