Skip to content

Commit 57a9633

Browse files
committed
- [WIP/CLN] Reimplementation nearest_surfaces_points
1 parent 5ac6447 commit 57a9633

File tree

3 files changed

+45
-51
lines changed

3 files changed

+45
-51
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from ._orientations_generator import select_nearest_surfaces_points

gempy_plugins/orientations_generator/_orientations_generator.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1+
import enum
2+
from typing import Optional
3+
14
import numpy as np
25
from sklearn.neighbors import NearestNeighbors
36
from sklearn.preprocessing import normalize
47

58

6-
def select_nearest_surfaces_points(geo_model, surface_points, searchcrit):
9+
class NearestSurfacePointsSearcher(enum.Enum):
10+
KNN = 1
11+
RADIUS = 2
12+
13+
14+
def select_nearest_surfaces_points(surface_points_xyz: np.ndarray, searchcrit: Optional[int|float] = 3,
15+
search_type: NearestSurfacePointsSearcher = NearestSurfacePointsSearcher.KNN
16+
) -> np.ndarray:
17+
match search_type:
18+
case NearestSurfacePointsSearcher.KNN:
19+
Tree = NearestNeighbors(n_neighbors=searchcrit)
20+
Tree.fit(surface_points_xyz)
21+
neighbours_surfaces = Tree.kneighbors(surface_points_xyz, n_neighbors=searchcrit, return_distance=False)
22+
case NearestSurfacePointsSearcher.RADIUS:
23+
Tree = NearestNeighbors(radius=searchcrit)
24+
Tree.fit(surface_points_xyz)
25+
neighbours_surfaces = Tree.radius_neighbors(surface_points_xyz, radius=searchcrit, return_distance=False)
26+
case _:
27+
raise ValueError(f"Invalid search type: {search_type}")
28+
29+
return neighbours_surfaces
30+
31+
32+
def _select_nearest_surfaces_points(geo_model, surface_points, searchcrit):
733
"""
834
Find the neighbour points of the same surface
935
by given radius (radius-search) or fix number (knn).
@@ -72,7 +98,6 @@ def set_orientation_from_neighbours(geo_model, neighbours):
7298
point-neighbours-id, first id is the point itself.
7399
"""
74100

75-
76101
# compute normal vector for the point
77102
if neighbours.size > 2:
78103
# extract point coordinates

tests/test_orientations_from_surface_points.py

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import numpy as np
33
import os
44

5-
from orientations_generator._orientations_generator import select_nearest_surfaces_points
5+
from orientations_generator import select_nearest_surfaces_points
6+
from orientations_generator._orientations_generator import NearestSurfacePointsSearcher
67

78
input_path = os.path.dirname(__file__) + '/../../examples/data'
89

@@ -38,67 +39,34 @@ def test_set_orientations():
3839

3940

4041
def test_select_nearest_surface_points():
41-
data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'
42-
path_to_data = data_path + "/data/input_data/jan_models/"
43-
44-
geo_data = gp.create_data_legacy('fault', extent=[0, 1000, 0, 1000, 0, 1000],
45-
resolution=[50, 50, 50],
46-
path_o=path_to_data + "model5_orientations.csv",
47-
path_i=path_to_data + "model5_surface_points.csv")
4842

4943
geo_model = _model_factory()
5044
print(geo_model)
51-
52-
# detect fault names
53-
f_id = geo_data._faults.df.index.categories[
54-
geo_data._faults.df.isFault.values]
55-
# find fault points
56-
fault_poi = geo_data._surface_points.df[
57-
geo_data._surface_points.df.series.isin(f_id)]
45+
46+
# TODO: This is to select the surface points we want to use to calculate the orientations
47+
48+
element: gp.data.StructuralElement = geo_model.structural_frame.get_element_by_name("fault")
5849

5950
# find neighbours
6051
knn = select_nearest_surfaces_points(
61-
geo_model=geo_data,
62-
surface_points=fault_poi,
63-
searchcrit=1
52+
surface_points_xyz=element.surface_points.xyz,
53+
searchcrit=3
6454
)
6555

6656
radius = select_nearest_surfaces_points(
67-
geo_model=geo_data,
68-
surface_points=fault_poi,
69-
searchcrit=200.
57+
surface_points_xyz=element.surface_points.xyz,
58+
searchcrit=200.,
59+
search_type=NearestSurfacePointsSearcher.RADIUS
7060
)
71-
72-
# sort neighbours, necessary for equal testing
73-
knn = [k.sort_values() for k in knn]
74-
radius = [r.sort_values() for r in radius]
75-
76-
# define reference
77-
reference = [[16, 17], [16, 17], [18, 19], [18, 19], [20, 21], [20, 21]]
78-
79-
assert np.array_equal(reference, knn) and np.array_equal(reference, radius)
61+
62+
return knn
8063

8164

8265
def test_set_orientation_from_neighbours():
83-
data_path = 'https://raw.githubusercontent.com/cgre-aachen/gempy_data/master/'
84-
path_to_data = data_path + "/data/input_data/jan_models/"
85-
86-
geo_data = gp.create_data_legacy('fault', extent=[0, 1000, 0, 1000, 0, 1000],
87-
resolution=[50, 50, 50],
88-
path_o=path_to_data + "model5_orientations.csv",
89-
path_i=path_to_data + "model5_surface_points.csv")
90-
91-
# Assigning series to formations as well as their order (timewise)
92-
gp.map_stack_to_surfaces(geo_data, {"Fault_Series": 'fault',
93-
"Strat_Series": ('rock2', 'rock1')})
94-
geo_data.set_is_fault(['Fault_Series'])
95-
96-
# detect fault names
97-
f_id = geo_data._faults.df.index.categories[
98-
geo_data._faults.df.isFault.values]
99-
# find fault points
100-
fault_poi = geo_data._surface_points.df[
101-
geo_data._surface_points.df.series.isin(f_id)]
66+
67+
68+
69+
10270
# find neighbours
10371
neighbours = gp.select_nearest_surfaces_points(geo_data, fault_poi, 5)
10472
# calculate one fault orientation

0 commit comments

Comments
 (0)