Skip to content

Commit b9aa563

Browse files
author
Miguel de la Varga
committed
[BUG/ENH] Making cross sections compatible with new scipy
1 parent ad87407 commit b9aa563

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

gempy/core/data/core_utils.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
from scipy.interpolate import RegularGridInterpolator, RectBivariateSpline
23

34
from gempy.optional_dependencies import require_scipy
45

@@ -20,39 +21,22 @@ def distance_2_points(p1, p2):
2021
return np.sqrt(np.diff((p1[0], p2[0])) ** 2 + np.diff((p1[1], p2[1])) ** 2)
2122

2223

23-
def interpolate_zvals_at_xy(xy, topography, method='interp2d'):
24+
def interpolate_zvals_at_xy(xy, topography, method='DEP'):
2425
"""
25-
Interpolates DEM values on a defined section
26+
Interpolates DEM values on a defined section.
2627
2728
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.
3231
3332
Returns:
34-
numpy.ndarray: z values, i.e. topography along the profile
35-
33+
np.ndarray: z values, i.e., topography along the profile.
3634
"""
37-
3835
xj = topography.values_2d[:, 0, 0]
3936
yj = topography.values_2d[0, :, 1]
4037
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

Comments
 (0)