tokfile 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/tokfile/ogyropsi.rb +165 -160
  4. data/tokfile.gemspec +4 -4
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76b4c392ebbae8dcc8bd73c3e74351792a4e37fa
4
- data.tar.gz: 5b59d16ba8f75f18d06f69a96f5caa9e8b6eec1c
3
+ metadata.gz: 062d056c77137d0588181f62d8d782a0e919703e
4
+ data.tar.gz: 0669f4b12c8d7413854240f290d481a319b7670b
5
5
  SHA512:
6
- metadata.gz: 1a4c808bc0555e2c38615104dc74b7c91fd588dab862bbb06ad728402b964e081ca0c98cdc1c72e03bd938d1146b0eb789c2828621d08b19dded6bd1ad7a4376
7
- data.tar.gz: 2b857ad75092b4a9c736eaa5449d46c94b7244fd32401e783a082bc6d68295830000f1c8f2d32ae818ab213c9b749cfe102b24dffca88e5bbac2be8bb2866a9f
6
+ metadata.gz: 40f5a4581ae863de2363f102b23abf4eda8810e31e8039fb6137ffd47256cfa10bdccca9a8c3867d0cbb41b81f307de842d017e948a49534c91a966e922a45b1
7
+ data.tar.gz: f33976293ca398d92e7c6bc86ebc0efe3d8f6bda2b2c1e6252e3867c297749cc17d5681f8d38168710e28c26d08602bdeed3fc16d2192f2e65261e0073426502
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -2,61 +2,65 @@
2
2
  # A class for interacting with files of format ogyropsi,
3
3
  # an input format for GENE and GYRO that is output by CHEASE
4
4
  #
5
- class TokFile::Ogyropsi
6
- # Create the object. Read data from filename if it exists.
7
- # Otherwise do nothing.
8
- def initialize(filename)
9
- @filename = filename
10
- return unless FileTest.exist? @filename
11
- @lines = File.read(filename).split("\n")
12
- #for i in 1...@lines.size
13
- vb2 = TokFile.verbosity > 1
14
- if vb2
15
- eputs
16
- eputs "Reading data from ogyropsi filename #{filename}."
17
- eputs
18
- end
19
- i = 0
20
- sz = @lines.size
21
- total_size = 0
22
- while i < sz
23
-
24
- var = @lines[i].gsub(/\s/, '').downcase.to_sym
25
- var = :pr if var == :p
26
- j=i+1
27
- j+=1 while j < sz and not @lines[j] =~ /^\s*[A-Za-z]/
28
- val = @lines.slice(i+1...j).join(' ').sub(/\A\s+/, '').sub(/\s+\Z/, '').split(/\s+/).map{|s| eval(s)}
29
- vsz = val.size
30
- total_size += vsz
31
- if vb2
32
- Terminal.erewind(1)
33
- eputs "#{var}(#{vsz})#{Terminal::CLEAR_LINE}" if vb2
34
- end
35
- self.class.attr_accessor var
36
- case val.size
37
- when 1
38
- set(var, val[0])
39
- when @npsi, @nchi
40
- set(var, val.to_gslv)
41
- when @npsi*@nchi
42
- set(var, GSL::Matrix.alloc(*val.pieces(@nchi)))
43
- else
44
- raise "Unknown size for #{var}"
45
- end
46
- i=j
47
- end
48
-
49
- if vb2
50
- Terminal.erewind(1)
51
- eputs "Read total data size of #{total_size.to_f * 8.0/1.0e6} MB"
52
- end
53
- if TokFile.verbosity > 0
54
- eputs <<EOF
5
+ class TokFile
6
+ def self.verbosity
7
+ 0
8
+ end
9
+ class Ogyropsi
10
+ # Create the object. Read data from filename if it exists.
11
+ # Otherwise do nothing.
12
+ def initialize(filename)
13
+ @filename = filename
14
+ return unless FileTest.exist? @filename
15
+ @lines = File.read(filename).split("\n")
16
+ #for i in 1...@lines.size
17
+ vb2 = TokFile.verbosity > 1
18
+ if vb2
19
+ eputs
20
+ eputs "Reading data from ogyropsi filename #{filename}."
21
+ eputs
22
+ end
23
+ i = 0
24
+ sz = @lines.size
25
+ total_size = 0
26
+ while i < sz
27
+
28
+ var = @lines[i].gsub(/\s/, '').downcase.to_sym
29
+ var = :pr if var == :p
30
+ j=i+1
31
+ j+=1 while j < sz and not @lines[j] =~ /^\s*[A-Za-z]/
32
+ val = @lines.slice(i+1...j).join(' ').sub(/\A\s+/, '').sub(/\s+\Z/, '').split(/\s+/).map{|s| eval(s)}
33
+ vsz = val.size
34
+ total_size += vsz
35
+ if vb2
36
+ Terminal.erewind(1)
37
+ eputs "#{var}(#{vsz})#{Terminal::CLEAR_LINE}" if vb2
38
+ end
39
+ self.class.attr_accessor var
40
+ case val.size
41
+ when 1
42
+ set(var, val[0])
43
+ when @npsi, @nchi
44
+ set(var, val.to_gslv)
45
+ when @npsi*@nchi
46
+ set(var, GSL::Matrix.alloc(*val.pieces(@nchi)))
47
+ else
48
+ raise "Unknown size for #{var}"
49
+ end
50
+ i=j
51
+ end
52
+
53
+ if vb2
54
+ Terminal.erewind(1)
55
+ eputs "Read total data size of #{total_size.to_f * 8.0/1.0e6} MB"
56
+ end
57
+ if TokFile.verbosity > 0
58
+ eputs <<EOF
55
59
  -----------------------------------------
56
60
  Tokfile
57
61
  -----------------------------------------
58
62
  Successfully read an ogyropsi file called
59
- #{filename}
63
+ #{filename}
60
64
  with the following parameters:
61
65
 
62
66
  npsi = #@npsi
@@ -64,114 +68,114 @@ nchi = #@nchi
64
68
  -----------------------------------------
65
69
  EOF
66
70
 
67
- end
68
-
69
- # A GraphKit::MultiKit containing summary information about the
70
- # contents of the file.
71
- def summary_graphkit
72
- multkit = GraphKit::MultiKit.new([:pr, :dpdpsi, :f, :fdfdpsi, :q, :shear, :ti, :te].map{|name|
73
- kit = GraphKit.quick_create([@psi, send(name)])
74
- kit.title = name.to_s
75
- kit.ylabel = nil
76
- kit.xlabel = 'psi'
77
- kit
78
- })
79
- multkit.gp.multiplot = "layout 3,3"
80
- kit = @npsi.times.map{|i| GraphKit.quick_create([@r.col(i), @z.col(i)])}.sum
81
- kit.data.each{|dk| dk.gp.with = 'l'}
82
- multkit.push kit
83
- multkit
84
- end
85
-
86
- # Read selected data from the given file object,
87
- # overwriting current values where present.
88
- def read_data(file_object, data_group, time)
89
- # Convert to an object of class Tokfile::Ogyropsi if necessary
90
- file_object = file_object.internal_representation(time).to_ogyropsi unless file_object.kind_of? TokFile::Ogyropsi
91
- VARIABLES.each do |var|
92
- next unless in_data_group(data_group, var)
93
- varname = instance_varname(var)
94
- if data_group=="all"
95
- set(varname, file_object.send(varname)) if file_object.send(varname)
96
- else
97
- if file_object.send(varname)
98
- input = file_object.send(varname)
99
- case input
100
- when Integer, Float
101
- set(varname, input)
102
- when GSL::Vector
103
- case input.size
104
- when file_object.npsi
105
- #interp = GSL::Interp.alloc('cspline', file_object.npsi)
106
- #ep [file_object.psi.max, file_object.psi.min, @psi.max, @psi.min, 'end']
107
- #ep input
108
- #set(varname, interp.eval(file_object.psi, input, @psi))
109
- interp = GSL::ScatterInterp.alloc(:linear, [file_object.psi, input], false)
110
- set(varname, @psi.collect{|ps| interp.eval(ps)})
111
- end
112
- end
113
- end
114
- end
115
-
116
- end
117
-
118
- end
119
-
120
- def instance_varname(var)
121
- varname = var.downcase.to_sym
122
- varname = :pr if varname == :p
123
- varname
124
- end
125
-
126
- def in_data_group(data_group, var)
127
- return true if data_group == "all"
128
- case var
129
- when /D?[NT][IE](DPSI)?/i, /ZEFF/i, /^p$|dpdpsi/i
130
- data_group == 'profiles'
131
- else
132
- data_group == 'geometry'
133
- end
134
- end
135
-
136
- # Write contents to @filename
137
- def write
138
- File.open(@filename, 'w') do |file|
139
- VARIABLES.each do |var|
140
- varname = instance_varname(var)
141
- file.puts var
142
- val = send(varname)
143
- case val
144
- when Integer, Float
145
- file.puts " #{val}"
146
- when GSL::Vector
147
- for i in 0...val.size
148
- file.print(sprintf(" %16.9E", val[i]))
149
- file.print("\n") if (i+1)%5 == 0
150
- end
151
- file.print("\n") unless val.size%5==0
152
- when GSL::Matrix
153
- # Note that fortran and hence this file is column major
154
- k = 0
155
- for i in 0...val.shape[0]
156
- for j in 0...val.shape[1]
157
- file.print(sprintf(" %16.9E", val[i,j]))
158
- file.print("\n") if (k+=1)%5 == 0
159
- end
160
- end
161
- file.print("\n") unless k%5==0
162
- end
163
- end
164
- end
165
- end
166
-
167
-
168
-
169
-
170
-
171
-
172
- end
173
-
174
- VARIABLES = %w{
71
+ end
72
+ end
73
+
74
+ # A GraphKit::MultiKit containing summary information about the
75
+ # contents of the file.
76
+ def summary_graphkit
77
+ multkit = GraphKit::MultiKit.new([:pr, :dpdpsi, :f, :fdfdpsi, :q, :shear, :ti, :te].map{|name|
78
+ kit = GraphKit.quick_create([@psi, send(name)])
79
+ kit.title = name.to_s
80
+ kit.ylabel = nil
81
+ kit.xlabel = 'psi'
82
+ kit
83
+ })
84
+ multkit.gp.multiplot = "layout 3,3"
85
+ kit = @npsi.times.map{|i| GraphKit.quick_create([@r.col(i), @z.col(i)])}.sum
86
+ kit.data.each{|dk| dk.gp.with = 'l'}
87
+ multkit.push kit
88
+ multkit
89
+ end
90
+
91
+ # Read selected data from the given file object,
92
+ # overwriting current values where present.
93
+ def read_data(file_object, data_group, time)
94
+ # Convert to an object of class Tokfile::Ogyropsi if necessary
95
+ file_object = file_object.internal_representation(time).to_ogyropsi unless file_object.kind_of? TokFile::Ogyropsi
96
+ VARIABLES.each do |var|
97
+ next unless in_data_group(data_group, var)
98
+ varname = instance_varname(var)
99
+ if data_group=="all"
100
+ set(varname, file_object.send(varname)) if file_object.send(varname)
101
+ else
102
+ if file_object.send(varname)
103
+ input = file_object.send(varname)
104
+ case input
105
+ when Integer, Float
106
+ set(varname, input)
107
+ when GSL::Vector
108
+ case input.size
109
+ when file_object.npsi
110
+ #interp = GSL::Interp.alloc('cspline', file_object.npsi)
111
+ #ep [file_object.psi.max, file_object.psi.min, @psi.max, @psi.min, 'end']
112
+ #ep input
113
+ #set(varname, interp.eval(file_object.psi, input, @psi))
114
+ interp = GSL::ScatterInterp.alloc(:linear, [file_object.psi, input], false)
115
+ set(varname, @psi.collect{|ps| interp.eval(ps)})
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+ def instance_varname(var)
126
+ varname = var.downcase.to_sym
127
+ varname = :pr if varname == :p
128
+ varname
129
+ end
130
+
131
+ def in_data_group(data_group, var)
132
+ return true if data_group == "all"
133
+ case var
134
+ when /D?[NT][IE](DPSI)?/i, /ZEFF/i, /^p$|dpdpsi/i
135
+ data_group == 'profiles'
136
+ else
137
+ data_group == 'geometry'
138
+ end
139
+ end
140
+
141
+ # Write contents to @filename
142
+ def write
143
+ File.open(@filename, 'w') do |file|
144
+ VARIABLES.each do |var|
145
+ varname = instance_varname(var)
146
+ file.puts var
147
+ val = send(varname)
148
+ case val
149
+ when Integer, Float
150
+ file.puts " #{val}"
151
+ when GSL::Vector
152
+ for i in 0...val.size
153
+ file.print(sprintf(" %16.9E", val[i]))
154
+ file.print("\n") if (i+1)%5 == 0
155
+ end
156
+ file.print("\n") unless val.size%5==0
157
+ when GSL::Matrix
158
+ # Note that fortran and hence this file is column major
159
+ k = 0
160
+ for i in 0...val.shape[0]
161
+ for j in 0...val.shape[1]
162
+ file.print(sprintf(" %16.9E", val[i,j]))
163
+ file.print("\n") if (k+=1)%5 == 0
164
+ end
165
+ end
166
+ file.print("\n") unless k%5==0
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+ VARIABLES = %w{
175
179
 
176
180
  NPSI
177
181
  NCHI
@@ -226,5 +230,6 @@ Jacobian
226
230
  R
227
231
  Z
228
232
 
229
- }
233
+ }
234
+ end
230
235
  end
data/tokfile.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: tokfile 0.0.3 ruby lib
5
+ # stub: tokfile 0.0.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tokfile"
9
- s.version = "0.0.3"
9
+ s.version = "0.0.4"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Edmund Highcock"]
14
- s.date = "2015-04-16"
14
+ s.date = "2015-08-09"
15
15
  s.description = "A tool for working with common tokamak file formats from tools like EFIT, CHEASE, TRANSP, CRONOS etc. Contains commands for plotting a summary of content, manipulating the data within them and most importantly, converting one format to another."
16
16
  s.email = "edmundhighcock@users.sourceforge.net"
17
17
  s.executables = ["tokfile"]
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  ]
44
44
  s.homepage = "http://github.com/edmundhighcock/tokfile"
45
45
  s.licenses = ["GPLv3"]
46
- s.rubygems_version = "2.2.2"
46
+ s.rubygems_version = "2.4.8"
47
47
  s.summary = "A set of tools for testing and manipulating and converting files associated with tokamaks."
48
48
 
49
49
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edmund Highcock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderunner
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.2.2
177
+ rubygems_version: 2.4.8
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: A set of tools for testing and manipulating and converting files associated