Skip to content

Commit

Permalink
Updated python API for 2024.03
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Mar 25, 2024
1 parent 1e73b05 commit 6ca9162
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/rips/contour_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
ResInsight 3d contour map module
"""

import Commands_pb2

from .pdmobject import add_method
Expand Down
4 changes: 2 additions & 2 deletions docs/rips/generated/PdmObject_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions docs/rips/generated/PdmObject_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def __init__(self, channel):
request_serializer=PdmObject__pb2.PdmObjectMethodRequest.SerializeToString,
response_deserializer=PdmObject__pb2.PdmObject.FromString,
)
self.DeleteExistingPdmObject = channel.unary_unary(
'/rips.PdmObjectService/DeleteExistingPdmObject',
request_serializer=PdmObject__pb2.PdmObject.SerializeToString,
response_deserializer=Definitions__pb2.Empty.FromString,
)


class PdmObjectServiceServicer(object):
Expand Down Expand Up @@ -108,6 +113,12 @@ def CallPdmObjectMethod(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def DeleteExistingPdmObject(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_PdmObjectServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand Down Expand Up @@ -151,6 +162,11 @@ def add_PdmObjectServiceServicer_to_server(servicer, server):
request_deserializer=PdmObject__pb2.PdmObjectMethodRequest.FromString,
response_serializer=PdmObject__pb2.PdmObject.SerializeToString,
),
'DeleteExistingPdmObject': grpc.unary_unary_rpc_method_handler(
servicer.DeleteExistingPdmObject,
request_deserializer=PdmObject__pb2.PdmObject.FromString,
response_serializer=Definitions__pb2.Empty.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'rips.PdmObjectService', rpc_method_handlers)
Expand Down Expand Up @@ -296,3 +312,20 @@ def CallPdmObjectMethod(request,
PdmObject__pb2.PdmObject.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def DeleteExistingPdmObject(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/rips.PdmObjectService/DeleteExistingPdmObject',
PdmObject__pb2.PdmObject.SerializeToString,
Definitions__pb2.Empty.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
4 changes: 2 additions & 2 deletions docs/rips/generated/RiaVersionInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# Python version of RiaVersionInfo.h
# Just sets version constants

RESINSIGHT_MAJOR_VERSION : str = "2023"
RESINSIGHT_MINOR_VERSION : str = "12"
RESINSIGHT_MAJOR_VERSION : str = "2024"
RESINSIGHT_MINOR_VERSION : str = "03"
RESINSIGHT_PATCH_VERSION : str = "0"

PYTHON_GRPC_PROTOC_VERSION : str = "libprotoc 23.4"
13 changes: 11 additions & 2 deletions docs/rips/generated/generated_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CurveIntersection(PdmObjectBase):
name (str): Name
points (List[List[float]]): Points
simulation_well (Optional[SimulationWell]): Simulation Well
type (str): One of [CS_WELL_PATH, CS_SIMULATION_WELL, CS_POLYLINE, CS_AZIMUTHLINE]
type (str): One of [CS_WELL_PATH, CS_SIMULATION_WELL, CS_POLYLINE, CS_AZIMUTHLINE, CS_POLYGON]
well_path (Optional[WellPath]): Well Path
"""
__custom_init__ = None #: Assign a custom init routine to be run at __init__
Expand Down Expand Up @@ -461,7 +461,7 @@ def __init__(self, pb2_object: Optional[PdmObject_pb2.PdmObject]=None, channel:
self.id: int = -1
self.name_setting: str = "FULL_CASE_NAME"
self.short_name: str = ""
self.show_sub_nodes_in_tree: bool = False
self.show_sub_nodes_in_tree: bool = True
self.summary_header_filename: Optional[str] = None
PdmObjectBase.__init__(self, pb2_object, channel)
if SummaryCase.__custom_init__ is not None:
Expand Down Expand Up @@ -1133,6 +1133,14 @@ def __init__(self, pb2_object: Optional[PdmObject_pb2.PdmObject]=None, channel:
if EclipseContourMap.__custom_init__ is not None:
EclipseContourMap.__custom_init__(self, pb2_object=pb2_object, channel=channel)

class RimEmCase(Reservoir):
__custom_init__ = None #: Assign a custom init routine to be run at __init__

def __init__(self, pb2_object: Optional[PdmObject_pb2.PdmObject]=None, channel: Optional[grpc.Channel]=None) -> None:
Reservoir.__init__(self, pb2_object, channel)
if RimEmCase.__custom_init__ is not None:
RimEmCase.__custom_init__(self, pb2_object=pb2_object, channel=channel)

class GeoMechContourMap(GeoMechView):
"""
A contour map for GeoMech cases
Expand Down Expand Up @@ -2308,6 +2316,7 @@ def class_dict() -> Dict[str, Type[PdmObjectBase]]:
classes['Project'] = Project
classes['ResampleData'] = ResampleData
classes['Reservoir'] = Reservoir
classes['RimEmCase'] = RimEmCase
classes['RimRoffCase'] = RimRoffCase
classes['RimStatisticalCalculation'] = RimStatisticalCalculation
classes['RimTextAnnotation'] = RimTextAnnotation
Expand Down
4 changes: 2 additions & 2 deletions docs/rips/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ def _check_connection_and_version(
raise Exception(
"Error: Wrong Version of ResInsight at ",
location,
self.version_string(),
"Executable : " + self.version_string(),
" ",
self.client_version_string(),
"rips : " + self.client_version_string(),
)

def __version_message(self) -> App_pb2.Version:
Expand Down
10 changes: 10 additions & 0 deletions docs/rips/pdmobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,13 @@ def update(self) -> None:
raise Exception(
"Object is not connected to GRPC service so cannot update ResInsight"
)

def delete(self) -> None:
"""Delete object in ResInsight"""
self.__copy_to_pb2()
if self._pdm_object_stub is not None:
self._pdm_object_stub.DeleteExistingPdmObject(self._pb2_object)
else:
raise Exception(
"Object is not connected to GRPC service so cannot update ResInsight"
)
1 change: 1 addition & 0 deletions docs/rips/plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
ResInsight 2d plot module
"""

import Commands_pb2

from .pdmobject import add_method
Expand Down
1 change: 1 addition & 0 deletions docs/rips/simulation_well.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
ResInsight SimulationWell
"""

import grpc

import SimulationWell_pb2
Expand Down
27 changes: 27 additions & 0 deletions docs/rips/tests/test_object_lifetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
import os

sys.path.insert(1, os.path.join(sys.path[0], "../../"))
import rips


def test_well_path(rips_instance, initialize_test):
well_path_coll = rips_instance.project.descendants(rips.WellPathCollection)[0]
assert len(well_path_coll.well_paths()) is 0

well_path = well_path_coll.add_new_object(rips.ModeledWellPath)
well_path2 = well_path_coll.add_new_object(rips.ModeledWellPath)
assert len(well_path_coll.well_paths()) is 2

well_path.delete()
assert len(well_path_coll.well_paths()) is 1

try:
# Delete again should throw exception
well_path.delete()
assert False
except Exception:
assert True

well_path2.delete()
assert len(well_path_coll.well_paths()) is 0

0 comments on commit 6ca9162

Please sign in to comment.