Class: WadrcBcpScripts::Tensor

Inherits:
Object
  • Object
show all
Defined in:
lib/wadrc-bcp-scripts/tensor.rb

Overview

A class for manipulating Tensor info for DTI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ Tensor

Returns a new instance of Tensor.



7
8
9
10
11
12
# File 'lib/wadrc-bcp-scripts/tensor.rb', line 7

def initialize(filepath)
  @data = []
  open(filepath, 'r').each do |line|
    @data << line.split(/[\,\:\s]+/).each { |val| val.strip }
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/wadrc-bcp-scripts/tensor.rb', line 5

def data
  @data
end

Instance Method Details

#to_fsl_txt(output_file = 'out.txt') ⇒ Object

Write out Data to a file.



15
16
17
18
19
20
21
22
# File 'lib/wadrc-bcp-scripts/tensor.rb', line 15

def to_fsl_txt(output_file = 'out.txt')
  puts "Writing " + output_file
  open(output_file, 'w') do |file|
    @data.transpose.each do |line|
      file.puts line.join(' ')
    end
  end
end