Class: NumRu::VArrayGrib

Inherits:
VArray
  • Object
show all
Defined in:
lib/numru/gphys/varraygrib.rb

Overview

NumRu::VArrayGrib < VArray

Class Methods

—new(GribVar)

Methods

Constant Summary collapse

@@GribLib =
:gphys_grib

Constants inherited from VArray

NumRu::VArray::Binary_operators, NumRu::VArray::Binary_operatorsL, NumRu::VArray::Binary_operatorsL_comp, NumRu::VArray::Binary_operatorsL_other, NumRu::VArray::Binary_operators_Uconv, NumRu::VArray::Binary_operators_Unone, NumRu::VArray::Binary_operators_Uop, NumRu::VArray::Math_funcs, NumRu::VArray::Math_funcs_nondim, NumRu::VArray::Math_funcs_radian, NumRu::VArray::NArray_type1_methods, NumRu::VArray::NArray_type2_methods, NumRu::VArray::NArray_type2_methods1, NumRu::VArray::NArray_type2_methods2, NumRu::VArray::NArray_type2_methods3, NumRu::VArray::NArray_type3_methods, NumRu::VArray::Unary_operators

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VArray

#+@, #[], #[]=, #att_names, #attr_copy, #axis_cyclic?, #axis_cyclic_extendible?, #axis_draw_positive, #axis_modulo, #bin_mean, #bin_sum, #coerce, #convert_units, #copy, #del_att, #get_att, #long_name, #long_name=, #mapped?, #marshal_dump, #marshal_load, #name, #name=, #ntype, #rename, #rename!, #replace_val, #reshape, #reshape!, #set_att, #sqrt, #to_g1D, #transpose, #units, #units=

Constructor Details

#initialize(aGribVar) ⇒ VArrayGrib

Returns a new instance of VArrayGrib.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/numru/gphys/varraygrib.rb', line 69

def initialize(aGribVar)
  if !@@GribVar===aGribVar && !@@GribDim===aGribVar
    raise ArgumentError,"Not a GribVar or GribDim"
  end
  @name = aGribVar.name
  @mapping = nil
  @varray = nil
  @ary = aGribVar
  @attr = Attribute.new
  aGribVar.att_names.each{|name|
    val = aGribVar.att(name)
    val = [val] if val.is_a?(Numeric)
    @attr[name] = val
  }
  if @@GribDim===@ary
    class << @ary
      def rank
        return 1
      end
      def shape
        return [@length]
      end
    end
  end
end

Class Method Details

.gribObject



51
52
53
# File 'lib/numru/gphys/varraygrib.rb', line 51

def grib
  @@Grib
end

.grib_libObject



48
49
50
# File 'lib/numru/gphys/varraygrib.rb', line 48

def grib_lib
  @@GribLib.dup
end

.new2(file, name, dims, vary) ⇒ Object Also known as: def_var

< redefined class methods > ##



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/numru/gphys/varraygrib.rb', line 106

def new2(file, name, dims, vary)
  v = file.def_var(name)
  dims.length.times{|n|
    d = dims[n]
    if @@GribDim===d
      gd = v.def_dim(d.name,n)
      gd.put(d.get)
      d.att_names.each{|name| gd.put_att(name,d.att(name)) }
    elsif VArray===d
      gd = v.def_dim(d.name,n)
      gd.put(d.val)
      d.att_names.each{|name| gd.put_att(name,d.get_att(name)) }
    elsif String===d
      gd = v.def_dim(d,n)
      gd.put(NArray.sfloat(vary.shape_ul0[n]).indgen)
    else
      raise "type is not correct"
    end
  }
  va = new(v)
  vary.att_names.each{|name| va.put_att(name,vary.get_att(name)) }
  return va
end

.set_grib_libObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/numru/gphys/varraygrib.rb', line 54

def set_grib_lib
  case @@GribLib
  when :gphys_grib
    @@GribDim = GPhys::GribDim
    @@GribVar = GPhys::GribVar
    @@Grib = GPhys::Grib
  when :rb_grib
    @@GribDim = GribDim
    @@GribVar = GribVar
    @@Grib = Grib
  end
end

.use_gphys_gribObject



37
38
39
40
# File 'lib/numru/gphys/varraygrib.rb', line 37

def use_gphys_grib
  @@GribLib = :gphys_grib
  set_grib_lib
end

.use_rb_gribObject



41
42
43
44
45
46
47
# File 'lib/numru/gphys/varraygrib.rb', line 41

def use_rb_grib
  if !@@rbgribloaded
    raise LoadError, "Loading rb-GRIB has been failed. You probably need to install it."
  end
  @@GribLib = :rb_grib
  set_grib_lib
end

.write(file, vary, dims = nil) ⇒ Object

< additional class methods > ##



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/numru/gphys/varraygrib.rb', line 134

def write(file,vary,dims=nil)
  @@Grib===file || raise(ArgumentError,"1st arg: not a Grib")
  VArray===vary || raise(ArgumentError,"2st arg: not a VArray")
  rank = vary.rank
  if !dims
    dims = vary.dim_names
    if VArrayGrib===vary
      class << vary
        def dim(dn)
          @ary.dim(dn)
        end
      end
      dims = dims.collect{|dim| vary.dim(dim) }
    end
  end
  newvary = new2(file,vary.name,dims,vary)
  newvary.val = vary.val
  file.write
  return newvary
end

Instance Method Details

#dim_namesObject

< additional instance methods > ##



184
185
186
# File 'lib/numru/gphys/varraygrib.rb', line 184

def dim_names
  @ary.dim_names
end

#fileObject



193
194
195
# File 'lib/numru/gphys/varraygrib.rb', line 193

def file
  @ary.file
end

#inspectObject



95
96
97
98
99
100
101
# File 'lib/numru/gphys/varraygrib.rb', line 95

def inspect
  if @@GribVar===@ary
    "<'#{@name}' in '#{@ary.file.path}'  [#{@ary.shape.join(", ")}]>"
  elsif @@GribDim===@ary
    "<'#{@name}' in '#{@ary.var.name}'  #{@ary.length}>"
  end
end

#put_att(name, val) ⇒ Object



197
198
199
# File 'lib/numru/gphys/varraygrib.rb', line 197

def put_att(name,val)
  @ary.put_att(name,val)
end

#rankObject



176
177
178
# File 'lib/numru/gphys/varraygrib.rb', line 176

def rank
  @ary.rank
end

#shapeObject



167
168
169
# File 'lib/numru/gphys/varraygrib.rb', line 167

def shape
  @ary.shape
end

#shape_currentObject



190
191
192
# File 'lib/numru/gphys/varraygrib.rb', line 190

def shape_current
  @ary.shape
end

#shape_ul0Object



187
188
189
# File 'lib/numru/gphys/varraygrib.rb', line 187

def shape_ul0
  @ary.shape
end

#totalObject Also known as: length



171
172
173
# File 'lib/numru/gphys/varraygrib.rb', line 171

def total
  @ary.total
end

#valObject

< redefined instance methods > ##



158
159
160
# File 'lib/numru/gphys/varraygrib.rb', line 158

def val
  return @ary.val
end

#val=(narray) ⇒ Object



162
163
164
165
# File 'lib/numru/gphys/varraygrib.rb', line 162

def val=(narray)
  shape==narray.shape || raise("not same shape")
  @ary.put(narray)
end