~ubuntu-branches/ubuntu/wily/ctioga2/wily

« back to all changes in this revision

Viewing changes to lib/ctioga2/data/dataset.rb

  • Committer: Package Import Robot
  • Author(s): Vincent Fourmond
  • Date: 2013-07-08 20:58:17 UTC
  • mfrom: (6.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130708205817-cephnc6etndyxrrp
Tags: 0.4-2
* Upload to unstable
* Already conforms to newer standards

Show diffs side-by-side

added added

removed removed

Lines of Context:
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: 233 $', '$Date: 2011-01-20 10:26:42 +0100 (Thu, 20 Jan 2011) $')
 
21
  Version::register_svn_info('$Revision: 304 $', '$Date: 2012-01-03 15:06:33 +0100 (Tue, 03 Jan 2012) $')
21
22
 
22
23
 
23
24
  # \todo now, port the backend infrastructure...
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
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
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-1,n)
359
 
          y.insert(i-1,n)
 
404
          x.insert(i,n)
 
405
          y.insert(i,n)
360
406
        end
361
407
        return Dobjects::Function.new(x,y)
362
408
      end