1
# stack.rb: the data stack
2
# copyright (c) 2009 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details (in the COPYING file).
14
require 'ctioga2/utils'
15
require 'ctioga2/data/datacolumn'
16
require 'ctioga2/data/backends/backends'
17
require 'ctioga2/data/backends/factory'
19
# This module contains all the classes used by ctioga
22
Version::register_svn_info('$Revision: 194 $', '$Date: 2010-11-22 10:26:54 +0100 (Mon, 22 Nov 2010) $')
27
# A series of commands that can be used as "filters", as they act
28
# upon the last Dataset pushed unto the stack.
32
CmdGroup.new('filter', "Filters",
33
"The commands in this group act upon the last
34
dataset pushed unto the data stack: they can be viewed as filters.",
38
Cmd.new("sort-last", nil, "--sort-last",
39
[], {}) do |plotmaker, opts|
40
plotmaker.data_stack.last.sort!
43
SortOperation.describe("Sorts the last dataset according to X values",
45
Sorts the last dataset pushed unto the stack according to X values. Can be
48
See also {command: sort}.
52
Cmd.new("sort", nil, "--sort",
53
[], {}) do |plotmaker, opts|
54
plotmaker.data_stack.add_to_dataset_hook('sort-last()')
57
SortFilter.describe("Systematically sort subsequent datasets",
59
Install the {command: sort-last} command as a dataset hook (see {command:
60
dataset-hook}): all subsequent datasets will be sorted according to
65
Cmd.new("trim-last", nil, "--trim-last",
66
[CmdArg.new('integer')], {}) do |plotmaker, number, opts|
67
plotmaker.data_stack.last.trim!(number)
70
TrimOperation.describe("Only keeps every n points in the last dataset",
72
Only keeps one every ? data point on the last dataset pushed unto the
73
data stack. Useful when data have too many points to avoid creating
74
heavy PDF files that take ages to display with no additional benefits.
76
This operation is very crude and does not average data.
78
See also {command: trim}.
82
Cmd.new("trim", nil, "--trim",
83
[CmdArg.new('integer')], {}) do |plotmaker, number, opts|
84
## @todo There should be a way to add commands in a type-safe
85
## way, without having to convert to string first.
86
plotmaker.data_stack.add_to_dataset_hook("trim-last(#{number})")
89
TrimFilter.describe("Systematically trim subsequent datasets",
91
Install the {command: trim-last} command as a dataset hook (see {command:
92
dataset-hook}): all subsequent datasets will be trimmed to keep only
98
Cmd.new("cherry-pick-last", nil, "--cherry-pick-last",
99
[CmdArg.new('text')], {}) do |plotmaker, formula|
100
plotmaker.data_stack.last.select_formula!(formula)
103
CherryPickOperation.describe("Removes data from the last dataset for which the formula is false",
106
Removes the data from the last dataset in the data stack for which the
107
formula returns false.
109
See also the {command: cherry-pick} command to apply the selection to
112
You might find it much easier to use the /where option of the
113
{command: plot} or {command: load} commands.
117
Cmd.new("cherry-pick", nil, "--cherry-pick",
118
[CmdArg.new('text')], {}) do |plotmaker, formula|
119
plotmaker.data_stack.add_to_dataset_hook("cherry-pick-last(#{formula})")
122
CherryPickFilter.describe("Systematicallly remove data for which the formula is false",
124
Install the {command: cherry-pick-last} command as a dataset hook (see
125
{command: dataset-hook}): all points for which the formula returns
126
false for subsequent datasets will be removed.
129
AverageDupOperation =
130
Cmd.new("avg-dup-last", nil, "--avg-dup-last",
131
[], {}) do |plotmaker|
132
plotmaker.data_stack.last.average_duplicates!
135
AverageDupOperation.describe("Average successive elements with identical X values",
137
Averages successive points with identical X values. This algorithm is
138
naive with respect to the min/max values and averages them just as
139
well, whereas one might expect something more clever.
141
To average over identical X values when they are not successive in the
142
dataset, you might want to hand it over to {command: sort-last} first.
147
Cmd.new("avg-dup", nil, "--avg-dup",
148
[], {}) do |plotmaker, formula|
149
plotmaker.data_stack.add_to_dataset_hook("avg-dup-last()")
152
AverageDupFilter.describe("Systematicallly average successive elements with identical X values",
154
Install the {command: avg-dup-last} command as a dataset hook (see
155
{command: dataset-hook}): all datasets acquired after this is on will
156
be averaged if they have identical successive values of X.
161
Cmd.new("smooth-last", nil, "--smooth-last",
162
[CmdArg.new('integer')], {}) do |plotmaker, number|
163
plotmaker.data_stack.last.naive_smooth!(number)
166
SmoothOperation.describe("Smooths data using a gaussian filter",
168
Smooth the data using a simple (naive even) gaussian filter. Good for
169
producing 'lines to guide the eye'