Skip to content

Commit 4b1e16b

Browse files
committed
Update rips module, proto files, and Python examples
1 parent a9ead2a commit 4b1e16b

File tree

7 files changed

+151
-5
lines changed

7 files changed

+151
-5
lines changed

docs/proto/Case.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ service Case {
2121
rpc GetCaseInfo(CaseRequest) returns (CaseInfo) {}
2222
rpc GetPdmObject(CaseRequest) returns (PdmObject) {}
2323
rpc GetReservoirBoundingBox(CaseRequest) returns (BoundingBox) {}
24+
rpc GetDistanceToClosestFault(ClosestFaultRequest) returns (ClosestFault) {}
2425
}
2526

2627
message CaseRequest { int32 id = 1; }
@@ -103,3 +104,14 @@ message SelectedCell {
103104
}
104105

105106
message SelectedCells { repeated SelectedCell cells = 1; }
107+
108+
message ClosestFaultRequest {
109+
CaseRequest case_request = 1;
110+
Vec3d point = 2;
111+
}
112+
113+
message ClosestFault {
114+
string fault_name = 1;
115+
double distance = 2;
116+
string face_name = 3;
117+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
###################################################################################
2+
# This example prints the distance to and the name of the fault closest to a point
3+
###################################################################################
4+
5+
import rips
6+
7+
resinsight = rips.Instance.find()
8+
if resinsight is None:
9+
exit(1)
10+
11+
cases = resinsight.project.cases()
12+
if len(cases) == 0:
13+
exit(1)
14+
15+
case = cases[0]
16+
print("Using case: " + case.name)
17+
18+
# random test point (positive Z for depth)
19+
point_x = 5039.84
20+
point_y = 6303.76
21+
point_z = 4144.21
22+
23+
print("Looking for closest fault to point %f, %f, %f:" % (point_x, point_y, point_z))
24+
25+
faultname, distance, facename = case.distance_to_closest_fault(
26+
point_x, point_y, point_z
27+
)
28+
29+
if facename == "":
30+
print("- No fault found!")
31+
else:
32+
print(
33+
"- Distance to closest fault %s is %f, closest face direction is %s"
34+
% (faultname, distance, facename)
35+
)

docs/rips/case.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import Case_pb2_grpc
4444
import Commands_pb2 as Cmd
4545
import PdmObject_pb2 as PdmObject_pb2
46+
import Definitions_pb2
4647

4748
import Properties_pb2
4849
import Properties_pb2_grpc
@@ -300,6 +301,17 @@ def reservoir_boundingbox(self):
300301
return self.__case_stub.GetReservoirBoundingBox(self.__request())
301302

302303

304+
@add_method(Case)
305+
def distance_to_closest_fault(self, x: float, y: float, z: float):
306+
"""Find the closest fault to the given point and return the distance, fault name and fault face"""
307+
request = Case_pb2.ClosestFaultRequest(
308+
case_request=self.__request(), point=Definitions_pb2.Vec3d(x=x, y=y, z=z)
309+
)
310+
reply = self.__case_stub.GetDistanceToClosestFault(request)
311+
312+
return (reply.fault_name, reply.distance, reply.face_name)
313+
314+
303315
@add_method(Case)
304316
def reservoir_depth_range(self) -> Tuple[float, float]:
305317
"""Get the reservoir depth range

docs/rips/generated/Case_pb2.py

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/rips/generated/Case_pb2_grpc.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ def __init__(self, channel):
9696
request_serializer=Case__pb2.CaseRequest.SerializeToString,
9797
response_deserializer=Case__pb2.BoundingBox.FromString,
9898
_registered_method=True)
99+
self.GetDistanceToClosestFault = channel.unary_unary(
100+
'/rips.Case/GetDistanceToClosestFault',
101+
request_serializer=Case__pb2.ClosestFaultRequest.SerializeToString,
102+
response_deserializer=Case__pb2.ClosestFault.FromString,
103+
_registered_method=True)
99104

100105

101106
class CaseServicer(object):
@@ -173,6 +178,12 @@ def GetReservoirBoundingBox(self, request, context):
173178
context.set_details('Method not implemented!')
174179
raise NotImplementedError('Method not implemented!')
175180

181+
def GetDistanceToClosestFault(self, request, context):
182+
"""Missing associated documentation comment in .proto file."""
183+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
184+
context.set_details('Method not implemented!')
185+
raise NotImplementedError('Method not implemented!')
186+
176187

177188
def add_CaseServicer_to_server(servicer, server):
178189
rpc_method_handlers = {
@@ -236,6 +247,11 @@ def add_CaseServicer_to_server(servicer, server):
236247
request_deserializer=Case__pb2.CaseRequest.FromString,
237248
response_serializer=Case__pb2.BoundingBox.SerializeToString,
238249
),
250+
'GetDistanceToClosestFault': grpc.unary_unary_rpc_method_handler(
251+
servicer.GetDistanceToClosestFault,
252+
request_deserializer=Case__pb2.ClosestFaultRequest.FromString,
253+
response_serializer=Case__pb2.ClosestFault.SerializeToString,
254+
),
239255
}
240256
generic_handler = grpc.method_handlers_generic_handler(
241257
'rips.Case', rpc_method_handlers)
@@ -570,3 +586,30 @@ def GetReservoirBoundingBox(request,
570586
timeout,
571587
metadata,
572588
_registered_method=True)
589+
590+
@staticmethod
591+
def GetDistanceToClosestFault(request,
592+
target,
593+
options=(),
594+
channel_credentials=None,
595+
call_credentials=None,
596+
insecure=False,
597+
compression=None,
598+
wait_for_ready=None,
599+
timeout=None,
600+
metadata=None):
601+
return grpc.experimental.unary_unary(
602+
request,
603+
target,
604+
'/rips.Case/GetDistanceToClosestFault',
605+
Case__pb2.ClosestFaultRequest.SerializeToString,
606+
Case__pb2.ClosestFault.FromString,
607+
options,
608+
channel_credentials,
609+
insecure,
610+
call_credentials,
611+
compression,
612+
wait_for_ready,
613+
timeout,
614+
metadata,
615+
_registered_method=True)

docs/rips/tests/test_faults.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
import os
3+
import math
4+
import pytest
5+
6+
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
7+
import rips
8+
9+
import dataroot
10+
11+
12+
def test_faultDistance(rips_instance, initialize_test):
13+
case = rips_instance.project.load_case(
14+
dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
15+
)
16+
17+
# a test point
18+
point_x = 4817.84
19+
point_y = 5204.76
20+
point_z = 4137.21
21+
22+
faultname, distance, facename = case.distance_to_closest_fault(
23+
point_x, point_y, point_z
24+
)
25+
26+
# Fault name is unstable between grid readers, so we skip this check
27+
# assert faultname == "Undefined Grid Faults"
28+
29+
assert facename == "I+"
30+
assert math.isclose(distance, 53.84, abs_tol=0.1)

docs/source/PythonExamples_case_and_grid_operations.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ Export Corner Point Grid
6666
:linenos:
6767
:caption: export_corner_point_grid.py
6868

69+
.. _case_and_grid_operations_fault_distance:
70+
71+
Fault Distance
72+
--------------
73+
74+
.. literalinclude:: ../rips/PythonExamples/case_and_grid_operations/fault_distance.py
75+
:language: python
76+
:linenos:
77+
:caption: fault_distance.py
78+
6979
.. _case_and_grid_operations_grid_information:
7080

7181
Grid Information

0 commit comments

Comments
 (0)