h5geo 0.4.0
C++17 and python API to work with geo-data (seismic, wells, maps, other in process) based on HDF5. Aimed at geoscientists and developers.
Loading...
Searching...
No Matches
h5interpolation.h
1#ifndef H5INTERPOLATION_H
2#define H5INTERPOLATION_H
3
4#include <Eigen/Dense>
5
6namespace h5geo
7{
8
9
10template <typename D>
17Eigen::VectorX<typename D::Scalar> interp1Monotonic(
18 const Eigen::DenseBase<D> &x,
19 const Eigen::DenseBase<D> &y,
20 const Eigen::DenseBase<D> &xnew,
21 typename D::Scalar extrapVal)
22{
23 typedef typename D::Scalar S;
24 if (x.size() != y.size() ||
25 x.size() < 2 ||
26 y.size() < 2)
27 return Eigen::VectorX<S>();
28
29 int nx = x.size();
30 Eigen::VectorX<S> ynew;
31 ynew.resize(xnew.size());
32 S dx = x(1)-x(0);
33 bool isXIncreasing;
34 if (dx > 0)
35 isXIncreasing = true;
36 else if (dx < 0)
37 isXIncreasing = false;
38 else
39 return Eigen::VectorX<S>();
40
41 for (ptrdiff_t i = 0; i < xnew.size(); i++){
42 int ind = 0;
43 if (isXIncreasing){
44 if (xnew(i) >= x(nx - 2))
45 ind = nx - 2;
46 else
47 while (xnew(i) > x(ind+1))
48 ind++;
49 } else {
50 if (xnew(i) <= x(nx - 2))
51 ind = nx - 2;
52 else
53 while (xnew(i) < x(ind+1))
54 ind++;
55 }
56
57 S xL = x(ind);
58 S yL = y(ind);
59 S xR = x(ind+1);
60 S yR = y(ind+1);
61 if (isXIncreasing){
62 if (xnew(i) < xL)
63 yR = extrapVal; // yR = yL;
64 if (xnew(i) > xR)
65 yL = extrapVal; // yL = yR;
66 } else {
67 if (xnew(i) > xL)
68 yR = extrapVal;
69 if (xnew(i) < xR)
70 yL = extrapVal;
71 }
72
73 S dydx = (yR - yL) / (xR - xL);
74
75 ynew(i) = yL + dydx * (xnew(i) - xL);
76 }
77
78 return ynew;
79}
80
81
82} // h5geo
83
84#endif // H5INTERPOLATION_H
Basic namespace.
Definition h5base.h:29
Eigen::VectorX< typename D::Scalar > interp1Monotonic(const Eigen::DenseBase< D > &x, const Eigen::DenseBase< D > &y, const Eigen::DenseBase< D > &xnew, typename D::Scalar extrapVal)
1D interpolation for
Definition h5interpolation.h:17