ctioga2 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +11 -0
- data/lib/ctioga2/commands/arguments.rb +1 -1
- data/lib/ctioga2/commands/commands.rb +1 -1
- data/lib/ctioga2/commands/doc/doc.rb +1 -1
- data/lib/ctioga2/commands/doc/documentation-commands.rb +1 -1
- data/lib/ctioga2/commands/doc/help.rb +1 -1
- data/lib/ctioga2/commands/doc/html.rb +1 -1
- data/lib/ctioga2/commands/doc/introspection.rb +1 -1
- data/lib/ctioga2/commands/doc/man.rb +1 -1
- data/lib/ctioga2/commands/doc/markup.rb +1 -1
- data/lib/ctioga2/commands/doc/wordwrap.rb +1 -1
- data/lib/ctioga2/commands/general-commands.rb +1 -1
- data/lib/ctioga2/commands/general-types.rb +1 -1
- data/lib/ctioga2/commands/groups.rb +1 -1
- data/lib/ctioga2/commands/interpreter.rb +8 -2
- data/lib/ctioga2/commands/parsers/command-line.rb +1 -1
- data/lib/ctioga2/commands/parsers/file.rb +4 -1
- data/lib/ctioga2/commands/strings.rb +1 -1
- data/lib/ctioga2/commands/type.rb +1 -1
- data/lib/ctioga2/commands/variables.rb +6 -6
- data/lib/ctioga2/data/backends/backend.rb +1 -1
- data/lib/ctioga2/data/backends/backends.rb +3 -2
- data/lib/ctioga2/data/backends/backends/direct.rb +72 -0
- data/lib/ctioga2/data/backends/backends/gnuplot.rb +1 -1
- data/lib/ctioga2/data/backends/backends/math.rb +1 -1
- data/lib/ctioga2/data/backends/backends/text.rb +8 -14
- data/lib/ctioga2/data/backends/description.rb +9 -5
- data/lib/ctioga2/data/backends/factory.rb +1 -1
- data/lib/ctioga2/data/backends/parameter.rb +1 -1
- data/lib/ctioga2/data/datacolumn.rb +1 -1
- data/lib/ctioga2/data/dataset.rb +50 -4
- data/lib/ctioga2/data/filters.rb +1 -1
- data/lib/ctioga2/data/indexed-dtable.rb +1 -1
- data/lib/ctioga2/data/point.rb +1 -1
- data/lib/ctioga2/data/stack.rb +151 -25
- data/lib/ctioga2/git-fools-svn.rb +7 -0
- data/lib/ctioga2/graphics/coordinates.rb +1 -1
- data/lib/ctioga2/graphics/elements.rb +1 -1
- data/lib/ctioga2/graphics/elements/containers.rb +1 -1
- data/lib/ctioga2/graphics/elements/contour.rb +5 -2
- data/lib/ctioga2/graphics/elements/curve2d.rb +1 -1
- data/lib/ctioga2/graphics/elements/element.rb +1 -1
- data/lib/ctioga2/graphics/elements/gradient-region.rb +1 -1
- data/lib/ctioga2/graphics/elements/parametric2d.rb +1 -2
- data/lib/ctioga2/graphics/elements/primitive.rb +1 -1
- data/lib/ctioga2/graphics/elements/redirecting-container.rb~ +123 -0
- data/lib/ctioga2/graphics/elements/region.rb +1 -1
- data/lib/ctioga2/graphics/elements/subplot.rb +1 -1
- data/lib/ctioga2/graphics/elements/tangent.rb +1 -1
- data/lib/ctioga2/graphics/elements/xyz-map.rb +1 -1
- data/lib/ctioga2/graphics/generator.rb +21 -4
- data/lib/ctioga2/graphics/legends.rb +1 -1
- data/lib/ctioga2/graphics/legends/area.rb +1 -1
- data/lib/ctioga2/graphics/legends/items.rb +1 -1
- data/lib/ctioga2/graphics/legends/provider.rb +1 -1
- data/lib/ctioga2/graphics/legends/storage.rb +1 -1
- data/lib/ctioga2/graphics/root.rb +1 -1
- data/lib/ctioga2/graphics/styles/axes.rb +2 -1
- data/lib/ctioga2/graphics/styles/background.rb +1 -1
- data/lib/ctioga2/graphics/styles/base.rb +1 -1
- data/lib/ctioga2/graphics/styles/carrays.rb +1 -1
- data/lib/ctioga2/graphics/styles/colormap.rb +1 -1
- data/lib/ctioga2/graphics/styles/curve.rb +1 -1
- data/lib/ctioga2/graphics/styles/drawable.rb +1 -1
- data/lib/ctioga2/graphics/styles/errorbar.rb +1 -1
- data/lib/ctioga2/graphics/styles/factory.rb +1 -1
- data/lib/ctioga2/graphics/styles/gradients.rb +1 -1
- data/lib/ctioga2/graphics/styles/legend.rb +1 -1
- data/lib/ctioga2/graphics/styles/location.rb +1 -1
- data/lib/ctioga2/graphics/styles/plot.rb +10 -1
- data/lib/ctioga2/graphics/styles/sets.rb +1 -1
- data/lib/ctioga2/graphics/styles/texts.rb +1 -1
- data/lib/ctioga2/graphics/subplot-commands.rb +1 -1
- data/lib/ctioga2/graphics/types.rb +1 -1
- data/lib/ctioga2/graphics/types/bijection.rb +1 -1
- data/lib/ctioga2/graphics/types/boundaries.rb +1 -1
- data/lib/ctioga2/graphics/types/boxes.rb +1 -1
- data/lib/ctioga2/graphics/types/dimensions.rb +1 -1
- data/lib/ctioga2/graphics/types/grid.rb +1 -1
- data/lib/ctioga2/graphics/types/location.rb +1 -1
- data/lib/ctioga2/graphics/types/point.rb +1 -1
- data/lib/ctioga2/log.rb +4 -1
- data/lib/ctioga2/metabuilder/type.rb +1 -1
- data/lib/ctioga2/metabuilder/types/coordinates.rb +1 -1
- data/lib/ctioga2/metabuilder/types/data.rb +1 -1
- data/lib/ctioga2/metabuilder/types/dates.rb +1 -1
- data/lib/ctioga2/metabuilder/types/generic.rb~ +225 -0
- data/lib/ctioga2/metabuilder/types/lists.rb +1 -1
- data/lib/ctioga2/metabuilder/types/numbers.rb +1 -1
- data/lib/ctioga2/metabuilder/types/strings.rb +1 -1
- data/lib/ctioga2/metabuilder/types/styles.rb +1 -1
- data/lib/ctioga2/plotmaker.rb +12 -7
- data/lib/ctioga2/postprocess.rb +1 -1
- data/lib/ctioga2/utils.rb +27 -3
- metadata +45 -56
@@ -17,7 +17,7 @@ require 'ctioga2/utils'
|
|
17
17
|
# This module contains all the classes used by ctioga
|
18
18
|
module CTioga2
|
19
19
|
|
20
|
-
Version::register_svn_info('$Revision
|
20
|
+
Version::register_svn_info('$Revision$', '$Date$')
|
21
21
|
|
22
22
|
module Data
|
23
23
|
|
data/lib/ctioga2/data/dataset.rb
CHANGED
@@ -12,12 +12,13 @@
|
|
12
12
|
# GNU General Public License for more details (in the COPYING file).
|
13
13
|
|
14
14
|
require 'ctioga2/utils'
|
15
|
+
require 'ctioga2/log'
|
15
16
|
require 'ctioga2/data/datacolumn'
|
16
17
|
require 'ctioga2/data/indexed-dtable'
|
17
18
|
|
18
19
|
module CTioga2
|
19
20
|
|
20
|
-
Version::register_svn_info('$Revision
|
21
|
+
Version::register_svn_info('$Revision$', '$Date$')
|
21
22
|
|
22
23
|
|
23
24
|
# \todo now, port the backend infrastructure...
|
@@ -43,6 +44,8 @@ module CTioga2
|
|
43
44
|
# legend (like for the --auto-legend option of ctioga).
|
44
45
|
attr_accessor :name
|
45
46
|
|
47
|
+
include Log
|
48
|
+
|
46
49
|
# Creates a new Dataset object with the given data columns
|
47
50
|
# (Dvector or DataColumn). #x is the first one
|
48
51
|
def initialize(name, columns)
|
@@ -298,6 +301,43 @@ module CTioga2
|
|
298
301
|
|
299
302
|
end
|
300
303
|
|
304
|
+
# Applies formulas to values. Formulas are like text-backend
|
305
|
+
# specification: ":"-separated specs of the target
|
306
|
+
def apply_formulas(formula)
|
307
|
+
columns = []
|
308
|
+
columns << Dobjects::Dvector.new(@x.size) do |i|
|
309
|
+
i
|
310
|
+
end
|
311
|
+
columns << @x.values
|
312
|
+
for y in @ys
|
313
|
+
columns << y.values
|
314
|
+
end
|
315
|
+
|
316
|
+
# Names:
|
317
|
+
heads = {
|
318
|
+
'x' => 1,
|
319
|
+
'y' => 2,
|
320
|
+
'z' => 3,
|
321
|
+
}
|
322
|
+
i = 1
|
323
|
+
for f in @ys
|
324
|
+
heads["y#{i}"] = i+1
|
325
|
+
i += 1
|
326
|
+
end
|
327
|
+
|
328
|
+
result = []
|
329
|
+
for f in formula.split(/:/) do
|
330
|
+
fm = Utils::parse_formula(f, nil, heads)
|
331
|
+
debug {
|
332
|
+
"Using formula #{fm} for column spec: #{f} (##{result.size})"
|
333
|
+
}
|
334
|
+
result << DataColumn.new(Dobjects::Dvector.
|
335
|
+
compute_formula(fm,
|
336
|
+
columns))
|
337
|
+
end
|
338
|
+
return Dataset.new(name + "_mod", result)
|
339
|
+
end
|
340
|
+
|
301
341
|
|
302
342
|
# Returns an IndexedDTable representing the XYZ
|
303
343
|
# data. Information about errors are not included.
|
@@ -349,14 +389,20 @@ module CTioga2
|
|
349
389
|
return @indexed_dtable
|
350
390
|
end
|
351
391
|
|
352
|
-
# Returns a x,y Function
|
392
|
+
# Returns a x,y Function
|
393
|
+
#
|
394
|
+
# @todo add algorithm
|
353
395
|
def make_contour(level)
|
354
396
|
dtable = indexed_table
|
355
397
|
x,y,gaps = *dtable.make_contour(level)
|
398
|
+
|
399
|
+
# We remove any gap corresponding to the element size,
|
400
|
+
# meaningless.
|
401
|
+
gaps -= [x.size]
|
356
402
|
n = 0.0/0.0
|
357
403
|
gaps.sort.reverse.each do |i|
|
358
|
-
x.insert(i
|
359
|
-
y.insert(i
|
404
|
+
x.insert(i,n)
|
405
|
+
y.insert(i,n)
|
360
406
|
end
|
361
407
|
return Dobjects::Function.new(x,y)
|
362
408
|
end
|
data/lib/ctioga2/data/filters.rb
CHANGED
@@ -19,7 +19,7 @@ require 'ctioga2/data/backends/factory'
|
|
19
19
|
# This module contains all the classes used by ctioga
|
20
20
|
module CTioga2
|
21
21
|
|
22
|
-
Version::register_svn_info('$Revision
|
22
|
+
Version::register_svn_info('$Revision$', '$Date$')
|
23
23
|
|
24
24
|
|
25
25
|
module Data
|
data/lib/ctioga2/data/point.rb
CHANGED
data/lib/ctioga2/data/stack.rb
CHANGED
@@ -25,7 +25,7 @@ require 'ctioga2/data/filters'
|
|
25
25
|
# This module contains all the classes used by ctioga
|
26
26
|
module CTioga2
|
27
27
|
|
28
|
-
Version::register_svn_info('$Revision
|
28
|
+
Version::register_svn_info('$Revision$', '$Date$')
|
29
29
|
|
30
30
|
|
31
31
|
module Data
|
@@ -80,8 +80,14 @@ module CTioga2
|
|
80
80
|
def get_datasets(set, options = {})
|
81
81
|
backend = @backend_factory.current
|
82
82
|
sets = backend.expand_sets(set)
|
83
|
-
datasets =
|
84
|
-
|
83
|
+
datasets = []
|
84
|
+
for s in sets
|
85
|
+
begin
|
86
|
+
datasets << backend.dataset(s)
|
87
|
+
rescue Exception => e
|
88
|
+
error { "Could not load dataset #{s} -- #{e}" }
|
89
|
+
debug { "#{e.backtrace.join("\n")}" }
|
90
|
+
end
|
85
91
|
end
|
86
92
|
add_datasets(datasets, options)
|
87
93
|
return datasets
|
@@ -157,6 +163,25 @@ module CTioga2
|
|
157
163
|
end
|
158
164
|
end
|
159
165
|
|
166
|
+
# Returns a list of datasets, either a named dataset, or the
|
167
|
+
# last datasets from the stack
|
168
|
+
def latest_datasets(opts)
|
169
|
+
if opts['which']
|
170
|
+
if opts['number']
|
171
|
+
warn { "Cannot use both which and number" }
|
172
|
+
end
|
173
|
+
datasets = [ specified_dataset(opts) ]
|
174
|
+
else
|
175
|
+
nb = opts['number'] || 2
|
176
|
+
if stack.stack.size < nb
|
177
|
+
raise "Not enough datasets on the stack"
|
178
|
+
end
|
179
|
+
datasets = stack.stack[(- nb).. -2]
|
180
|
+
datasets.reverse!
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
|
160
185
|
# Appends a set of commands to the dataset hook
|
161
186
|
def add_to_dataset_hook(commands)
|
162
187
|
if @dataset_hook
|
@@ -176,25 +201,25 @@ module CTioga2
|
|
176
201
|
end
|
177
202
|
end
|
178
203
|
|
179
|
-
#
|
180
|
-
def concatenate_datasets(
|
204
|
+
# Add all the given datasets to the current one.
|
205
|
+
def concatenate_datasets(datasets, name = nil)
|
181
206
|
ds = @stack.pop
|
182
207
|
raise "Nothing on the stack" unless ds
|
183
|
-
|
184
|
-
|
185
|
-
raise "Not enough datasets on the stack" unless ds2
|
208
|
+
|
209
|
+
for ds2 in datasets
|
186
210
|
ds << ds2
|
187
211
|
end
|
188
212
|
@stack.push(ds)
|
213
|
+
# Name the dataset
|
214
|
+
@named_datasets[name] = ds if name
|
189
215
|
end
|
190
216
|
|
191
|
-
# Merges
|
217
|
+
# Merges one or more datasets into the last one.
|
192
218
|
#
|
193
|
-
#
|
194
|
-
def
|
219
|
+
# The last dataset of the stack is overwritten.
|
220
|
+
def merge_datasets_into_last(datasets, columns = [0], precision = nil)
|
195
221
|
ds = @stack.pop
|
196
222
|
raise "Nothing on the stack" unless ds
|
197
|
-
datasets = @stack[-1..-(n-1)]
|
198
223
|
ds.merge_datasets_in(datasets, columns, precision)
|
199
224
|
@stack.push(ds)
|
200
225
|
end
|
@@ -204,6 +229,32 @@ module CTioga2
|
|
204
229
|
return @stack.last
|
205
230
|
end
|
206
231
|
|
232
|
+
# Displays the contents of the stack
|
233
|
+
def show
|
234
|
+
STDERR.puts "Stack contents"
|
235
|
+
i = 0
|
236
|
+
# Swap the named dataset stuff
|
237
|
+
## @todo Maybe a hash pair should be maintained in permanence ?
|
238
|
+
rev = {}
|
239
|
+
for k,v in @named_datasets
|
240
|
+
rev[v] = k
|
241
|
+
end
|
242
|
+
|
243
|
+
for ds in @stack
|
244
|
+
name = rev[ds]
|
245
|
+
if name
|
246
|
+
name = "(named: '#{name}')"
|
247
|
+
else
|
248
|
+
name = ""
|
249
|
+
end
|
250
|
+
|
251
|
+
pref = sprintf("#%-2d %-3d:", i, - @stack.size + i)
|
252
|
+
|
253
|
+
STDERR.puts " * #{pref} #{ds.name} -- #{ds.ys.size + 1} columns #{name}"
|
254
|
+
i += 1
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
207
258
|
|
208
259
|
end
|
209
260
|
|
@@ -284,31 +335,82 @@ onto the stack, or the given stored dataset if the which option is given.
|
|
284
335
|
EOH
|
285
336
|
|
286
337
|
ConcatLastCommand =
|
287
|
-
Cmd.new("join-datasets",
|
288
|
-
[],
|
289
|
-
|
290
|
-
|
338
|
+
Cmd.new("join-datasets", "-j", "--join-datasets",
|
339
|
+
[],
|
340
|
+
{
|
341
|
+
'number' => CmdArg.new('integer'),
|
342
|
+
'which' => CmdArg.new('stored-dataset'),
|
343
|
+
'name' => CmdArg.new('text')
|
344
|
+
}) do |plotmaker, opts|
|
345
|
+
stack = plotmaker.data_stack
|
346
|
+
datasets = stack.latest_datasets(opts)
|
347
|
+
stack.concatenate_datasets(datasets, opts['name'])
|
291
348
|
end
|
292
349
|
|
293
350
|
ConcatLastCommand.describe("Concatenates the last datasets on the stack",
|
294
351
|
<<EOH, DataStackGroup)
|
295
352
|
Pops the last two (or number, if it is specified) datasets from the
|
296
353
|
stack, concatenates them (older last) and push them back onto the
|
297
|
-
stack.
|
354
|
+
stack. The name option can be used to give a name to the new dataset.
|
298
355
|
EOH
|
299
356
|
|
357
|
+
ApplyLastCommand =
|
358
|
+
Cmd.new("apply-formula", '', "--apply-formula",
|
359
|
+
[CmdArg.new('text')],
|
360
|
+
{
|
361
|
+
'which' => CmdArg.new('stored-dataset'),
|
362
|
+
'name' => CmdArg.new('text'),
|
363
|
+
}) do |plotmaker, formula, opts|
|
364
|
+
ds = plotmaker.data_stack.specified_dataset(opts)
|
365
|
+
newds = ds.apply_formulas(formula)
|
366
|
+
plotmaker.data_stack.add_datasets([newds], opts)
|
367
|
+
end
|
368
|
+
|
369
|
+
ApplyLastCommand.describe("Applies a formula to the last dataset",
|
370
|
+
<<EOH, DataStackGroup)
|
371
|
+
Applies a formula to the last dataset (or the named one)
|
372
|
+
EOH
|
300
373
|
|
374
|
+
ShowStackCommand =
|
375
|
+
Cmd.new("show-stack", nil, "--show-stack",
|
376
|
+
[],
|
377
|
+
{ }
|
378
|
+
) do |plotmaker, opts|
|
379
|
+
plotmaker.data_stack.show
|
380
|
+
end
|
381
|
+
|
382
|
+
ShowStackCommand.describe("Displays the content of the stack",
|
383
|
+
<<EOH, DataStackGroup)
|
384
|
+
Displays the current contents of the dataset stack.
|
385
|
+
|
386
|
+
Mostly used for debugging when operations like {cmd: merge-datasets}
|
387
|
+
or {cmd: join-datasets} don't work as expected.
|
388
|
+
EOH
|
389
|
+
|
390
|
+
|
391
|
+
## @todo Add column selection ?
|
301
392
|
MergeToLastCommand =
|
302
393
|
Cmd.new("merge-datasets", nil, "--merge-datasets",
|
303
|
-
[],
|
304
|
-
|
305
|
-
|
306
|
-
|
394
|
+
[],
|
395
|
+
{
|
396
|
+
'number' => CmdArg.new('integer'),
|
397
|
+
'which' => CmdArg.new('stored-dataset')
|
398
|
+
}
|
399
|
+
) do |plotmaker, opts|
|
400
|
+
stack = plotmaker.data_stack
|
401
|
+
datasets = stack.latest_datasets(opts)
|
402
|
+
plotmaker.data_stack.merge_datasets_into_last(datasets)
|
307
403
|
end
|
308
404
|
|
309
|
-
MergeToLastCommand.describe("
|
310
|
-
|
311
|
-
|
405
|
+
MergeToLastCommand.describe("Merge datasets based on X column",
|
406
|
+
<<EOH, DataStackGroup)
|
407
|
+
This commands merges data with matching X values from a dataset (by
|
408
|
+
default the one before the last) into the last one. Data points that
|
409
|
+
have no corresponding X value in the current dataset are simply
|
410
|
+
ignored.
|
411
|
+
|
412
|
+
This can be used to build 3D datasets for {cmd: xyz-map} or
|
413
|
+
{cmd: xy-parametric}.
|
312
414
|
EOH
|
313
415
|
|
314
416
|
XYReglinCommand =
|
@@ -325,7 +427,31 @@ EOH
|
|
325
427
|
|
326
428
|
XYReglinCommand.describe("....",
|
327
429
|
<<EOH, DataStackGroup)
|
328
|
-
|
430
|
+
...
|
431
|
+
|
432
|
+
This command will get documented some day.
|
433
|
+
EOH
|
434
|
+
|
435
|
+
|
436
|
+
ComputeContourCommand =
|
437
|
+
Cmd.new("compute-contour", nil, "--compute-contour",
|
438
|
+
[CmdArg.new("float")], {
|
439
|
+
'which' => CmdArg.new('stored-dataset')
|
440
|
+
}) do |plotmaker, level, opts|
|
441
|
+
stack = plotmaker.data_stack
|
442
|
+
ds = stack.specified_dataset(opts)
|
443
|
+
f = ds.make_contour(level)
|
444
|
+
newds = Dataset.new("Contour #{level}", [f.x, f.y])
|
445
|
+
stack.store_dataset(newds, true)
|
446
|
+
end
|
447
|
+
|
448
|
+
ComputeContourCommand.describe("computes the contour and push it to data stack",
|
449
|
+
<<EOH, DataStackGroup)
|
450
|
+
Computes the contour at the given level for the given dataset (or the
|
451
|
+
last on the stack if none is specified) and pushes it onto the data
|
452
|
+
stack.
|
453
|
+
|
454
|
+
You can further manipulate it as usual.
|
329
455
|
EOH
|
330
456
|
|
331
457
|
SetDatasetHookCommand =
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# contour.rb: contouring code for XYZ data
|
2
|
-
# copyright (c)
|
2
|
+
# copyright (c) 2010, 2011 by Vincent Fourmond
|
3
3
|
|
4
4
|
# This program is free software; you can redistribute it and/or modify
|
5
5
|
# it under the terms of the GNU General Public License as published by
|
@@ -17,7 +17,7 @@ require 'ctioga2/graphics/elements/primitive'
|
|
17
17
|
# This module contains all the classes used by ctioga
|
18
18
|
module CTioga2
|
19
19
|
|
20
|
-
Version::register_svn_info('$Revision
|
20
|
+
Version::register_svn_info('$Revision$', '$Date$')
|
21
21
|
|
22
22
|
module Graphics
|
23
23
|
|
@@ -36,6 +36,9 @@ module CTioga2
|
|
36
36
|
# $last_curve_style calls for a context for the primitive, ie
|
37
37
|
# which was the state of the dataset/curve stack at the moment
|
38
38
|
# when the primitive was drawn ?
|
39
|
+
#
|
40
|
+
# Worse, I already designed something better. I'll need to get
|
41
|
+
# that straight some day.
|
39
42
|
TiogaPrimitiveCall.
|
40
43
|
primitive("contour", "contour", [ 'level'],
|
41
44
|
ContoursOptions) do |t, level,options|
|