| Total Complexity | 3 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import numpy as np |
||
|
|
|||
| 2 | from numpy import log10 |
||
| 3 | from math import log10 as mlog10 |
||
| 4 | import scipy.interpolate |
||
| 5 | |||
| 6 | |||
| 7 | class LogLogInterpolator(object): # pragma: no cover |
||
| 8 | |||
| 9 | def __init__(self, x, y, k=2): |
||
| 10 | |||
| 11 | y = y.astype(np.float64) |
||
| 12 | y = np.clip(y, 2 * np.finfo(np.float64).tiny, None) |
||
| 13 | |||
| 14 | logx = log10(x) |
||
| 15 | logy = log10(y) |
||
| 16 | |||
| 17 | self._interp = scipy.interpolate.InterpolatedUnivariateSpline(logx, logy, k=k) |
||
| 18 | |||
| 19 | def __call__(self, x): |
||
| 20 | |||
| 21 | return 10**self._interp(log10(x)) |
||
| 22 | |||
| 23 | def integral(self, a, b, n_points=100, k=1): |
||
| 24 | |||
| 25 | # Make a second interpolator |
||
| 26 | xx = np.logspace(mlog10(a), mlog10(b), n_points) |
||
| 27 | |||
| 28 | yy = self.__call__(xx) |
||
| 29 | |||
| 30 | int_interp = scipy.interpolate.InterpolatedUnivariateSpline(xx, yy, k=k) |
||
| 31 | |||
| 32 | return int_interp.integral(a, b) |
||
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.