graphkit 0.1.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "> 1.0.0"
12
+ gem "jeweler", "~> 1.8.4"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Edmund Highcock
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ graphkit
2
+ ========
3
+
4
+ A GraphKit is a device independent intelligent data container that allows the easy sharing, combining and plotting of graphic data representations. Easily created from data, they can be output in a variety of formats using packages such as gnuplot.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = graphkit
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to graphkit
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Edmund Highcock. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "graphkit"
18
+ gem.homepage = "http://github.com/edmundhighcock/graphkit"
19
+ gem.license = "GPLv3"
20
+ gem.summary = %Q{A GraphKit is a device independent intelligent data container for generating and plotting graphs.}
21
+ gem.description = %Q{A GraphKit is a device independent intelligent data container that allows the easy sharing, combining and plotting of graphic data representations. Easily created from data, they can be output in a variety of formats using packages such as gnuplot. }
22
+ gem.email = "edmundhighcock@sourceforge.net"
23
+ gem.authors = ["Edmund Highcock"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ #require 'rcov/rcovtask'
36
+ #Rcov::RcovTask.new do |test|
37
+ ##test.libs << 'test'
38
+ ##test.pattern = 'test/**/test_*.rb'
39
+ ##test.verbose = true
40
+ ##test.rcov_opts << '--exclude "gems/*"'
41
+ ##end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "graphkit #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/graphkit.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "graphkit"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Edmund Highcock"]
12
+ s.date = "2012-10-05"
13
+ s.description = "A GraphKit is a device independent intelligent data container that allows the easy sharing, combining and plotting of graphic data representations. Easily created from data, they can be output in a variety of formats using packages such as gnuplot. "
14
+ s.email = "edmundhighcock@sourceforge.net"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "graphkit.gemspec",
29
+ "lib/graphkit.rb",
30
+ "lib/graphkit/csv.rb",
31
+ "lib/graphkit/gnuplot.rb",
32
+ "lib/graphkit/mm.rb",
33
+ "lib/graphkit/vtk_legacy_ruby.rb",
34
+ "test/helper.rb",
35
+ "test/test_graphkit.rb"
36
+ ]
37
+ s.homepage = "http://github.com/edmundhighcock/graphkit"
38
+ s.licenses = ["GPLv3"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = "1.8.24"
41
+ s.summary = "A GraphKit is a device independent intelligent data container for generating and plotting graphs."
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
51
+ else
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>, ["> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
60
+ s.add_dependency(%q<bundler>, ["> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,140 @@
1
+ require 'matrix'
2
+ # Methods for writing graphkits to csv (comma separated value) files
3
+
4
+
5
+
6
+ class GraphKit
7
+
8
+
9
+
10
+
11
+
12
+
13
+ def to_csv(options={})
14
+ check_integrity
15
+ ep 'to_csv'
16
+ stringio = options[:io] || StringIO.new
17
+ data.each do |dk|
18
+ dk.to_csv(io: stringio)
19
+ stringio << "\n\n"
20
+ end
21
+ return stringio.string unless options[:io]
22
+ end
23
+
24
+
25
+ class DataKit
26
+
27
+ class TensorArray
28
+ def initialize(arr)
29
+ @arr=arr
30
+ end
31
+ def [](*args)
32
+ args.reverse.inject(@arr) do |arr,idx|
33
+ arr[idx]
34
+ end
35
+ end
36
+ end
37
+ def to_csv(options={})
38
+ io = options[:io] || StringIO.new
39
+ axs = self.axes.values_at(*AXES).compact
40
+ #ep 'axs', axs
41
+ dl = data_length = axs[-1].shape.product
42
+ dat = axs.map{|ax| ax.data}
43
+ sh = shapes
44
+ cml_sh = sh.map do |sh|
45
+ cml = 1
46
+ sh.reverse.map{|dim| cml *= dim; cml}.reverse
47
+ end
48
+ dat = dat.map do |d|
49
+ d.kind_of?(Array) ? TensorArray.new(d) : d
50
+ end
51
+
52
+ if self.errors
53
+ raise "Errors can only be plotted for 1D or 2D data" unless ranks == [1] or ranks == [1,1]
54
+ edat = self.errors.values_at(:x, :xmin, :xmax, :y, :ymin, :ymax).compact
55
+ #ep 'edat', edat
56
+ end
57
+ case ranks
58
+ when [1], [1,1], [1,1,1], [1,1,1,1]
59
+ dl.times do |n|
60
+ dat.each{|d| io << d[n] << " "}
61
+ io << " " << edat.map{|e| e[n].to_s}.join(", ") if self.errors
62
+ io << "\n"
63
+ end
64
+ when [1,1,2]
65
+ sh[-1][0].times do |i|
66
+ sh[-1][1].times do |j|
67
+ next unless dat[2][i,j]
68
+ d = [dat[0][i], dat[1][j], dat[2][i,j]]
69
+ io << d[0] << ", " << d[1] << ", " << d[2] << "\n"
70
+ end
71
+ io << "\n" unless sh[-1][1] == 1
72
+ end
73
+ when [2,2,2]
74
+ sh[-1][0].times do |i|
75
+ sh[-1][1].times do |j|
76
+ next unless dat[2][i,j]
77
+ d = [dat[0][i,j], dat[1][i,j], dat[2][i,j]]
78
+ io << d[0] << ", " << d[1] << ", " << d[2] << "\n"
79
+ end
80
+ io << "\n" unless sh[-1][1] == 1
81
+ end
82
+ when [1,1,2,2]
83
+ sh[-1][0].times do |i|
84
+ sh[-1][1].times do |j|
85
+ next unless dat[3][i,j]
86
+ d = [dat[0][i], dat[1][j], dat[2][i,j], dat[3][i,j]]
87
+ io << d[0] << ", " << d[1] << ", " << d[2] << ", " << d[3] << "\n"
88
+ end
89
+ io << "\n" unless sh[-1][1] == 1
90
+ end
91
+ when [1,1,1,3]
92
+ sh[-1][0].times do |i|
93
+ sh[-1][1].times do |j|
94
+ sh[-1][2].times do |k|
95
+ next unless dat[3][i,j,k]
96
+
97
+ d = [dat[0][i], dat[1][j], dat[2][k], dat[3][i,j,k]]
98
+ io << d[0] << ", " << d[1] << ", " << d[2] << ", " << d[3] << "\n"
99
+ end
100
+ io << "\n" unless sh[-1][2] == 1
101
+ end
102
+ io << "\n" unless sh[-1][1] == 1
103
+ end
104
+ when [2,2,2,2]
105
+ sh[-1][0].times do |i|
106
+ sh[-1][1].times do |j|
107
+ next unless dat[3][i,j]
108
+ d = [dat[0][i,j], dat[1][i,j], dat[2][i,j], dat[3][i,j]]
109
+ d.each{|dt| io << dt << " "}
110
+ io << "\n"
111
+ end
112
+ io << "\n" unless sh[-1][1] == 1
113
+ end
114
+ when [3,3,3,3]
115
+ #pp dat
116
+ #pp dat
117
+ #pp sh
118
+ sh[-1][0].times do |i|
119
+ sh[-1][1].times do |j|
120
+ sh[-1][2].times do |k|
121
+ next unless dat[3][i,j,k]
122
+ #p [i,j,k]
123
+
124
+ #d = [dat[0][i,j,k], dat[1][i,j,k], dat[2][i,j,k], dat[3][i,j,k]]
125
+ io << "#{dat[0][i,j,k]},#{dat[1][i,j,k]},#{dat[2][i,j,k]},#{dat[3][i,j,k]}\n"
126
+ #d.each{|dt| io << dt << " "}
127
+ #io << "\n"
128
+ end
129
+ io << "\n" unless sh[-1][2] == 1
130
+ end
131
+ io << "\n" unless sh[-1][1] == 1
132
+ end
133
+ end
134
+
135
+ return stringio.string unless options[:io]
136
+ end
137
+ end
138
+
139
+ end
140
+