vice.toolkit.interpolation.interp_scheme_2d¶
A 2-dimensional interpolation scheme. This object takes in x-, y-, and z-coordinates of the appropriate lengths and constructs a continuous function by connecting the points with bilinear interpolation.
Signature: vice.toolkit.interpolation.interp_scheme_2d(xcoords, ycoords, zcoords)
New in version 1.2.0.
Parameters¶
- xccordsarray-like
The attribute
xcoords
. See below.- ycoordsarray-like
The attribute
ycoords
. See below.- zcoordsarray-like
The attribute
zcoords
. See below.
Attributes¶
- xcoords
list
[elements are real numbers] The x-coordinates of the points to construct the interpolation scheme out of, in arbitrary units.
Note
These values will be automatically sorted from least to greatest upon construction of an
interp_scheme_2d
object. While this could potentially alter the ordering of this attribute, it will not affect thezcoords
attribute, which is assumed to correspond component-wise to the x-coordinates in their least to greatest sorting. The burden is on the user to ensure that their coordinates are in the proper ordering.- ycoords
list
[elements are real numbers] The y-coordinates fo the points to construct the interpolation scheme out of, in arbitrary units.
Note
The same note which applies to the x-coordinates above also applies to the y-coordinates.
- zcoords
list
[elements are of typelist
containing real numbers] The z-coordinates of the points to construct the interpolation scheme out of, in arbitrary units. This must be of the same length as the
xcoords
array, containing elements which are of the same length as theycoords
array. The values stored should correspond component-wise to those arrays such thatself(xcoords[i], ycoords[j]) = zcoords[i][j]
.
Calling¶
Call this object with any given x- and y-coordinates, and it will automatically determine the correct set of (x, y) coordinates to interpolate between, and return the appropriate value.
Parameters:
- xreal number
The x-coordinate to evaluate the interpolation scheem at, in the same units as the attribute
xcoords
.
- yreal number
The y-coordinate to evaluate the interpolation scheme at, in the same units as the attribute
ycoords
.Returns:
- zreal number
The value of the z-coordinate, approximated via bilinear interpolation connecting the points \((x_1, y_1)\), \((x_1, y_2)\), \((x_2, y_1)\), and \((x_2, y_2)\): the points defining the four corners of the box in x-y space bouding the point (
x
,y
).The interpolation is such that the values of \(f(x_1, y)\) and \(f(x_2, y)\) are determined via linear interpolation in one-dimension at constant \(x\), then the value of \(f(x, y)\) is calculated similarly at constant \(y\).
Example Code¶
>>> from vice.toolkit.interpolation import interp_scheme_2d
>>> example = interp_scheme_2d([1, 2, 3], [2, 4, 6],
[[3, 6, 9], [4, 8, 12], [5, 10, 15]])
>>> example(0, 0)
0.0
>>> example(10, 10)
60.0
>>> example(3.1, 2.8)
7.140000000000001
>>> example.xcoords
[1, 2, 3]
>>> example.ycoords
[2, 4, 6]
>>> example.zcoords
[[3, 6, 9], [4, 8, 12], [5, 10, 15]]