Class: NumRu::VizShot

Inherits:
Object
  • Object
show all
Defined in:
lib/vizshot_gfdnavi.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



6
7
8
9
# File 'lib/vizshot_gfdnavi.rb', line 6

def ==(other)
  return false unless @set == other.instance_variable_get("@set")
  self.instance_variable_get("@plots") == other.instance_variable_get("@plots")
end

#_gen_codeObject

redefined



55
# File 'lib/vizshot_gfdnavi.rb', line 55

alias :_gen_code :gen_code

#cut_out_data(basename) ⇒ Object

redefined



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/vizshot_gfdnavi.rb', line 101

def cut_out_data(basename)
  newplots = Array.new
  data_paths = Array.new
  @plots.each_with_index{|pl, i|
    gphys, gphys2 = get_gphyses(pl.dup)
    method = pl[:method]
    script = pl.delete(:script)
    cut = pl.delete(:cut)
    slice = pl.delete(:slice)
    ndims = self.class.ndims(method)
    filename = basename + sprintf("_%03d",i) + '.nc'
    data_paths.push _output_data(gphys,filename,ndims)
    pl = pl.dup
    pl[:file] = filename
    pl[:var] = gphys.name
    if gphys2
      cut2 = pl.delete(:cut2) || cut
      slice2 = pl.delete(:slice2) || slice
      filename = basename + sprintf("_%03d_2",i) + '.nc'
      data_paths.push _output_data(gphys2,filename,ndims)
      pl = pl.dup
      pl[:file2] = filename
      pl[:var2] = gphys.name
    end
  }
  return data_paths
end

#gen_code(all_in_one = false, exec_opt = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
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
94
95
96
97
98
# File 'lib/vizshot_gfdnavi.rb', line 56

def gen_code(all_in_one=false, exec_opt=nil)
  if exec_opt
    case exec_opt.delete(:for)
    when :in
      flag = true
    when :out
      flag = false
      basename = exec_opt.delete(:basename)
    else
      raise "BUG"
    end
    exec_opts = nil if exec_opt.empty?
  else
    raise "BUG"
  end
  plots_org = @plots
  i = 0
  @plots = @plots.collect do |plot|
    plot = plot.dup
    vars = plot.delete(:variables)
    if flag
      v =  var_from_path(vars[0])
      plot[:file] = v.fname
      plot[:var] = v.vname
      if vars[1]
        v =  var_from_path(vars[1])
        plot[:file2] = v.fname
        plot[:var2] = v.vname
      end
    else
      plot[:file] = basename + sprintf("_%03d",i) + '.nc'
      plot[:var] = File.basename(vars[0])
      if vars[1]
        plot[:file2] = basename + sprintf("_%03d_2",i) + '.nc'
        plot[:var2] = File.basename(vars[1])
      end
    end
    plot
  end
  code = _gen_code(all_in_one, exec_opt)
  @plots = plots_org
  return code
end

#get_itrObject



46
47
48
# File 'lib/vizshot_gfdnavi.rb', line 46

def get_itr
  @set[:fig]['itr']
end

#get_plots(num = nil) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/vizshot_gfdnavi.rb', line 34

def get_plots(num=nil)
  if num
    @plots[num].dup
  else
    @plots.collect{|pl| pl.dup}
  end
end

#get_sizeObject



42
43
44
# File 'lib/vizshot_gfdnavi.rb', line 42

def get_size
  [ @set[:admin][:iwidth], @set[:admin][:iheight] ]
end

#get_variablesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vizshot_gfdnavi.rb', line 11

def get_variables
  unless @variables
    @variables = Array.new
    @plots.each{|pl|
      pl[:variables].each{|path|
        var =  var_from_path(path)
        if var
          @variables.push var unless @variables.include?(var)
        else
          raise "[BUG] variable is invalid (#{path})"
        end
      }
    }
  end
  return @variables
end

#get_viewportObject



50
51
52
# File 'lib/vizshot_gfdnavi.rb', line 50

def get_viewport
  @set[:fig]['viewport'].join(',')
end

#to_yaml_propertiesObject



28
29
30
31
32
# File 'lib/vizshot_gfdnavi.rb', line 28

def to_yaml_properties
  props = instance_variables.sort
  props.delete("@variables")
  return props
end