iconPlot 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/gemspec +4 -1
  2. data/lib/iconPlot.rb +80 -0
  3. data/test/test_iconPlot.rb +5 -0
  4. metadata +36 -3
data/gemspec CHANGED
@@ -3,7 +3,7 @@ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
3
3
 
4
4
  spec = Gem::Specification.new do |s|
5
5
  s.name = "iconPlot"
6
- s.version = '0.0.2'
6
+ s.version = '0.0.3'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.files = ["lib/iconPlot.rb"] + ["gemspec"] + ["contrib/nclsh"] + Dir.glob("lib/*ncl")
9
9
  s.test_file = "test/test_iconPlot.rb"
@@ -14,6 +14,9 @@ spec = Gem::Specification.new do |s|
14
14
  s.homepage = "https://github.com/Try2Code/iconPlot"
15
15
  s.license = "GPLv2"
16
16
  s.required_ruby_version = ">= 1.8"
17
+ s.add_dependency('cdo')
18
+ s.add_dependency('extcsv')
19
+ s.add_dependency('gnuplot')
17
20
  end
18
21
 
19
22
  # vim:ft=ruby
data/lib/iconPlot.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require 'fileutils'
2
+ require 'cdo'
3
+ require 'extcsv'
4
+ require 'shellwords'
2
5
 
3
6
  class IconPlot < Struct.new(:caller,:plotter,:libdir,:otype,:display,:cdo,:debug)
4
7
  def IconPlot.gemPath
@@ -52,6 +55,36 @@ class IconPlot < Struct.new(:caller,:plotter,:libdir,:otype,:display,:cdo,:debug
52
55
  def vectorPlot(ifile,ofile,varname,opts={})
53
56
  plot(ifile,ofile,varname,'vector',opts)
54
57
  end
58
+ def levelPlot(ifile,ofile,varname,opts={})
59
+ Cdo.setCdo('/home/ram/src/cdo/trunk/cdo/build/bin/cdo')
60
+ operation = opts[:operation].nil? ? 'fldmin' : opts[:operation]
61
+
62
+ data = createData(ifile,varname,operation)
63
+ icon = ExtCsv.new("array","plain",data.transpose)
64
+ setDatetime(icon)
65
+
66
+ # Plot data with automatic splitting by depth
67
+ unless icon.datacolumns.include?(varname)
68
+ warn "Variable cannot be found!"
69
+ exit -1
70
+ end
71
+ Cdo.debug = true
72
+ unit = Cdo.showunit(:in => "-selname,#{varname} #{ifile}").first
73
+ ExtCsvDiagram.plot_xy(icon,"datetime",varname,
74
+ "ICON: #{operation} on #{varname} (file:#{ifile})", # Change title here
75
+ :label_position => 'below',:skipColumnCheck => true,
76
+ :type => 'lines',:groupBy => ["depth"], :onlyGroupTitle => true,
77
+ # :addSettings => ["logscale y"], # Commend theses out for large scale values like Vert_Mixing_V
78
+ # :yrange => '[0.0001:10]', # Otherwise you'll see nothing reasonable
79
+ :terminal => true ? 'png' : 'x11',
80
+ :ylabel => "#{varname} [#{Shellwords.escape(unit)}]", # Correct the label if necessary
81
+ :input_time_format => "'%Y%m%d %H:%M:%S'",
82
+ :filename => ofile,
83
+ :output_time_format => '"%d.%m.%y \n %H:%M"',:size => "1600,600")
84
+ return "#{ofile}.png"
85
+ end
86
+ def scatterPlot(ifile,ofile,varname,opts={})
87
+ end
55
88
 
56
89
  def del(file)
57
90
  FileUtils.rm(file) if File.exists?(file)
@@ -65,4 +98,51 @@ class IconPlot < Struct.new(:caller,:plotter,:libdir,:otype,:display,:cdo,:debug
65
98
  def showVector(ifile,ofile,vars,opts={})
66
99
  show(vectorPlot(ifile,ofile,vars,opts))
67
100
  end
101
+
102
+ def createData(ifile,varname,operation)
103
+ # Temporal file for text output
104
+ dataFile = MyTempfile.path
105
+
106
+ # read the date
107
+ IO.popen("echo 'date|time|depth|#{varname}' > #{dataFile}")
108
+ Cdo.debug = true
109
+ Cdo.outputkey('date,time,level,value',
110
+ :in => "-#{operation} -selname,#{varname} #{ifile} >>#{dataFile} 2>&1")
111
+
112
+ # postprocessing for correct time values
113
+ data = []
114
+ File.open(dataFile).each_with_index {|line,lineIndex|
115
+ next if line.chomp.empty?
116
+ _t = line.chomp.gsub(/ +/,'|').split('|')
117
+ if 0 == lineIndex then
118
+ data << _t
119
+ next
120
+ end
121
+ if "0" == _t[1] then
122
+ _t[1] = '00:00:00'
123
+ else
124
+ time = _t[1].reverse
125
+ timeStr = ''
126
+ while time.size > 2 do
127
+ timeStr << time[0,2] << ':'
128
+ time = time[2..-1]
129
+ end
130
+ timeStr << time.ljust(2,'0') unless time.size == 0
131
+ _t[1] = timeStr.reverse
132
+ end
133
+ data << _t
134
+ }
135
+ data
136
+ end
137
+
138
+ def setDatetime(extcsvObj)
139
+ unless (extcsvObj.respond_to?(:date) and extcsvObj.respond_to?(:time))
140
+ warn "Cannot set datetime due to missing date and time attributes"
141
+ raise ArgumentError
142
+ end
143
+ # Create datetime column for timeseries plot
144
+ extcsvObj.datetime = []
145
+ extcsvObj.date.each_with_index{|date,i| extcsvObj.datetime << [date,extcsvObj.time[i]].join(' ') }
146
+ extcsvObj.datacolumns << "datetime"
147
+ end
68
148
  end
@@ -9,6 +9,7 @@ class TestIconPlot < Test::Unit::TestCase
9
9
  PLOTLIB = "/home/ram/src/git/icon/scripts/postprocessing/tools"
10
10
  LS = 'ls -crtlh'
11
11
  OCE_PLOT_TEST_FILE = ENV['HOME']+'/data/icon/oce.nc'
12
+ OCELONG_PLOT_TEST_FILE = ENV['HOME']+'/data/icon/oceLong.nc'
12
13
  ATM_PLOT_TEST_FILE = ENV['HOME']+'/data/icon/atm.nc'
13
14
  OCE_REGPLOT_TEST_FILE = ENV['HOME']+'/data/icon/regular_oce.nc' #remapnn,r180x90
14
15
  ATM_REGPLOT_TEST_FILE = ENV['HOME']+'/data/icon/regular_atm.nc' #remapnn,n63 (no sections), r180x90 (with sections)
@@ -30,4 +31,8 @@ class TestIconPlot < Test::Unit::TestCase
30
31
  assert_includes(p.plotter.split(File::SEPARATOR),'gems')
31
32
  assert_includes(p.libdir.split(File::SEPARATOR),'gems')
32
33
  end
34
+ def test_levelPlot
35
+ p = IconPlot.new
36
+ p.show( p.levelPlot(OCELONG_PLOT_TEST_FILE,'test_levelPlot_00','T',:operation => :fldmax))
37
+ end
33
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iconPlot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,41 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-23 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-08-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cdo
16
+ requirement: &16945020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *16945020
25
+ - !ruby/object:Gem::Dependency
26
+ name: extcsv
27
+ requirement: &16944200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *16944200
36
+ - !ruby/object:Gem::Dependency
37
+ name: gnuplot
38
+ requirement: &16943700 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *16943700
14
47
  description: ! 'Plot with ncl via Ruby: requires NCL 6.* and CDO 1.5.*'
15
48
  email: stark.dreamdetective@gmail.com
16
49
  executables: []