Skip to content

Commit 7c107bc

Browse files
committed
Update rips module and Python examples
1 parent 5c282f6 commit 7c107bc

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

docs/rips/generated/RiaVersionInfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
RESINSIGHT_MAJOR_VERSION : str = "2025"
2020
RESINSIGHT_MINOR_VERSION : str = "09"
21-
RESINSIGHT_PATCH_VERSION : str = "2"
21+
RESINSIGHT_PATCH_VERSION : str = "3"
2222

2323
PYTHON_GRPC_PROTOC_VERSION : str = "libprotoc 31.1"

docs/rips/generated/generated_classes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,19 @@ def set_cell_result_data(self, values : List[float]) -> None:
16601660
self._call_set_method("CellResultData", values)
16611661

16621662

1663+
def visible_cells_internal(self, visibility_key: str="", time_step: int=0) -> None:
1664+
"""
1665+
Visible Cells Internal
1666+
1667+
Arguments:
1668+
visibility_key (str):
1669+
time_step (int):
1670+
Returns:
1671+
1672+
"""
1673+
self._call_pdm_method_void("visible_cells_internal", visibility_key=visibility_key, time_step=time_step)
1674+
1675+
16631676
class EclipseResult(PdmObjectBase):
16641677
"""
16651678
An eclipse result definition

docs/rips/tests/test_view.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import sys
2+
import os
3+
4+
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
5+
6+
import dataroot
7+
8+
9+
def test_visible_cells(rips_instance, initialize_test):
10+
"""Test the visible_cells() method on a view"""
11+
case_root_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC"
12+
case_path = case_root_path + "/TEST10K_FLT_LGR_NNC.EGRID"
13+
case = rips_instance.project.load_case(path=case_path)
14+
15+
# Get the first view or create one
16+
views = case.views()
17+
if views:
18+
view = views[0]
19+
else:
20+
view = case.create_view()
21+
22+
# Test visible_cells at time step 0
23+
visibility = view.visible_cells(time_step=0)
24+
25+
# Verify we got a list
26+
assert isinstance(visibility, list)
27+
28+
# Verify we have data
29+
assert len(visibility) > 0
30+
31+
# Verify all values are either 0 or 1
32+
for v in visibility:
33+
assert v in [0, 1]
34+
35+
# Count visible and invisible cells
36+
visible_count = sum(visibility)
37+
invisible_count = len(visibility) - visible_count
38+
39+
# Total cells should match grid size
40+
assert len(visibility) == visible_count + invisible_count
41+
42+
# The visibility array should have the correct size (can be all visible, all invisible, or mixed)
43+
# This depends on the view settings
44+
assert visible_count + invisible_count > 0
45+
46+
47+
def test_visible_cells_different_timesteps(rips_instance, initialize_test):
48+
"""Test visible_cells() at different time steps"""
49+
case_root_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC"
50+
case_path = case_root_path + "/TEST10K_FLT_LGR_NNC.EGRID"
51+
case = rips_instance.project.load_case(path=case_path)
52+
53+
view = case.views()[0] if case.views() else case.create_view()
54+
55+
# Test at time step 0
56+
visibility_ts0 = view.visible_cells(time_step=0)
57+
assert len(visibility_ts0) > 0
58+
59+
# Test at time step 1 (if it exists)
60+
visibility_ts1 = view.visible_cells(time_step=1)
61+
assert len(visibility_ts1) > 0
62+
63+
# Both should have the same number of cells
64+
assert len(visibility_ts0) == len(visibility_ts1)

docs/rips/view.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import Commands_pb2 as Cmd
66

7+
import uuid
8+
import rips.project
9+
710
import rips.case # Circular import of Case, which already imports View. Use full name.
811
from .pdmobject import add_method
912
from .resinsight_classes import (
@@ -211,6 +214,37 @@ def case(self):
211214
return None
212215

213216

217+
@add_method(View)
218+
def visible_cells(self, time_step=0):
219+
"""Get the visibility status of all cells in the view
220+
221+
Arguments:
222+
time_step (int): The time step to get visibility for. Defaults to 0.
223+
224+
Returns:
225+
List[int]: A list where 1 represents a visible cell and 0 represents an invisible cell
226+
"""
227+
228+
# Generate temporary key for key-value store
229+
visibility_key = f"{uuid.uuid4()}_visibility"
230+
231+
# Get the project
232+
project = self.ancestor(rips.project.Project)
233+
try:
234+
# Call internal method to store visibility data
235+
self.visible_cells_internal(visibility_key=visibility_key, time_step=time_step)
236+
237+
# Retrieve visibility data from key-value store
238+
visibility_values = project.key_values(visibility_key)
239+
240+
# Convert floats to integers (1 for visible, 0 for invisible)
241+
return [int(v) for v in visibility_values]
242+
243+
finally:
244+
# Clean up temporary key from key-value store
245+
project.remove_key_values(visibility_key)
246+
247+
214248
@add_method(ViewWindow)
215249
def export_snapshot(self, prefix="", export_folder=""):
216250
"""Export snapshot for the current view

0 commit comments

Comments
 (0)