Class: SciYAG::Backends::DataSet
- Inherits:
-
Object
- Object
- SciYAG::Backends::DataSet
- Extended by:
- Forwardable
- Defined in:
- lib/SciYAG/Backends/dataset.rb
Overview
An abstract class representing a DataSet. You should consider using a subclass, DataSet2D or DataSet3D. A DataSet must be either 2D or 3D, and redefine #is_2D? and #is_3D? accordingly.
As DataSets grow more complex, it is likely that it will be less and less easy to tweak directly the data inside. So, please, do use the accessors and tweakers provided in the interface, else you’ll expose yourself to some intensive breakages when I get more clever. Meanwhile, the apply(meth,where,*rest) method should be used to keep everything in sync when you apply a method to a Dvector.
Instance Attribute Summary collapse
-
#creation_context ⇒ Object
The #creation_context attribute is a hash containing a :backend key indicating the name of the Backend created and filled with the contents of the backend’s DescriptionInclude#save_state function.
-
#data ⇒ Object
The data of the set.
-
#errors ⇒ Object
Errors on data, if applicable.
-
#meta_data ⇒ Object
The metadata given when the set was created.
Instance Method Summary collapse
-
#all_vectors ⇒ Object
Returns all the Dvectors held by this dataset.
-
#apply(what, where, *rest) ⇒ Object
Apply a Dvector operation to the given dimension, including everything that could be left somewhere in the error bars.
-
#initialize(context, data, errors = {}, meta_data = {}) ⇒ DataSet
constructor
A new instance of DataSet.
- #is_2D? ⇒ Boolean
- #is_3D? ⇒ Boolean
-
#method_missing(sym, *args, &b) ⇒ Object
Does a redirection to the underlying @data if that makes sense.
-
#sort! ⇒ Object
Sorts the data according to the X value.
Constructor Details
#initialize(context, data, errors = {}, meta_data = {}) ⇒ DataSet
Returns a new instance of DataSet.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/SciYAG/Backends/dataset.rb', line 75 def initialize(context, data, errors = {}, = {}) if context.respond_to? :save_state @creation_context = context.save_state @creation_context[:backend] = context.description.name else @creation_context = context.dup end @data = data @errors = errors @meta_data = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &b) ⇒ Object
Does a redirection to the underlying @data if that makes sense.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/SciYAG/Backends/dataset.rb', line 102 def method_missing(sym, *args, &b) if @data.respond_to?(sym) @data.send(sym, *args, &b) elsif x.respond_to?(sym) # We are trying to apply something # like data.mul!(:x, factor) apply(sym,args.shift,*args,&b) else super end end |
Instance Attribute Details
#creation_context ⇒ Object
The #creation_context attribute is a hash containing a :backend key indicating the name of the Backend created and filled with the contents of the backend’s DescriptionInclude#save_state function.
44 45 46 |
# File 'lib/SciYAG/Backends/dataset.rb', line 44 def creation_context @creation_context end |
#data ⇒ Object
The data of the set.
47 48 49 |
# File 'lib/SciYAG/Backends/dataset.rb', line 47 def data @data end |
#errors ⇒ Object
Errors on data, if applicable. For 2D data, this will just be a hash with the following Dvectors:
:xmin, :xmax for errors on the x values + :x, to make sure
we keep it up-to-date.
:ymin, :ymax for errors on y + :y.
Both ?min and ?max have to be specified if any output should be created.
57 58 59 |
# File 'lib/SciYAG/Backends/dataset.rb', line 57 def errors @errors end |
#meta_data ⇒ Object
The metadata given when the set was created.
60 61 62 |
# File 'lib/SciYAG/Backends/dataset.rb', line 60 def @meta_data end |
Instance Method Details
#all_vectors ⇒ Object
Returns all the Dvectors held by this dataset. Can be used to Dvector#replace them
115 116 117 118 119 |
# File 'lib/SciYAG/Backends/dataset.rb', line 115 def all_vectors list = [@data.x, @data.y, *@errors.values] list << @data.z if @data.respond_to?(:z) return list end |
#apply(what, where, *rest) ⇒ Object
Apply a Dvector operation to the given dimension, including everything that could be left somewhere in the error bars. It should be very powerful in the end.
Beautiful, isn’t it ??
92 93 94 95 96 97 98 99 |
# File 'lib/SciYAG/Backends/dataset.rb', line 92 def apply(what, where, *rest) self.send(where).send(what, *rest) for key,values in @errors if key.to_s =~ /^#{where}/ # Very much overkill, but, well... values.send(what,*rest) end end end |
#is_2D? ⇒ Boolean
62 63 64 |
# File 'lib/SciYAG/Backends/dataset.rb', line 62 def is_2D? return false end |
#is_3D? ⇒ Boolean
66 67 68 |
# File 'lib/SciYAG/Backends/dataset.rb', line 66 def is_3D? return false end |
#sort! ⇒ Object
Sorts the data according to the X value. This also includes the error bars.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/SciYAG/Backends/dataset.rb', line 123 def sort! new_error = {} idx_vector = Dobjects::Dvector.new(@data.x.size) do |i| i end f = Dobjects::Function.new(@data.x.dup, idx_vector) f.sort for vector in all_vectors new_vector = Dobjects::Dvector.new(vector.size) do |i| vector[f.y[i]] end vector.replace(new_vector) end end |