9.4. Interpolators¶
Historically Cherab provided 1D, 2D and 3D interpolators. New codes are encouraged to use Raysect’s interpolators instead. For backwards compatibility the Cherab interpolators are retained for now.
- class cherab.core.math.interpolators.interpolators1d.Interpolate1DLinear¶
Deprecated since version 1.3.0: Use raysect.core.math.function.float.Interpolator1DArray instead.
Interpolates 1D data using linear interpolation.
Inherits from Function1D, implements __call__(x).
- Parameters
x (object) – A 1D array-like object of real values.
f (object) – A 1D array-like object of real values. The length of f_data must be equal to the length of x_data.
extrapolate (bint) – If True, the extrapolation of data is enabled outside the range of the data set. The default is False. A ValueError is raised if extrapolation is disabled and a point is requested outside the data set.
extrapolation_type (object) – Sets the method of extrapolation. The options are: ‘nearest’ (default), ‘linear’.
extrapolation_range (double) – The attribute can be set to limit the range beyond the data set bounds that extrapolation is permitted. The default range is set to infinity. Requesting data beyond the extrapolation range will result in a ValueError being raised.
tolerate_single_value – If True, single-value arrays will be tolerated as inputs. If a single value is supplied, that value will be extrapolated over the entire real range. If False (default), supplying a single value will result in a ValueError being raised.
>>> from cherab.core.math import Interpolate1DLinear >>> >>> f1d = Interpolate1DLinear([0, 0.5, 0.9, 1.0], [2500, 2000, 1000, 0]) >>> >>> f1d(0.2) 2300.0 >>> f1d(0.875) 1062.5 >>> f1d(1.2) ValueError: The specified value (x=1.2) is outside the range of the supplied data and/or extrapolation range: x bounds=(0.0, 1.0)
- class cherab.core.math.interpolators.interpolators1d.Interpolate1DCubic¶
Deprecated since version 1.3.0: Use raysect.core.math.function.float.Interpolator1DArray instead.
Interpolates 1D data using cubic interpolation.
Inherits from Function1D, implements __call__(x).
Data and coordinates are first normalised to the range [0, 1] so as to prevent inaccuracy from float numbers. Spline coefficients are cached so they have to be calculated at initialisation only.
- Parameters
x (object) – A 1D array-like object of real values.
f (object) – A 1D array-like object of real values. The length of f_data must be equal to the length of x_data.
continuity_order (int) – Sets the continuity of the cubic spline. When set to 1 the cubic spline second derivatives are estimated from the data samples and is not continuous. Here, the first derivative is free and forced to be continuous, but the second derivative is imposed from finite differences estimation. When set to 2 the cubic spline second derivatives are free but are forced to be continuous. Defaults to continuity_order = 2.
extrapolate (bint) – If True, the extrapolation of data is enabled outside the range of the data set. The default is False. A ValueError is raised if extrapolation is disabled and a point is requested outside the data set.
extrapolation_type (object) – Sets the method of extrapolation. The options are: ‘nearest’ (default), ‘linear’, ‘quadratic’
extrapolation_range (double) – The attribute can be set to limit the range beyond the data set bounds that extrapolation is permitted. The default range is set to infinity. Requesting data beyond the extrapolation range will result in a ValueError being raised.
tolerate_single_value – If True, single-value arrays will be tolerated as inputs. If a single value is supplied, that value will be extrapolated over the entire real range. If False (default), supplying a single value will result in a ValueError being raised.
>>> from cherab.core.math import Interpolate1DCubic >>> >>> f1d = Interpolate1DCubic([0, 0.5, 0.9, 1.0], [2500, 2000, 1000, 0]) >>> >>> f1d(0.2) 2197.4683 >>> f1d(0.875) 1184.4343 >>> f1d(1.2) ValueError: The specified value (x=1.2) is outside the range of the supplied data and/or extrapolation range: x bounds=(0.0, 1.0)
- class cherab.core.math.interpolators.interpolators2d.Interpolate2DLinear¶
Deprecated since version 1.3.0: Use raysect.core.math.function.float.Interpolator2DArray instead.
Interpolates 2D data using linear interpolation.
Inherits from Function2D, implements __call__(x, y).
- Parameters
x (object) – An array-like object containing real values.
y (object) – An array-like object containing real values.
f (object) – A 2D array-like object of sample values corresponding to the x and y array points.
extrapolate (bint) – If True, the extrapolation of data is enabled outside the range of the data set. The default is False. A ValueError is raised if extrapolation is disabled and a point is requested outside the data set.
extrapolation_type (object) – Sets the method of extrapolation. The options are: ‘nearest’ (default), ‘linear’
extrapolation_range (double) – The attribute can be set to limit the range beyond the data set bounds that extrapolation is permitted. The default range is set to infinity. Requesting data beyond the extrapolation range will result in a ValueError being raised.
tolerate_single_value – If True, single-value arrays will be tolerated as inputs. If a single value is supplied, that value will be extrapolated over the entire real range. If False (default), supplying a single value will result in a ValueError being raised.
>>> import numpy as np >>> from cherab.core.math import Interpolate2DLinear >>> >>> # implements x**2 + y >>> drange = np.linspace(-2.5, 2.5, 100) >>> values = np.zeros((100, 100)) >>> for i in range(100): >>> for j in range(100): >>> values[i, j] = drange[i]**2 + drange[j] >>> >>> f2d = Interpolate2DLinear(drange, drange, values) >>> >>> f2d(0, 0) 0.00063769 >>> f2d(-2, 1) 5.00022956 >>> f2d(-2, 3) ValueError: The specified value (x=-2.0, y=3.0) is outside the range of the supplied data and/or extrapolation range: x bounds=(-2.5, 2.5), y bounds=(-2.5, 2.5)
- class cherab.core.math.interpolators.interpolators2d.Interpolate2DCubic¶
Deprecated since version 1.3.0: Use raysect.core.math.function.float.Interpolator2DArray instead.
Interpolates 2D data using cubic interpolation.
Inherits from Function2D, implements __call__(x, y).
Data and coordinates are first normalised to the range [0, 1] so as to prevent inaccuracy from float numbers. A local calculation based on finite differences is used. The splines coefficients are not calculated before evaluation but on demand only and are cached as they are calculated. Plus, only one polynomial is calculated at each evaluation. The first derivatives and the cross derivative are imposed by the finite differences. The resulting function is C1.
- Parameters
x (object) – An array-like object containing real values.
y (object) – An array-like object containing real values.
f (object) – A 2D array-like object of sample values corresponding to the x and y array points.
extrapolate (bint) – If True, the extrapolation of data is enabled outside the range of the data set. The default is False. A ValueError is raised if extrapolation is disabled and a point is requested outside the data set.
extrapolation_type (object) – Sets the method of extrapolation. The options are: ‘nearest’ (default), ‘linear’, ‘quadratic’.
extrapolation_range (double) – The attribute can be set to limit the range beyond the data set bounds that extrapolation is permitted. The default range is set to infinity. Requesting data beyond the extrapolation range will result in a ValueError being raised.
tolerate_single_value – If True, single-value arrays will be tolerated as inputs. If a single value is supplied, that value will be extrapolated over the entire real range. If False (default), supplying a single value will result in a ValueError being raised.
>>> import numpy as np >>> from cherab.core.math import Interpolate2DCubic >>> >>> # implements x**2 + y >>> drange = np.linspace(-2.5, 2.5, 100) >>> values = np.zeros((100, 100)) >>> for i in range(100): >>> for j in range(100): >>> values[i, j] = drange[i]**2 + drange[j] >>> >>> f2d = Interpolate2DCubic(drange, drange, values) >>> >>> f2d(0, 0) 0.00063769 >>> f2d(-2, 1) 5.00022956 >>> f2d(-2, 3) ValueError: The specified value (x=-2.0, y=3.0) is outside the range of the supplied data and/or extrapolation range: x bounds=(-2.5, 2.5), y bounds=(-2.5, 2.5)
- class cherab.core.math.interpolators.interpolators3d.Interpolate3DLinear¶
Deprecated since version 1.3.0: Use raysect.core.math.function.float.Interpolator3DArray instead.
Interpolates 3D data using linear interpolation.
Inherits from Function3D, implements __call__(x, y, z).
- Parameters
x (object) – An array-like object containing real values.
y (object) – An array-like object containing real values.
z (object) – An array-like object containing real values.
f (object) – A 3D array-like object of sample values corresponding to the x, y and z array points.
extrapolate (bint) – If True, the extrapolation of data is enabled outside the range of the data set. The default is False. A ValueError is raised if extrapolation is disabled and a point is requested outside the data set.
extrapolation_type (object) – Sets the method of extrapolation. The options are: ‘nearest’ (default), ‘linear’.
extrapolation_range (double) – The attribute can be set to limit the range beyond the data set bounds that extrapolation is permitted. The default range is set to infinity. Requesting data beyond the extrapolation range will result in a ValueError being raised.
tolerate_single_value – If True, single-value arrays will be tolerated as inputs. If a single value is supplied, that value will be extrapolated over the entire real range. If False (default), supplying a single value will result in a ValueError being raised.
>>> import numpy as np >>> from cherab.core.math import Interpolate3DLinear >>> >>> # implements x**3 + y**2 + z >>> drange = np.linspace(-2.5, 2.5, 100) >>> values = np.zeros((100, 100, 100)) >>> for i in range(100): >>> for j in range(100): >>> for k in range(100): >>> values[i, j, k] = drange[i]**3 + drange[j]**2 + drange[k] >>> >>> f3d = Interpolate3DLinear(drange, drange, drange, values) >>> >>> f3d(0, 0, 0) 0.00063769 >>> f3d(-2, 1, 1.5) -5.50085102 >>> f3d(-3, 1, 0) ValueError: The specified value (x=-3.0, y=1.0, z=0.0) is outside the range of the supplied data and/or extrapolation range: x bounds=(-2.5, 2.5), y bounds=(-2.5, 2.5), z bounds=(-2.5, 2.5)
- class cherab.core.math.interpolators.interpolators3d.Interpolate3DCubic¶
Deprecated since version 1.3.0: Use raysect.core.math.function.float.Interpolator3DArray instead.
Interpolates 3D data using cubic interpolation.
Inherits from Function3D, implements __call__(x, y, z).
Data and coordinates are first normalised to the range [0, 1] so as to prevent inaccuracy from float numbers. A local calculation based on finite differences is used. The splines coefficients are calculated on demand and are cached as they are calculated. Plus, no more than one polynomial is calculated at each evaluation. The first derivatives and the cross derivatives (xy, xz, yz and xyz) are imposed by the finite differences approximation, and the resulting function is C1 (first derivatives are continuous).
- Parameters
x (object) – An array-like object containing real values.
y (object) – An array-like object containing real values.
z (object) – An array-like object containing real values.
f (object) – A 3D array-like object of sample values corresponding to the x, y and z array points.
extrapolate (bint) – If True, the extrapolation of data is enabled outside the range of the data set. The default is False. A ValueError is raised if extrapolation is disabled and a point is requested outside the data set.
extrapolation_type (object) – Sets the method of extrapolation. The options are: ‘nearest’ (default), ‘linear’, ‘quadratic’.
extrapolation_range (double) – The attribute can be set to limit the range beyond the data set bounds that extrapolation is permitted. The default range is set to infinity. Requesting data beyond the extrapolation range will result in a ValueError being raised.
tolerate_single_value – If True, single-value arrays will be tolerated as inputs. If a single value is supplied, that value will be extrapolated over the entire real range. If False (default), supplying a single value will result in a ValueError being raised.
>>> import numpy as np >>> from cherab.core.math import Interpolate3DCubic >>> >>> # implements x**3 + y**2 + z >>> drange = np.linspace(-2.5, 2.5, 100) >>> values = np.zeros((100, 100, 100)) >>> for i in range(100): >>> for j in range(100): >>> for k in range(100): >>> values[i, j, k] = drange[i]**3 + drange[j]**2 + drange[k] >>> >>> f3d = Interpolate3DCubic(drange, drange, drange, values) >>> >>> f3d(0, 0, 0) -1.7763e-14 >>> f3d(-2, 1, 1.5) -5.50000927 >>> f3d(-3, 1, 0) ValueError: The specified value (x=-3.0, y=1.0, z=0.0) is outside the range of the supplied data and/or extrapolation range: x bounds=(-2.5, 2.5), y bounds=(-2.5, 2.5), z bounds=(-2.5, 2.5)