Class: CTioga2::Data::IndexedDTable
- Inherits:
-
Object
- Object
- CTioga2::Data::IndexedDTable
- 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
-
#table ⇒ Object
The underlying Dtable.
-
#x_values ⇒ Object
X values.
-
#y_values ⇒ Object
Y values.
Instance Method Summary collapse
-
#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.
- #height ⇒ Object
-
#initialize(x, y, t) ⇒ IndexedDTable
constructor
A new instance of IndexedDTable.
-
#ll ⇒ Object
Returns the coordinates of the lower-left XY values.
-
#lr ⇒ Object
Returns the coordinates of the lower-left XY values.
-
#make_contour(level, opts = {}) ⇒ Object
Makes a contour using the given level.
-
#ul ⇒ Object
Returns the coordinates of the upper-right XY values.
-
#ur ⇒ Object
Returns the coordinates of the upper-right XY values.
- #width ⇒ Object
-
#xy_boundaries ⇒ Object
Returns the XY boundaries of the object.
-
#xy_correction ⇒ Object
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 !).
Constructor Details
#initialize(x, y, t) ⇒ IndexedDTable
Returns a new instance of IndexedDTable.
40 41 42 43 44 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 40 def initialize(x, y, t) @table = t @x_values = x @y_values = y end |
Instance Attribute Details
#table ⇒ Object
The underlying Dtable
32 33 34 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 32 def table @table end |
#x_values ⇒ Object
X values
35 36 37 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 35 def x_values @x_values end |
#y_values ⇒ Object
Y values
38 39 40 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 38 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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 86 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 |
#height ⇒ Object
110 111 112 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 110 def height return @y_values.size end |
#ll ⇒ Object
Returns the coordinates of the lower-left XY values
65 66 67 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 65 def ll return [@x_values.first, @y_values.first] end |
#lr ⇒ Object
Returns the coordinates of the lower-left XY values
70 71 72 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 70 def lr return [@x_values.last, @y_values.first] end |
#make_contour(level, opts = {}) ⇒ Object
Makes a contour using the given level.
Depending on the value of opts, what is returned is:
-
if ‘xyg’, [xs, ys, gaps] triplet suitable for use with t.append_points_with_gaps_to_path to show the given level (default)
-
if ‘func’, a single function with nans inserted at the position of the gaps
-
if ‘funcs’, a function for each of the “continuous” segments
Anything else in opts is given directly to make_contour
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 125 def make_contour(level, opts = {}) gaps = [] # Requires Tioga r598 opts = {'data' => @table, 'xs' => @x_values, 'ys' => @y_values, 'gaps' => gaps, 'level' => level }.update(opts) ret = opts['ret'] || 'xyg' opts.delete('ret') xs, ys = *Tioga::FigureMaker.make_contour(opts) if ret == 'xyg' return [xs, ys, gaps] end gaps = opts['gaps'].dup gaps -= [xs.size] n = 0.0/0.0 gaps.sort.reverse.each do |i| xs.insert(i,n) ys.insert(i,n) end fnc = Dobjects::Function.new(xs,ys) if ret == 'func' return fnc else return fnc.split_on_nan(:x) end end |
#ul ⇒ Object
Returns the coordinates of the upper-right XY values
80 81 82 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 80 def ul return [@x_values.first, @y_values.last] end |
#ur ⇒ Object
Returns the coordinates of the upper-right XY values
75 76 77 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 75 def ur return [@x_values.last, @y_values.last] end |
#width ⇒ Object
106 107 108 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 106 def width return @x_values.size end |
#xy_boundaries ⇒ Object
Returns the XY boundaries of the object
47 48 49 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 47 def xy_boundaries return Graphics::Types::Boundaries.bounds(@x_values, @y_values) end |
#xy_correction ⇒ Object
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.
59 60 61 62 |
# File 'lib/ctioga2/data/indexed-dtable.rb', line 59 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 |