Module: CTioga2::Data

Defined in:
lib/ctioga2/data/dataset.rb,
lib/ctioga2/data/point.rb,
lib/ctioga2/data/stack.rb,
lib/ctioga2/data/filters.rb,
lib/ctioga2/data/datacolumn.rb,
lib/ctioga2/data/indexed-dtable.rb,
lib/ctioga2/data/backends/backend.rb,
lib/ctioga2/data/backends/factory.rb,
lib/ctioga2/data/backends/parameter.rb,
lib/ctioga2/data/backends/description.rb,
lib/ctioga2/data/backends/backends/math.rb,
lib/ctioga2/data/backends/backends/text.rb,
lib/ctioga2/data/backends/backends/smath.rb,
lib/ctioga2/data/backends/backends/direct.rb,
lib/ctioga2/data/backends/backends/gnuplot.rb

Overview

This module holds all the code that deals with manipulation and acquisition of data of any sort.

Defined Under Namespace

Modules: Backends, Filters, NaN Classes: DataColumn, DataPoint, DataStack, Dataset, IndexedDTable

Constant Summary collapse

DataStackGroup =
CmdGroup.new('stack', "Data stack manipulation",
"Commands for manipulation of the data stack", 
100)
AppendDatasetOptions =
{ 
  'as' => CmdArg.new('text'),
  'where' => CmdArg.new('text'),
  'ignore_hooks' => CmdArg.new('boolean')
}
AppendDataCommand =
Cmd.new("append", nil, "--append", 
          [ CmdArg.new('dataset'), ], 
          AppendDatasetOptions) do |plotmaker, set, opts|
  datasets = plotmaker.data_stack.get_datasets(set, opts, false)
  # Now, we append them to the last dataset
  plotmaker.data_stack.concatenate_datasets(datasets)
end
LoadDatasetOptions =
AppendDatasetOptions.dup.merge(
{
  'name' => CmdArg.new('text')
})
LoadDataCommand =
Cmd.new("load", '-L', "--load", 
          [ CmdArg.new('dataset'), ], 
          LoadDatasetOptions) do |plotmaker, set, opts|
  plotmaker.data_stack.get_datasets(set, opts)
end
ContourOptions =
LoadDatasetOptions.dup.update({
  'which' => CmdArg.new('stored-dataset'),
})
MakeContourCommand =
Cmd.new("make-contour", nil, "--make-contour", 
          [ CmdArg.new('float'), ], 
          ContourOptions) do |plotmaker, level, opts|
  ds = plotmaker.data_stack.specified_dataset(opts)
  f = ds.make_contour(level)
  name = "Level #{level} for plot '#{ds.name}'"
  newds = Dataset.new(name, [f.x, f.y])
  plotmaker.data_stack.add_datasets([newds], opts)
end
PrintLastCommand =
Cmd.new("print-dataset", '-P', "--print-dataset",
          [], {
            'which' => CmdArg.new('stored-dataset'),
            'save' => CmdArg.new('file'),
          }) do |plotmaker,opts|
  ds = plotmaker.data_stack.specified_dataset(opts)
  if opts['save']
    # Writing
    out = open(opts['save'], 'w')
  else
    out = STDOUT
  end
  plotmaker.data_stack.print_dataset(ds, out)
end
DropCommand =
Cmd.new("drop", nil, "--drop",
          [CmdArg.new('stored-dataset')], { }) do |plotmaker,spec,opts|
  plotmaker.data_stack.drop_from_stack(spec)
end
ConcatLastCommand =
Cmd.new("join-datasets", "-j", "--join-datasets", 
          [], 
          { 
            'number' => CmdArg.new('integer'),
            'which' => CmdArg.new('stored-dataset'),
            'name' => CmdArg.new('text') 
          }) do |plotmaker, opts|
  stack = plotmaker.data_stack
  datasets = stack.latest_datasets(opts)
  stack.concatenate_datasets(datasets, opts['name'])
end
ApplyLastCommand =
Cmd.new("apply-formula", nil, "--apply-formula",
          [CmdArg.new('text')], 
          {
            'which' => CmdArg.new('stored-dataset'),
            'name' => CmdArg.new('text'),
          }) do |plotmaker, formula, opts|
  ds = plotmaker.data_stack.specified_dataset(opts)
  newds = ds.apply_formulas(formula)
  plotmaker.data_stack.add_datasets([newds], opts)
end
BinLastCommand =
Cmd.new("bin", nil, "--bin", 
          [], 
          { 
            'number' => CmdArg.new('integer'),
            'column' => CmdArg.new('integer'),
            'delta' => CmdArg.new('float'),
            'min' => CmdArg.new('float'),
            'max' => CmdArg.new('float'),
            'normalize' => CmdArg.new('boolean'),
            'which' => CmdArg.new('stored-dataset'),
            'name' => CmdArg.new('text') 
          }) do |plotmaker, opts|
  stack = plotmaker.data_stack
  ds = plotmaker.data_stack.specified_dataset(opts)

  cn = opts['column'] || 1
  col = ds.all_columns[cn]

  
  if opts.key? 'number'
    min = opts['min'] || col.min
    max = opts['max'] || col.max
    number = opts['number']
  elsif opts.key? 'delta'
    delta = opts['delta']
    if opts.key? 'min'
      min = opts['min']
      max = min+((col.max-min)/delta).ceil*delta
    elsif opts.key? 'max'
      max = opts['max']
      min = max-((max-col.min)/delta).floor*delta
    else
      min = (col.min/delta).floor * delta
      max = (col.max/delta).ceil * delta
    end
    number = ((max-min)/delta).to_i
  else
    raise "Must specify either the option 'number' or the option 'delta'"
  end

  newds = Dataset.new("bin", col.bin(min, max, number, opts['normalize']))
  plotmaker.data_stack.add_datasets([newds], opts)
end
ShowStackCommand =
Cmd.new("show-stack", nil, "--show-stack", 
          [], 
          { }
          ) do |plotmaker, opts|
  plotmaker.data_stack.show
end
MergeToLastCommand =
TODO:

Add column selection ?

Cmd.new("merge-datasets", nil, "--merge-datasets", 
          [], 
          {
            'number' => CmdArg.new('integer'), 
            'precision' => CmdArg.new('float'), 
            'which' => CmdArg.new('stored-dataset'),
            'columns' => CmdArg.new('integer-list')
          }
          ) do |plotmaker, opts|
  stack = plotmaker.data_stack
  cols = if opts.key? 'columns'
           opts['columns'].map { |x| x - 1 }
         else
           [0]
         end
  datasets = stack.latest_datasets(opts)
  plotmaker.data_stack.merge_datasets_into_last(datasets, cols,
                                                opts['precision'])
end
XYReglinCommand =
Cmd.new("xy-reglin", nil, "--xy-reglin", [], {
            'which' => CmdArg.new('stored-dataset'),
            'linear' => CmdArg.new('boolean'),
          }) do |plotmaker,opts|
  stack = plotmaker.data_stack
  ds = stack.specified_dataset(opts)
  coeffs, lines = ds.reglin(opts)
  stack.store_dataset(lines, true)
  stack.store_dataset(coeffs, true)
end
ComputeContourCommand =
Cmd.new("compute-contour", nil, "--compute-contour", 
          [CmdArg.new("float")], {
            'which' => CmdArg.new('stored-dataset')
          }) do |plotmaker, level, opts|
  stack = plotmaker.data_stack
  ds = stack.specified_dataset(opts)
  f = ds.make_contour(level)
  newds = Dataset.new("Contour #{level}", [f.x, f.y])
  stack.store_dataset(newds, true)
end
SetDatasetHookCommand =
Cmd.new("dataset-hook", nil, "--dataset-hook", 
          [CmdArg.new('commands')], {}) do |plotmaker, commands, opts|
  raise 'This command is disabled as of now'
  plotmaker.data_stack.dataset_hook = commands
end
ClearDatasetHookCommand =
Cmd.new("dataset-hook-clear", nil, "--dataset-hook-clear", 
          [], {}) do |plotmaker, opts|
  plotmaker.data_stack.dataset_hook = nil
end
AddDatasetHookCommand =
Cmd.new("dataset-hook-add", nil, "--dataset-hook-add", 
          [CmdArg.new('commands')], {}) do |plotmaker, commands, opts|
  raise 'This command is disabled as of now'
  plotmaker.data_stack.add_to_dataset_hook(commands)
end