bilinear Module
This module contains the code defining a JIT-compatible bilinear interpolation scheme.
BilinearInterpolator
A JIT-ed bilinear interpolation class
Interpolator for regularly spaced grid, where axes are given in strictly ascending order. Values outside the interpolation range can either be clamped to the interpolation range or result in a NaN value. Interpolates functions like f(x, y) -> z where z can be a vector or scalar.
We use numba to just-in-time compile these methods, which results in dramatic speed increases, on the order of a factor of 50
The grid is NxMxP shaped. N is the length of the grid in x, M the length in y, and P the length of the function output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_min |
float
|
Minimum value of the x-coordinate for the grid |
required |
x_max |
float
|
Maximum value fo the x-coordinate for the grid |
required |
x_bins |
int
|
Number of bins (cells) in the x-coordinate for the grid |
required |
y_min |
float
|
Minimum value of the y-coordinate for the grid |
required |
y_max |
float
|
Maximum value fo the y-coordinate for the grid |
required |
y_bins |
int
|
Number of bins (cells) in the y-coordinate for the grid |
required |
data |
ndarray
|
The NxMxP grid of data to interpolate on |
required |
nan |
bool
|
The policy of handling requests to extrapolate on the grid. If nan is True, requests to extrapolate will return arrays of NaN values. Otherwise the requests are clamped to the edge of the grid. Default is True. |
True
|
Attributes:
Name | Type | Description |
---|---|---|
x_min |
float
|
Minimum value of the x-coordinate for the grid |
x_max |
float
|
Maximum value fo the x-coordinate for the grid |
x_bins |
int
|
Number of bins (cells) in the x-coordinate for the grid |
y_min |
float
|
Minimum value of the y-coordinate for the grid |
y_max |
float
|
Maximum value fo the y-coordinate for the grid |
y_bins |
int
|
Number of bins (cells) in the y-coordinate for the grid |
values |
ndarray
|
The NxMxP grid of data to interpolate on |
nan |
bool
|
The policy of handling requests to extrapolate on the grid. If nan is True, requests to extrapolate will return arrays of NaN values. Otherwise the requests are clamped to the edge of the grid |
Methods:
Name | Description |
---|---|
BilinearInterpolator |
Construct the interpolator. |
get_edges_x |
Get the edges of the grid cell in the x-coordinate in coordinate and bin space for a given value |
get_edges_y |
Get the edges of the grid cell in the y-coordinate in coordinate and bin space for a given value |
check_values_shape |
Internal consistency check of the grid. Raises an Exception if check fails. |
interpolate |
Interpolate on a given coordinate (x,y) |
Source code in src/spyral/interpolate/bilinear.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
check_values_shape()
Internal consistency check of the grid. Raises an Exception if check fails.
Check to make sure all of the data given to the interpolator makes sense.
Source code in src/spyral/interpolate/bilinear.py
get_edges_x(value)
Get the edges of the grid cell in the x-coordinate in coordinate and bin space for a given value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
float
|
The value in x-coorindates for which edges should be found |
required |
Returns:
Type | Description |
---|---|
tuple[int, float, int, float]
|
A four-member tuple of (low x-bin number, low x-coorindate, high x-bin number, high x-coordinate) which describes the edges of the grid cell |
Source code in src/spyral/interpolate/bilinear.py
get_edges_y(value)
Get the edges of the grid cell in the y-coordinate in coordinate and bin space for a given value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
float
|
The value in y-coorindates for which edges should be found |
required |
Returns:
Type | Description |
---|---|
tuple[int, float, int, float]
|
A four-member tuple of (low y-bin number, low y-coorindate, high y-bin number, high y-coordinate) which describes the edges of the grid cell |
Source code in src/spyral/interpolate/bilinear.py
interpolate(x, y)
Interpolate on a given coordinate (x,y)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
float
|
The x-coordinate of the point to interpolate |
required |
y |
float
|
The y-coordinate of the point to interpolate |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The interpolated value. If the extrapolation policy was set to NaN, this can contain NaN values. Otherwise the requests are clamped to the edge of the grid |
Source code in src/spyral/interpolate/bilinear.py
clamp(value, low, hi)
Clamp a value to a range
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
float | int
|
Value to be clamped |
required |
low |
float | int
|
Bottom of the clamp range |
required |
hi |
float | int
|
Top of the clamp range |
required |
Returns:
Type | Description |
---|---|
float | int
|
Clamped value |