gentooboontoo-gphys 0.6.1.3 → 1.3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +5631 -464
- data/LICENSE.txt +34 -0
- data/README +23 -25
- data/bin/gdir_client +25 -7
- data/bin/gdir_server +19 -13
- data/bin/gpaop +41 -28
- data/bin/gpcat +19 -11
- data/bin/gpcut +20 -11
- data/bin/gpedit +37 -1
- data/bin/gplist +5 -4
- data/bin/gpmath +21 -14
- data/bin/gpmaxmin +9 -7
- data/bin/gpprint +15 -11
- data/bin/gpvect +217 -96
- data/bin/gpview +278 -123
- data/bin/grads2nc_with_gphys +11 -6
- data/doc/attribute.html +1 -1
- data/doc/axis.html +85 -66
- data/doc/coordmapping.html +22 -22
- data/doc/dclext.html +709 -0
- data/doc/derivative/gphys-derivative.html +33 -13
- data/doc/derivative/numru-derivative.html +60 -31
- data/doc/gdir.html +76 -76
- data/doc/gdir_server.html +28 -16
- data/doc/ggraph.html +493 -706
- data/doc/gpcat.html +28 -11
- data/doc/gpcut.html +26 -11
- data/doc/gphys.html +195 -71
- data/doc/gphys_fft.html +162 -21
- data/doc/gphys_grads_io.html +9 -9
- data/doc/gphys_grib_io.html +7 -7
- data/doc/gphys_io.html +118 -31
- data/doc/gphys_io_common.html +1 -1
- data/doc/gphys_netcdf_io.html +14 -14
- data/doc/gplist.html +6 -5
- data/doc/gpmath.html +32 -14
- data/doc/gpmaxmin.html +9 -7
- data/doc/gpprint.html +14 -11
- data/doc/gpview.html +254 -146
- data/doc/grads2nc_with_gphys.html +6 -8
- data/doc/grads_gridded.html +77 -77
- data/doc/grib.html +102 -59
- data/doc/grid.html +45 -61
- data/doc/index.html +51 -41
- data/doc/index.rd +47 -36
- data/doc/netcdf_convention.html +39 -39
- data/doc/unumeric.html +79 -30
- data/doc/update +2 -1
- data/doc/varray.html +62 -56
- data/doc/varraycomposite.html +3 -3
- data/ext/ext_coord.c +209 -0
- data/ext/ext_init.c +7 -0
- data/ext/extconf.rb +41 -0
- data/ext/interpo.c +536 -0
- data/ext/multibitIO.c +567 -0
- data/lib/numru/dcl_mouse.rb +71 -0
- data/lib/numru/dclext.rb +2749 -0
- data/lib/numru/derivative.rb +124 -31
- data/lib/numru/ganalysis.rb +7 -0
- data/lib/numru/ganalysis/covariance.rb +154 -0
- data/lib/numru/ganalysis/eof.rb +302 -0
- data/lib/numru/ganalysis/histogram.rb +337 -0
- data/lib/numru/ganalysis/met.rb +872 -0
- data/lib/numru/ganalysis/planet.rb +392 -0
- data/lib/numru/ggraph.rb +1709 -2498
- data/lib/numru/gphys.rb +7 -1
- data/lib/numru/gphys/assoccoords.rb +384 -0
- data/lib/numru/gphys/attribute.rb +10 -11
- data/lib/numru/gphys/axis.rb +97 -25
- data/lib/numru/gphys/coordmapping.rb +2 -2
- data/lib/numru/gphys/derivative.rb +117 -46
- data/lib/numru/gphys/gphys.rb +595 -31
- data/lib/numru/gphys/gphys_fft.rb +365 -13
- data/lib/numru/gphys/gphys_grads_io.rb +6 -5
- data/lib/numru/gphys/gphys_grib_io.rb +6 -6
- data/lib/numru/gphys/gphys_gtool3_io.rb +162 -0
- data/lib/numru/gphys/gphys_hdfeos5_io.rb +672 -0
- data/lib/numru/gphys/gphys_io.rb +260 -20
- data/lib/numru/gphys/gphys_io_common.rb +1 -1
- data/lib/numru/gphys/gphys_netcdf_io.rb +111 -40
- data/lib/numru/gphys/gphys_nusdas_io.rb +64 -7
- data/lib/numru/gphys/grads_gridded.rb +158 -57
- data/lib/numru/gphys/grib.rb +205 -157
- data/lib/numru/gphys/grib_params.rb +196 -1
- data/lib/numru/gphys/grid.rb +214 -83
- data/lib/numru/gphys/gtool3.rb +771 -0
- data/lib/numru/gphys/interpolate.rb +992 -0
- data/lib/numru/gphys/mdstorage.rb +145 -0
- data/lib/numru/gphys/narray_ext.rb +34 -0
- data/lib/numru/gphys/netcdf_convention.rb +44 -2
- data/lib/numru/gphys/subsetmapping.rb +1 -1
- data/lib/numru/gphys/unumeric.rb +101 -8
- data/lib/numru/gphys/varray.rb +66 -20
- data/lib/numru/gphys/varraycomposite.rb +107 -29
- data/lib/numru/gphys/varraygrib.rb +70 -8
- data/lib/numru/gphys/varraygtool3.rb +226 -0
- data/lib/numru/gphys/varrayhdfeos5.rb +451 -0
- data/lib/numru/gphys/varraynetcdf.rb +13 -5
- data/lib/numru/gphys/version.rb +3 -0
- data/sample/druby_cli1.rb +2 -0
- data/sample/druby_cli2.rb +0 -6
- data/sample/druby_serv2.rb +0 -13
- data/sample/ncep_theta_coord.rb +79 -0
- data/test/eof_slp.rb +28 -0
- data/test/mltbit.dat +0 -0
- data/test/test_multibitIO.rb +19 -0
- data/testdata/assoc_crds.nc +0 -0
- metadata +79 -8
- data/lib/numru/dclext_datetime_ax.rb +0 -220
- data/lib/numru/vizshot.rb +0 -697
@@ -77,24 +77,31 @@ module NumRu
|
|
77
77
|
|
78
78
|
nvas = varrays.shape
|
79
79
|
vrank = nvas.length
|
80
|
-
rank=0
|
81
80
|
varrays.each{|va|
|
82
|
-
if va.
|
81
|
+
if !va.nil?
|
83
82
|
@first_vary = va
|
84
|
-
@attr = @first_vary.
|
83
|
+
@attr = @first_vary.attr_copy
|
85
84
|
@name = @first_vary.name
|
86
|
-
@
|
85
|
+
@crank = va.rank # rank of the component VArrays
|
87
86
|
break
|
88
87
|
end
|
89
88
|
}
|
90
|
-
if vrank > @
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
89
|
+
if vrank > @crank
|
90
|
+
@rank = vrank #=> @rank > @crank
|
91
|
+
else
|
92
|
+
@rank = @crank
|
93
|
+
if vrank < @crank
|
94
|
+
(@crank - vrank).times{
|
95
|
+
varrays = varrays.newdim(vrank)
|
96
|
+
nvas.push(1)
|
97
|
+
}
|
98
|
+
vrank = @crank # rank of varrays is increased to @crank (==@rank)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
un0 = varrays[0].units
|
102
|
+
for i in 1...varrays.length
|
103
|
+
va = varrays[i]
|
104
|
+
varrays[i] = va.convert_units(un0) if va && va.units != un0
|
98
105
|
end
|
99
106
|
|
100
107
|
@bound_idx = Array.new # will be Array of Array
|
@@ -106,14 +113,24 @@ module NumRu
|
|
106
113
|
len=0
|
107
114
|
varrays[*idx].each{|va|
|
108
115
|
if !set && va
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
116
|
+
### commented out for the duck typing:
|
117
|
+
#if !va.is_a?(VArray)
|
118
|
+
# raise ArgumentError,"Not a VArray: #{va.inspect}"
|
119
|
+
#end
|
120
|
+
if dim < @crank
|
121
|
+
len = va.shape_current[dim]
|
122
|
+
else
|
123
|
+
len = 1
|
124
|
+
end
|
113
125
|
@bound_idx[dim][i+1] = @bound_idx[dim][i] + len
|
114
126
|
set=true
|
115
127
|
elsif va
|
116
|
-
|
128
|
+
if dim < @crank
|
129
|
+
lc = va.shape_current[dim]
|
130
|
+
else
|
131
|
+
lc = 1
|
132
|
+
end
|
133
|
+
if lc != len
|
117
134
|
raise ArgumentError,"Non-uniformity in the #{i}th element"+
|
118
135
|
" of the #{dim}th dimension (#{va.shape_current[dim]} for #{len})"
|
119
136
|
end
|
@@ -148,10 +165,6 @@ module NumRu
|
|
148
165
|
# "bounds=#{@bound_idx.collect{|b| b[1..-2]}.inspect}"
|
149
166
|
end
|
150
167
|
|
151
|
-
def ntype
|
152
|
-
@first_vary.ntype
|
153
|
-
end
|
154
|
-
|
155
168
|
def shape
|
156
169
|
@shape
|
157
170
|
end
|
@@ -169,14 +182,18 @@ module NumRu
|
|
169
182
|
loop_multi_dim_index( @varrays.shape ){|index|
|
170
183
|
vidx = Array.new
|
171
184
|
for d in 0...@rank
|
172
|
-
|
185
|
+
if d < @crank
|
186
|
+
vidx[d] = (@bound_idx[d][index[d]])..(@bound_idx[d][index[d]+1]-1)
|
187
|
+
else
|
188
|
+
vidx[d] = @bound_idx[d][index[d]]
|
189
|
+
end
|
173
190
|
end
|
174
191
|
v = @varrays[*index].val
|
175
192
|
if !val
|
176
193
|
if NArray===v
|
177
|
-
val = NArray.new(
|
194
|
+
val = NArray.new(v.typecode,*@shape)
|
178
195
|
elsif NArrayMiss===v
|
179
|
-
val = NArrayMiss.new(
|
196
|
+
val = NArrayMiss.new(v.typecode,*@shape)
|
180
197
|
else
|
181
198
|
raise TypeError, "Unexpected type #{v.class}"
|
182
199
|
end
|
@@ -194,7 +211,11 @@ module NumRu
|
|
194
211
|
__check_ary_class(narray)
|
195
212
|
vidx = Array.new
|
196
213
|
for d in 0...@rank
|
197
|
-
|
214
|
+
if d < @crank
|
215
|
+
vidx[d] = (@bound_idx[d][index[d]])..(@bound_idx[d][index[d]+1]-1)
|
216
|
+
else
|
217
|
+
vidx[d] = @bound_idx[d][index[d]]
|
218
|
+
end
|
198
219
|
end
|
199
220
|
sub=narray[*vidx]
|
200
221
|
end
|
@@ -224,8 +245,11 @@ module NumRu
|
|
224
245
|
val
|
225
246
|
end
|
226
247
|
|
248
|
+
# def ntype
|
249
|
+
# @first_vary.ntype
|
250
|
+
# end
|
227
251
|
def ntype
|
228
|
-
__ntype(
|
252
|
+
__ntype(typecode)
|
229
253
|
end
|
230
254
|
|
231
255
|
def typecode
|
@@ -287,12 +311,12 @@ module NumRu
|
|
287
311
|
idx.each_with_index{ |ix, dim|
|
288
312
|
size = @bound_idx[dim][-1]
|
289
313
|
imask[dim] = Array.new
|
290
|
-
isub[dim] = Array.new
|
314
|
+
isub[dim] = Array.new if dim < @crank
|
291
315
|
for j in 0...(@bound_idx[dim].length)
|
292
316
|
match, isb = _imatch( size, ix, @bound_idx[dim][j..j+1] )
|
293
317
|
if match
|
294
318
|
imask[dim].push(j)
|
295
|
-
isub[dim].push(isb)
|
319
|
+
isub[dim].push(isb) if dim < @crank
|
296
320
|
end
|
297
321
|
end
|
298
322
|
}
|
@@ -335,6 +359,11 @@ module NumRu
|
|
335
359
|
stp = 1
|
336
360
|
else # Hash
|
337
361
|
range, stp = index.to_a[0]
|
362
|
+
if stp<=0
|
363
|
+
raise(ArgumentError,"Currently only positive step is supported")
|
364
|
+
# development note: current handling of fst and lst assumes a
|
365
|
+
# positive step
|
366
|
+
end
|
338
367
|
range = 0..-1 if range==true
|
339
368
|
fst = range.first
|
340
369
|
fst += size if fst < 0
|
@@ -350,11 +379,28 @@ module NumRu
|
|
350
379
|
if stp==1
|
351
380
|
return [true, a..b ]
|
352
381
|
else
|
353
|
-
|
382
|
+
len = last-first+1
|
383
|
+
if a<len
|
384
|
+
return [true, {(a..b) => stp} ]
|
385
|
+
else
|
386
|
+
return [false, nil]
|
387
|
+
end
|
354
388
|
end
|
355
389
|
else
|
356
390
|
return [false, nil]
|
357
391
|
end
|
392
|
+
when Array
|
393
|
+
match = false
|
394
|
+
isb = []
|
395
|
+
index.each{ |idx|
|
396
|
+
idx += size if idx < 0
|
397
|
+
if first <= idx && idx <= last
|
398
|
+
match = true
|
399
|
+
isb.push(idx-first)
|
400
|
+
end
|
401
|
+
}
|
402
|
+
isb = nil if isb == []
|
403
|
+
return [match, isb]
|
358
404
|
else
|
359
405
|
raise "Unsupported type for indexing: #{index.class}"
|
360
406
|
end
|
@@ -412,4 +458,36 @@ if __FILE__ == $0
|
|
412
458
|
vac.set_att('long_name', 'test data')
|
413
459
|
p vac.get_att('long_name')
|
414
460
|
p va01.get_att('long_name')
|
461
|
+
p vac.typecode,vac.ntype
|
462
|
+
|
463
|
+
puts "testing rank extension.."
|
464
|
+
va0 = VArray.new( NArray.float(3,2).indgen!, {"units"=>"m/s"}, 'V' )
|
465
|
+
va1 = VArray.new( NArray.float(3,2).indgen!+100, {"units"=>"m/s"}, 'V' )
|
466
|
+
va2 = VArray.new( NArray.float(3,2).indgen!+200, {"units"=>"m/s"}, 'V' )
|
467
|
+
va3 = VArray.new( NArray.float(3,2).indgen!+300, {"units"=>"m/s"}, 'V' )
|
468
|
+
varrays = NArray.to_na([ [[va0]], [[va1]], [[va2]], [[va3]] ])
|
469
|
+
vac = VArrayComposite.new(varrays)
|
470
|
+
p vac, vac.val
|
471
|
+
if vac[1,1,1].val == 104.0
|
472
|
+
puts "test OK"
|
473
|
+
else
|
474
|
+
raise "test failed"
|
475
|
+
end
|
476
|
+
|
477
|
+
v = vac[0..1,0,{1..-1=>2}].val
|
478
|
+
ans = NArray.to_na( [ [100.0,101.0], [300.0, 301.0] ] )
|
479
|
+
if v==ans
|
480
|
+
puts "test OK"
|
481
|
+
else
|
482
|
+
raise "test failed"
|
483
|
+
end
|
484
|
+
|
485
|
+
vac[-1,true,1..2] = -999.0
|
486
|
+
if vac[-1,true,1..2].val.to_a.flatten.uniq == [-999.0 ]
|
487
|
+
puts "test OK"
|
488
|
+
else
|
489
|
+
raise "test failed"
|
490
|
+
end
|
491
|
+
#vac.val = NArray.float(3,2,4).random!
|
492
|
+
#p vac.val
|
415
493
|
end
|
@@ -4,6 +4,14 @@
|
|
4
4
|
=end
|
5
5
|
|
6
6
|
require "numru/gphys/grib"
|
7
|
+
|
8
|
+
### to be made below in the definition of VArrayGrib in order to record
|
9
|
+
### whetehr its successfull or not
|
10
|
+
#begin
|
11
|
+
# require "numru/grib"
|
12
|
+
#rescue LoadError
|
13
|
+
#end
|
14
|
+
|
7
15
|
require "numru/gphys/varray"
|
8
16
|
|
9
17
|
module NumRu
|
@@ -16,8 +24,50 @@ module NumRu
|
|
16
24
|
=end
|
17
25
|
class VArrayGrib < VArray
|
18
26
|
|
27
|
+
begin
|
28
|
+
require "numru/grib"
|
29
|
+
@@rbgribloaded = true
|
30
|
+
rescue LoadError
|
31
|
+
@@rbgribloaded = false
|
32
|
+
end
|
33
|
+
|
34
|
+
@@GribLib = :gphys_grib
|
35
|
+
|
36
|
+
class << self
|
37
|
+
def use_gphys_grib
|
38
|
+
@@GribLib = :gphys_grib
|
39
|
+
set_grib_lib
|
40
|
+
end
|
41
|
+
def use_rb_grib
|
42
|
+
if !@@rbgribloaded
|
43
|
+
raise LoadError, "Loading rb-GRIB has been failed. You probably need to install it."
|
44
|
+
end
|
45
|
+
@@GribLib = :rb_grib
|
46
|
+
set_grib_lib
|
47
|
+
end
|
48
|
+
def grib_lib
|
49
|
+
@@GribLib.dup
|
50
|
+
end
|
51
|
+
def grib
|
52
|
+
@@Grib
|
53
|
+
end
|
54
|
+
def set_grib_lib
|
55
|
+
case @@GribLib
|
56
|
+
when :gphys_grib
|
57
|
+
@@GribDim = GPhys::GribDim
|
58
|
+
@@GribVar = GPhys::GribVar
|
59
|
+
@@Grib = GPhys::Grib
|
60
|
+
when :rb_grib
|
61
|
+
@@GribDim = GribDim
|
62
|
+
@@GribVar = GribVar
|
63
|
+
@@Grib = Grib
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
set_grib_lib
|
68
|
+
|
19
69
|
def initialize(aGribVar)
|
20
|
-
if
|
70
|
+
if !@@GribVar===aGribVar && !@@GribDim===aGribVar
|
21
71
|
raise ArgumentError,"Not a GribVar or GribDim"
|
22
72
|
end
|
23
73
|
@name = aGribVar.name
|
@@ -26,9 +76,11 @@ module NumRu
|
|
26
76
|
@ary = aGribVar
|
27
77
|
@attr = Attribute.new
|
28
78
|
aGribVar.att_names.each{|name|
|
29
|
-
|
79
|
+
val = aGribVar.att(name)
|
80
|
+
val = [val] if val.is_a?(Numeric)
|
81
|
+
@attr[name] = val
|
30
82
|
}
|
31
|
-
if GribDim===@ary
|
83
|
+
if @@GribDim===@ary
|
32
84
|
class << @ary
|
33
85
|
def rank
|
34
86
|
return 1
|
@@ -41,9 +93,9 @@ module NumRu
|
|
41
93
|
end
|
42
94
|
|
43
95
|
def inspect
|
44
|
-
if GribVar===@ary
|
96
|
+
if @@GribVar===@ary
|
45
97
|
"<'#{@name}' in '#{@ary.file.path}' [#{@ary.shape.join(", ")}]>"
|
46
|
-
elsif GribDim===@ary
|
98
|
+
elsif @@GribDim===@ary
|
47
99
|
"<'#{@name}' in '#{@ary.var.name}' #{@ary.length}>"
|
48
100
|
end
|
49
101
|
end
|
@@ -55,7 +107,7 @@ module NumRu
|
|
55
107
|
v = file.def_var(name)
|
56
108
|
dims.length.times{|n|
|
57
109
|
d = dims[n]
|
58
|
-
if GribDim===d
|
110
|
+
if @@GribDim===d
|
59
111
|
gd = v.def_dim(d.name,n)
|
60
112
|
gd.put(d.get)
|
61
113
|
d.att_names.each{|name| gd.put_att(name,d.att(name)) }
|
@@ -80,7 +132,7 @@ module NumRu
|
|
80
132
|
## < additional class methods > ##
|
81
133
|
|
82
134
|
def write(file,vary,dims=nil)
|
83
|
-
Grib===file || raise(ArgumentError,"1st arg: not a Grib")
|
135
|
+
@@Grib===file || raise(ArgumentError,"1st arg: not a Grib")
|
84
136
|
VArray===vary || raise(ArgumentError,"2st arg: not a VArray")
|
85
137
|
rank = vary.rank
|
86
138
|
if !dims
|
@@ -157,7 +209,7 @@ if $0 == __FILE__
|
|
157
209
|
|
158
210
|
include NumRu
|
159
211
|
|
160
|
-
grib =
|
212
|
+
grib = VArrayGrib.grib.open("../../../testdata/T.jan.grib")
|
161
213
|
gv = grib.var("TMP")
|
162
214
|
|
163
215
|
va = VArrayGrib.new(gv)
|
@@ -174,4 +226,14 @@ if $0 == __FILE__
|
|
174
226
|
p va2.shape
|
175
227
|
p va2.val
|
176
228
|
|
229
|
+
begin
|
230
|
+
VArrayGrib.use_rb_grib
|
231
|
+
grib = VArrayGrib.grib.open("../../../testdata/T.jan.grib")
|
232
|
+
p grib.var_names
|
233
|
+
gv = grib.var("t")
|
234
|
+
p gv.val
|
235
|
+
rescue LoadError
|
236
|
+
print "...error rescued & test skipped\n\n"
|
237
|
+
end
|
238
|
+
|
177
239
|
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
=begin
|
2
|
+
=ToDo list
|
3
|
+
* Support a temporay attribute (@tmp_attr = Attribute.new)
|
4
|
+
=end
|
5
|
+
|
6
|
+
require "numru/gphys/gtool3"
|
7
|
+
require "numru/gphys/varray"
|
8
|
+
|
9
|
+
module NumRu
|
10
|
+
|
11
|
+
ATTR_CF_CONV = {
|
12
|
+
"DSET" => "dataset",
|
13
|
+
"TITLE" => "long_name",
|
14
|
+
"UNIT" => "units",
|
15
|
+
"MISS" => "missing_value"
|
16
|
+
# "ITEM" => nil, # identical to name
|
17
|
+
# "TIME" => nil, # treated in the time axis
|
18
|
+
# "DATE" => nil, # treated in the time axis
|
19
|
+
# "UTIM" => nil, # treated in the time axis
|
20
|
+
# "TDUR" => nil, # in Future, should be treaded with cell_* in CF
|
21
|
+
# "CSIGN" => nil, # will be in history in convination
|
22
|
+
# "CDATE" => nil # will be in history in convination
|
23
|
+
# "MDATE" => nil, # will be in history in convination
|
24
|
+
# "MSIGN" => nil, # will be in history in convination
|
25
|
+
}
|
26
|
+
|
27
|
+
class VArrayGtool3 < VArray
|
28
|
+
|
29
|
+
## < initialization redefined > ##
|
30
|
+
|
31
|
+
def initialize(aGtool3Var)
|
32
|
+
raise ArgumentError,"Not a Gtool3Var" if ! aGtool3Var.is_a?(Gtool3Var)
|
33
|
+
@name = aGtool3Var.name
|
34
|
+
@mapping = nil
|
35
|
+
@varray = nil
|
36
|
+
@ary = aGtool3Var
|
37
|
+
@attr = _attr_conv_to_CF( aGtool3Var.attr )
|
38
|
+
end
|
39
|
+
|
40
|
+
def _attr_conv_to_CF(org)
|
41
|
+
attr = Attribute.new
|
42
|
+
ATTR_CF_CONV.each do |ik,ok|
|
43
|
+
val = org[ik]
|
44
|
+
val = NArray[val] if val.is_a?(Numeric)
|
45
|
+
attr[ok] = val
|
46
|
+
end
|
47
|
+
hist = ""
|
48
|
+
hist += "Created #{org["CDATE"]} by #{org["CSIGN"]}. " if org["CDATE"]
|
49
|
+
hist += "Modifiled #{org["MDATE"]} by #{org["MSIGN"]}. "if org["MDATE"]
|
50
|
+
attr["history"] = hist if hist.length > 0
|
51
|
+
attr
|
52
|
+
end
|
53
|
+
private :_attr_conv_to_CF
|
54
|
+
|
55
|
+
class << self
|
56
|
+
## < redefined class methods > ##
|
57
|
+
|
58
|
+
#def new2(file, name, ntype, dimensions, attr=nil)
|
59
|
+
# va = new( file.def_var(name, ntype, dimensions) )
|
60
|
+
# if attr; attr.each{|key,val| va.attr[key]=val}; end
|
61
|
+
# va
|
62
|
+
#end
|
63
|
+
undef new2
|
64
|
+
|
65
|
+
# to make a varray from an axis (except for time)
|
66
|
+
def make_coord(hash)
|
67
|
+
nary = hash.delete(:val)
|
68
|
+
name = hash.delete("ITEM")
|
69
|
+
coord_att_conv!(hash)
|
70
|
+
VArray.new(nary, hash, name)
|
71
|
+
end
|
72
|
+
|
73
|
+
def coord_att_conv!(hash)
|
74
|
+
hash.keys.each do |k|
|
75
|
+
v = hash.delete(k)
|
76
|
+
if (ck=ATTR_CF_CONV[k]) # substitution, not ==
|
77
|
+
v = NArray[v] if v.is_a?(Numeric)
|
78
|
+
if k=="UNIT"
|
79
|
+
case v
|
80
|
+
when "deg"
|
81
|
+
v = "degrees"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
hash[ck] = v
|
85
|
+
elsif k=="STYP" && v
|
86
|
+
if v >= 0
|
87
|
+
hash["positive"] = "up"
|
88
|
+
else
|
89
|
+
hash["positive"] = "down"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
hash
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
## < redefined instance methods > ##
|
98
|
+
|
99
|
+
def val
|
100
|
+
v = @ary.get
|
101
|
+
end
|
102
|
+
|
103
|
+
def val=(narray)
|
104
|
+
@ary.put( __check_ary_class2(narray) )
|
105
|
+
narray
|
106
|
+
end
|
107
|
+
|
108
|
+
# # It is safer not to have the method "shape" to avoid misconfusion of
|
109
|
+
# # shape_ul0 and shape_current:
|
110
|
+
# def shape
|
111
|
+
# raise "The shape method is not available. Use shape_ul0 or shape_current instead."
|
112
|
+
# end
|
113
|
+
|
114
|
+
def inspect
|
115
|
+
"<'#{@name}' in '#{@ary.file.path}' #{ntype}#{shape_current.inspect}>"
|
116
|
+
end
|
117
|
+
|
118
|
+
def total
|
119
|
+
len = 1
|
120
|
+
@ary.shape_current.each{|i| len *= i}
|
121
|
+
len
|
122
|
+
end
|
123
|
+
alias length total
|
124
|
+
|
125
|
+
def rank
|
126
|
+
shape_current.length
|
127
|
+
end
|
128
|
+
|
129
|
+
# def reshape!( *args )
|
130
|
+
# raise "cannot reshape a #{class}. Use copy first to make it a VArray with NArray"
|
131
|
+
# end
|
132
|
+
undef reshape!
|
133
|
+
|
134
|
+
|
135
|
+
## < additional instance methods > ##
|
136
|
+
|
137
|
+
def dim_names
|
138
|
+
@ary.dim_names
|
139
|
+
end
|
140
|
+
def shape_ul0
|
141
|
+
@ary.shape_ul0
|
142
|
+
end
|
143
|
+
def shape_current
|
144
|
+
@ary.shape_current
|
145
|
+
end
|
146
|
+
def file
|
147
|
+
@ary.file
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
class VArrayGtool3Time < VArray
|
153
|
+
def initialize(hash, calendar=nil)
|
154
|
+
@ary = hash.delete(:val)
|
155
|
+
@name = hash.delete("ITEM")
|
156
|
+
@attr = Attribute.new
|
157
|
+
@attr.update( VArrayGtool3.coord_att_conv!(hash) )
|
158
|
+
@attr["calendar"] = calendar if calendar
|
159
|
+
@varray = nil
|
160
|
+
@mapping = nil
|
161
|
+
end
|
162
|
+
|
163
|
+
def inspect
|
164
|
+
"<'#{name}' in '#{@ary.file.path}' #{ntype}#{shape.inspect}>"
|
165
|
+
end
|
166
|
+
|
167
|
+
def val
|
168
|
+
@ary.get
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
###########################################################
|
176
|
+
### < test >
|
177
|
+
|
178
|
+
if $0 == __FILE__
|
179
|
+
# $DEBUG = true
|
180
|
+
include NumRu
|
181
|
+
Gtool3.gtaxdir = File.expand_path("~/dennou/GTAXDIR")
|
182
|
+
path = ARGV[0]
|
183
|
+
varname = ARGV[1] or raise("Need two args")
|
184
|
+
|
185
|
+
file = Gtool3.open(File.expand_path(path))
|
186
|
+
var = file.var(varname)
|
187
|
+
va = VArrayGtool3.new(var)
|
188
|
+
|
189
|
+
p va, va.name
|
190
|
+
p va.dim_names
|
191
|
+
p va.shape_ul0
|
192
|
+
p va.val
|
193
|
+
|
194
|
+
va.att_names.each do |nm|
|
195
|
+
print nm,"\t",va.get_att(nm).inspect,"\n"
|
196
|
+
end
|
197
|
+
|
198
|
+
p va.get_att("long_name")
|
199
|
+
|
200
|
+
print "***************\n"
|
201
|
+
va2 = va[3..9,5..15,0,0]
|
202
|
+
p va2.shape
|
203
|
+
p va2.val
|
204
|
+
|
205
|
+
p va2.get_att("long_name")
|
206
|
+
|
207
|
+
print "****** time *******\n"
|
208
|
+
|
209
|
+
t = VArrayGtool3Time.new(var.axis(-1)["LOC"])
|
210
|
+
p t, t[1..3].val
|
211
|
+
t.att_names.each do |nm|
|
212
|
+
print nm,"\t",va.get_att(nm).inspect,"\n"
|
213
|
+
end
|
214
|
+
|
215
|
+
print "****** lon *******\n"
|
216
|
+
|
217
|
+
xg = var.axis(0)["LOC"]
|
218
|
+
#nm = xg.delete("ITEM)"
|
219
|
+
#na = xg.delete(:val)
|
220
|
+
#x = VArray.new(na, xg, nm)
|
221
|
+
x = VArrayGtool3.make_coord(xg)
|
222
|
+
p x, x[1..3].val
|
223
|
+
x.att_names.each do |nm|
|
224
|
+
print nm,"\t",x.get_att(nm).inspect,"\n"
|
225
|
+
end
|
226
|
+
end
|