1
1
import numpy as np
2
+ from scipy .interpolate import RegularGridInterpolator , RectBivariateSpline
2
3
3
4
from gempy .optional_dependencies import require_scipy
4
5
@@ -20,39 +21,22 @@ def distance_2_points(p1, p2):
20
21
return np .sqrt (np .diff ((p1 [0 ], p2 [0 ])) ** 2 + np .diff ((p1 [1 ], p2 [1 ])) ** 2 )
21
22
22
23
23
- def interpolate_zvals_at_xy (xy , topography , method = 'interp2d ' ):
24
+ def interpolate_zvals_at_xy (xy , topography , method = 'DEP ' ):
24
25
"""
25
- Interpolates DEM values on a defined section
26
+ Interpolates DEM values on a defined section.
26
27
27
28
Args:
28
- xy: x (EW) and y (NS) coordinates of the profile
29
- topography (:class:`gempy.core.grid_modules.topography.Topography`)
30
- method: interpolation method, 'interp2d' for cubic scipy.interpolate.interp2d
31
- 'spline' for scipy.interpolate.RectBivariateSpline
29
+ xy (np.ndarray): Array of shape (n, 2) containing x (EW) and y (NS) coordinates of the profile.
30
+ topography (Topography): An instance of Topography containing the DEM data.
32
31
33
32
Returns:
34
- numpy.ndarray: z values, i.e. topography along the profile
35
-
33
+ np.ndarray: z values, i.e., topography along the profile.
36
34
"""
37
-
38
35
xj = topography .values_2d [:, 0 , 0 ]
39
36
yj = topography .values_2d [0 , :, 1 ]
40
37
zj = topography .values_2d [:, :, 2 ]
41
- scipy = require_scipy ()
42
- if method == 'interp2d' :
43
- f = scipy .interpolate .interp2d (xj , yj , zj .T , kind = 'cubic' )
44
- zi = f (xy [:, 0 ], xy [:, 1 ])
45
- if xy [:, 0 ][0 ] <= xy [:, 0 ][- 1 ] and xy [:, 1 ][0 ] <= xy [:, 1 ][- 1 ]:
46
- return np .diag (zi )
47
- else :
48
- return np .flipud (zi ).diagonal ()
49
- else :
50
- assert xy [:, 0 ][0 ] <= xy [:, 0 ][
51
- - 1 ], 'The xy values of the first point must be smaller than second.' \
52
- 'Please use interp2d as method argument. Will be fixed.'
53
- assert xy [:, 1 ][0 ] <= xy [:, 1 ][
54
- - 1 ], 'The xy values of the first point must be smaller than second.' \
55
- 'Please use interp2d as method argument. Will be fixed.'
56
- f = scipy .interpolate .RectBivariateSpline (xj , yj , zj )
57
- zi = f (xy [:, 0 ], xy [:, 1 ])
58
- return np .flipud (zi ).diagonal ()
38
+
39
+ spline = RectBivariateSpline (xj , yj , zj )
40
+ zi = spline .ev (xy [:, 0 ], xy [:, 1 ])
41
+
42
+ return zi
0 commit comments