Class: CTioga2::Data::IndexedDTable

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/data/indexed-dtable.rb

Overview

An indexed Dtable.

This object represents an indexed Dtable, that is a Dtable with given values of X and Y (not necessarily uniform). Its main use is to get back a uniform (non-indexed) Dtable, for use with create_image

An important information is that places where there was no data is implicitly represented as NaN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, t) ⇒ IndexedDTable

Returns a new instance of IndexedDTable.



43
44
45
46
47
# File 'lib/ctioga2/data/indexed-dtable.rb', line 43

def initialize(x, y, t)
  @table = t
  @x_values = x
  @y_values = y
end

Instance Attribute Details

#tableObject

The underlying Dtable



35
36
37
# File 'lib/ctioga2/data/indexed-dtable.rb', line 35

def table
  @table
end

#x_valuesObject

X values



38
39
40
# File 'lib/ctioga2/data/indexed-dtable.rb', line 38

def x_values
  @x_values
end

#y_valuesObject

Y values



41
42
43
# File 'lib/ctioga2/data/indexed-dtable.rb', line 41

def y_values
  @y_values
end

Instance Method Details

#corner_positions(correction = true) ⇒ Object

Returns a hash ul,ll,lr with the corresponding values of the the points, with the correction applied if correction is true



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ctioga2/data/indexed-dtable.rb', line 89

def corner_positions(correction = true)
  dict = {
    'll' => ll,
    'lr' => lr,
    'ul' => ul
  }
  if correction
    dx, dy = *xy_correction
    # This isn't really beautiful, but it just works.
    dict['ll'][0] -= dx
    dict['lr'][0] += dx
    dict['ul'][0] -= dx

    dict['ll'][1] -= dy
    dict['lr'][1] -= dy
    dict['ul'][1] += dy
  end
  return dict
end

#heightObject



113
114
115
# File 'lib/ctioga2/data/indexed-dtable.rb', line 113

def height
  return @y_values.size
end

#llObject

Returns the coordinates of the lower-left XY values



68
69
70
# File 'lib/ctioga2/data/indexed-dtable.rb', line 68

def ll
  return [@x_values.first, @y_values.first]
end

#lrObject

Returns the coordinates of the lower-left XY values



73
74
75
# File 'lib/ctioga2/data/indexed-dtable.rb', line 73

def lr
  return [@x_values.last, @y_values.first]
end

#make_contour(level) ⇒ Object

TODO:

add algorithm choice too

Returns a [xs, ys, gaps] triplet suitable for use with t.append_points_with_gaps_to_path to show the given level.



121
122
123
124
125
126
127
128
129
130
# File 'lib/ctioga2/data/indexed-dtable.rb', line 121

def make_contour(level)
  gaps = []
  # Requires Tioga r598
  xs, ys = *Tioga::FigureMaker.make_contour('data' => @table,
                                            'xs' => @x_values, 
                                            'ys' => @y_values,
                                            'gaps' => gaps,
                                            'level' => level)
  return  [xs, ys, gaps]
end

#ulObject

Returns the coordinates of the upper-right XY values



83
84
85
# File 'lib/ctioga2/data/indexed-dtable.rb', line 83

def ul
  return [@x_values.first, @y_values.last]
end

#urObject

Returns the coordinates of the upper-right XY values



78
79
80
# File 'lib/ctioga2/data/indexed-dtable.rb', line 78

def ur
  return [@x_values.last, @y_values.last]
end

#widthObject



109
110
111
# File 'lib/ctioga2/data/indexed-dtable.rb', line 109

def width
  return @x_values.size
end

#xy_boundariesObject

Returns the XY boundaries of the object



50
51
52
# File 'lib/ctioga2/data/indexed-dtable.rb', line 50

def xy_boundaries
  return Graphics::Types::Boundaries.bounds(@x_values, @y_values)
end

#xy_correctionObject

Returns the value by which one should shift the X and Y positions of the borders of the images in order to get the points centered on their pixel (for a uniform grid !).

While this correction looks better on non-uniform grids, it does not guarantee that it places all the points int the middle of their pixel, but that is still true for the ones at the border.



62
63
64
65
# File 'lib/ctioga2/data/indexed-dtable.rb', line 62

def xy_correction
  return [(@x_values.last - @x_values.first)/ (2 * @x_values.size),
          (@y_values.last - @y_values.first)/ (2 * @y_values.size)]
end