1
# dataset.rb : The implementation of data sets
2
# Copyright (C) 2006 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.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
require 'MetaBuilder/metabuilder'
27
# An abstract class representing a DataSet. You should consider using
28
# a subclass, DataSet2D or DataSet3D. A DataSet must be either 2D or 3D,
29
# and redefine #is_2D? and #is_3D? accordingly.
31
# As DataSets grow more complex, it is likely that it will be less and
32
# less easy to tweak directly the data inside. So, please, do use the
33
# accessors and tweakers provided in the interface, else you'll expose
34
# yourself to some intensive breakages when I get more clever.
35
# Meanwhile, the apply(meth,where,*rest) method should be used to keep
36
# everything in sync when you apply a method to a Dvector.
41
# The #creation_context attribute is a hash containing a :backend key
42
# indicating the name of the Backend created and filled with the
43
# contents of the backend's DescriptionInclude#save_state function.
44
attr_accessor :creation_context
46
# The data of the set.
49
# Errors on data, if applicable.
50
# For 2D data, this will just be a hash with the following Dvectors:
51
# :xmin, :xmax for errors on the x values + :x, to make sure
52
# we keep it up-to-date.
53
# :ymin, :ymax for errors on y + :y.
55
# Both ?min and ?max have to be specified if any output should be
59
# The metadata given when the set was created.
60
attr_accessor :meta_data
70
# A few forwarded stuff to make the DataSet behave exactly like
71
# Function and it's future 3D counterpart
73
def_delegators :@data, :x, :y, :z
75
def initialize(backend, data, errors = {}, meta_data = {})
76
@creation_context = backend.save_state
77
@creation_context[:backend] = backend.description.name
80
@meta_data = meta_data
83
# Apply a Dvector operation to the given dimension, including
84
# everything that could be left somewhere in the error bars.
85
# It should be very powerful in the end.
87
# Beautiful, isn't it ??
88
def apply(what, where, *rest)
89
self.send(where).send(what, *rest)
90
for key,values in @errors
91
if key.to_s =~ /^#{where}/ # Very much overkill, but, well...
92
values.send(what,*rest)
97
# Does a redirection to the underlying @data if that makes sense.
98
def method_missing(sym, *args, &b)
99
if @data.respond_to?(sym)
100
@data.send(sym, *args, &b)
101
elsif x.respond_to?(sym) # We are trying to apply something
102
# like data.mul!(:x, factor)
103
apply(sym,args.shift,*args,&b)
111
# A 2-dimensionnal DataSet
112
class DataSet2D < DataSet
119
# A 3-dimensionnal DataSet
120
class DataSet3D < DataSet