Skip to content

Commit e23db6f

Browse files
committed
Update rips module and Python examples
1 parent a456e51 commit e23db6f

19 files changed

+607
-14
lines changed

docs/rips/PythonExamples/surfaces_and_visualization/create_intersection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
intersection.update()
2424

2525
# Add a new modeled well path
26-
well_path_coll = resinsight.project.descendants(rips.WellPathCollection)[0]
26+
well_path_coll = resinsight.project.well_path_collection()
2727
well_path = well_path_coll.add_new_object(rips.ModeledWellPath)
2828
well_path.name = "Test Well-1"
2929
well_path.update()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
###################################################################################
2+
# This example will connect to ResInsight, extract trajectory properties for
3+
# each wells in the project, and extract some properties for each points on the
4+
# trajectory.
5+
#
6+
###################################################################################
7+
8+
import rips
9+
10+
11+
def print_dictionary(title, data):
12+
# Dictionary of lists of floats.
13+
keys = list(data.keys())
14+
15+
print(title)
16+
for i, properties in enumerate(zip(*data.values()), 1):
17+
prop_pairs = [
18+
f"{key.replace('coordinate_', '')}={prop:.3f}"
19+
for key, prop in zip(keys, properties)
20+
]
21+
print(f"Point {i}: {', '.join(prop_pairs)}")
22+
23+
24+
# Connect to ResInsight
25+
resinsight = rips.Instance.find()
26+
if resinsight is not None:
27+
# Get a list of all wells
28+
wells = resinsight.project.well_paths()
29+
30+
# Find the first case
31+
cases = resinsight.project.cases()
32+
c = cases[0] if len(cases) else None
33+
34+
for well in wells:
35+
result = well.trajectory_properties(resampling_interval=10.0)
36+
37+
if c:
38+
# Convert the result data into points
39+
positions = [
40+
list(coord)
41+
for coord in zip(
42+
result["coordinate_x"],
43+
result["coordinate_y"],
44+
result["coordinate_z"],
45+
)
46+
]
47+
48+
# Extract some properties
49+
properties = [
50+
("DYNAMIC_NATIVE", "PRESSURE", 0),
51+
("STATIC_NATIVE", "FAULTDIST", 0),
52+
]
53+
54+
for property_type, property_name, time_step in properties:
55+
porosity_model = "MATRIX_MODEL"
56+
result[property_name] = c.grid_property_for_positions(
57+
positions, property_type, property_name, time_step, porosity_model
58+
)
59+
60+
title = "Well name: " + well.name
61+
print_dictionary(title, result)

docs/rips/PythonExamples/wells_and_fractures/fishbones_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# The coordinates are based on the Norne case
99
# Add a lateral to the main well path
1010

11-
well_path_coll = resinsight.project.descendants(rips.WellPathCollection)[0]
11+
well_path_coll = resinsight.project.well_path_collection()
1212

1313
editable_well_paths = well_path_coll.descendants(rips.ModeledWellPath)
1414
if editable_well_paths:

docs/rips/PythonExamples/wells_and_fractures/modeled_well_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Create a modeled well path and add well path targets
88
# The coordinates are based on the Norne case
99

10-
well_path_coll = resinsight.project.descendants(rips.WellPathCollection)[0]
10+
well_path_coll = resinsight.project.well_path_collection()
1111
well_path = well_path_coll.add_new_object(rips.ModeledWellPath)
1212
well_path.name = "Test Well-1"
1313
well_path.update()

docs/rips/PythonExamples/wells_and_fractures/modeled_well_path_lateral.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# The coordinates are based on the Norne case
1010
# Add a lateral to the main well path
1111

12-
well_path_coll = resinsight.project.descendants(rips.WellPathCollection)[0]
12+
well_path_coll = resinsight.project.well_path_collection()
1313
well_path = well_path_coll.add_new_object(rips.ModeledWellPath)
1414
well_path.name = "Test Well-1"
1515
well_path.update()

docs/rips/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
GeoMechContourMap as GeoMechContourMap,
1717
)
1818
from .well_log_plot import WellLogPlot as WellLogPlot
19+
from .well_path import WellPath as WellPath
1920
from .simulation_well import SimulationWell as SimulationWell
2021
from .exception import RipsError as RipsError
2122
from .surface import RegularSurface as RegularSurface

docs/rips/case.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"""
3737

3838
import grpc
39+
import uuid
3940
from typing import List, Tuple
4041

4142
import Case_pb2
@@ -56,6 +57,7 @@
5657
)
5758

5859
from .grid import Grid as Grid
60+
from .project import Project as Project
5961
from .pdmobject import add_method
6062
from .view import View as View
6163
from .simulation_well import SimulationWell
@@ -1332,3 +1334,55 @@ def set_nnc_connections_values(
13321334
reply = self.__nnc_properties_stub.SetNNCValues(request_iterator)
13331335
if reply.accepted_value_count < len(values):
13341336
raise IndexError
1337+
1338+
1339+
@add_method(EclipseCase)
1340+
def grid_property_for_positions(
1341+
self,
1342+
positions: List[List[float]],
1343+
property_type: str,
1344+
property_name: str,
1345+
time_step: int,
1346+
porosity_model: str = "MATRIX_MODEL",
1347+
) -> List[float]:
1348+
shared_uuid = uuid.uuid4()
1349+
coordinate_x = "{}_{}".format(shared_uuid, "coordinate_x")
1350+
coordinate_y = "{}_{}".format(shared_uuid, "coordinate_y")
1351+
coordinate_z = "{}_{}".format(shared_uuid, "coordinate_z")
1352+
result_key = "{}_{}".format(shared_uuid, "result")
1353+
1354+
coord_x = []
1355+
coord_y = []
1356+
coord_z = []
1357+
for pos in positions:
1358+
coord_x.append(pos[0])
1359+
coord_y.append(pos[1])
1360+
coord_z.append(pos[2])
1361+
1362+
# Get the results from the key-value store.
1363+
project = self.ancestor(Project)
1364+
if project:
1365+
project.set_key_values(coordinate_x, coord_x)
1366+
project.set_key_values(coordinate_y, coord_y)
1367+
project.set_key_values(coordinate_z, coord_z)
1368+
1369+
self.export_values_internal(
1370+
coordinate_x=coordinate_x,
1371+
coordinate_y=coordinate_y,
1372+
coordinate_z=coordinate_z,
1373+
result_key=result_key,
1374+
property_type=property_type,
1375+
property_name=property_name,
1376+
time_step=time_step,
1377+
porosity_model=porosity_model,
1378+
)
1379+
result = project.key_values(result_key)
1380+
1381+
project.remove_key_values(coordinate_x)
1382+
project.remove_key_values(coordinate_y)
1383+
project.remove_key_values(coordinate_z)
1384+
project.remove_key_values(result_key)
1385+
1386+
return result
1387+
else:
1388+
return []

docs/rips/generated/KeyValueStore_pb2.py

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

docs/rips/generated/KeyValueStore_pb2_grpc.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ def __init__(self, channel):
4545
request_serializer=KeyValueStore__pb2.KeyValueStoreInputChunk.SerializeToString,
4646
response_deserializer=Definitions__pb2.ClientToServerStreamReply.FromString,
4747
_registered_method=True)
48+
self.GetValue = channel.unary_stream(
49+
'/rips.KeyValueStore/GetValue',
50+
request_serializer=KeyValueStore__pb2.KeyValueStoreOutputRequest.SerializeToString,
51+
response_deserializer=KeyValueStore__pb2.KeyValueStoreOutputChunk.FromString,
52+
_registered_method=True)
53+
self.RemoveValue = channel.unary_unary(
54+
'/rips.KeyValueStore/RemoveValue',
55+
request_serializer=KeyValueStore__pb2.KeyValueStoreRemoveRequest.SerializeToString,
56+
response_deserializer=Definitions__pb2.Empty.FromString,
57+
_registered_method=True)
4858

4959

5060
class KeyValueStoreServicer(object):
@@ -56,6 +66,18 @@ def SetValue(self, request_iterator, context):
5666
context.set_details('Method not implemented!')
5767
raise NotImplementedError('Method not implemented!')
5868

69+
def GetValue(self, request, context):
70+
"""Missing associated documentation comment in .proto file."""
71+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
72+
context.set_details('Method not implemented!')
73+
raise NotImplementedError('Method not implemented!')
74+
75+
def RemoveValue(self, request, context):
76+
"""Missing associated documentation comment in .proto file."""
77+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
78+
context.set_details('Method not implemented!')
79+
raise NotImplementedError('Method not implemented!')
80+
5981

6082
def add_KeyValueStoreServicer_to_server(servicer, server):
6183
rpc_method_handlers = {
@@ -64,6 +86,16 @@ def add_KeyValueStoreServicer_to_server(servicer, server):
6486
request_deserializer=KeyValueStore__pb2.KeyValueStoreInputChunk.FromString,
6587
response_serializer=Definitions__pb2.ClientToServerStreamReply.SerializeToString,
6688
),
89+
'GetValue': grpc.unary_stream_rpc_method_handler(
90+
servicer.GetValue,
91+
request_deserializer=KeyValueStore__pb2.KeyValueStoreOutputRequest.FromString,
92+
response_serializer=KeyValueStore__pb2.KeyValueStoreOutputChunk.SerializeToString,
93+
),
94+
'RemoveValue': grpc.unary_unary_rpc_method_handler(
95+
servicer.RemoveValue,
96+
request_deserializer=KeyValueStore__pb2.KeyValueStoreRemoveRequest.FromString,
97+
response_serializer=Definitions__pb2.Empty.SerializeToString,
98+
),
6799
}
68100
generic_handler = grpc.method_handlers_generic_handler(
69101
'rips.KeyValueStore', rpc_method_handlers)
@@ -100,3 +132,57 @@ def SetValue(request_iterator,
100132
timeout,
101133
metadata,
102134
_registered_method=True)
135+
136+
@staticmethod
137+
def GetValue(request,
138+
target,
139+
options=(),
140+
channel_credentials=None,
141+
call_credentials=None,
142+
insecure=False,
143+
compression=None,
144+
wait_for_ready=None,
145+
timeout=None,
146+
metadata=None):
147+
return grpc.experimental.unary_stream(
148+
request,
149+
target,
150+
'/rips.KeyValueStore/GetValue',
151+
KeyValueStore__pb2.KeyValueStoreOutputRequest.SerializeToString,
152+
KeyValueStore__pb2.KeyValueStoreOutputChunk.FromString,
153+
options,
154+
channel_credentials,
155+
insecure,
156+
call_credentials,
157+
compression,
158+
wait_for_ready,
159+
timeout,
160+
metadata,
161+
_registered_method=True)
162+
163+
@staticmethod
164+
def RemoveValue(request,
165+
target,
166+
options=(),
167+
channel_credentials=None,
168+
call_credentials=None,
169+
insecure=False,
170+
compression=None,
171+
wait_for_ready=None,
172+
timeout=None,
173+
metadata=None):
174+
return grpc.experimental.unary_unary(
175+
request,
176+
target,
177+
'/rips.KeyValueStore/RemoveValue',
178+
KeyValueStore__pb2.KeyValueStoreRemoveRequest.SerializeToString,
179+
Definitions__pb2.Empty.FromString,
180+
options,
181+
channel_credentials,
182+
insecure,
183+
call_credentials,
184+
compression,
185+
wait_for_ready,
186+
timeout,
187+
metadata,
188+
_registered_method=True)

0 commit comments

Comments
 (0)