mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
#12950 Add api for export cell visibility for a given view.
This commit is contained in:
1 parent
cf5da1ff7a
commit
8e6a96da00
5 files changed
+224
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
|
||||
import dataroot
|
||||
|
||||
|
||||
def test_visible_cells(rips_instance, initialize_test):
|
||||
"""Test the visible_cells() method on a view"""
|
||||
case_root_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC"
|
||||
case_path = case_root_path + "/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.load_case(path=case_path)
|
||||
|
||||
# Get the first view or create one
|
||||
views = case.views()
|
||||
if views:
|
||||
view = views[0]
|
||||
else:
|
||||
view = case.create_view()
|
||||
|
||||
# Test visible_cells at time step 0
|
||||
visibility = view.visible_cells(time_step=0)
|
||||
|
||||
# Verify we got a list
|
||||
assert isinstance(visibility, list)
|
||||
|
||||
# Verify we have data
|
||||
assert len(visibility) > 0
|
||||
|
||||
# Verify all values are either 0 or 1
|
||||
for v in visibility:
|
||||
assert v in [0, 1]
|
||||
|
||||
# Count visible and invisible cells
|
||||
visible_count = sum(visibility)
|
||||
invisible_count = len(visibility) - visible_count
|
||||
|
||||
# Total cells should match grid size
|
||||
assert len(visibility) == visible_count + invisible_count
|
||||
|
||||
# The visibility array should have the correct size (can be all visible, all invisible, or mixed)
|
||||
# This depends on the view settings
|
||||
assert visible_count + invisible_count > 0
|
||||
|
||||
|
||||
def test_visible_cells_different_timesteps(rips_instance, initialize_test):
|
||||
"""Test visible_cells() at different time steps"""
|
||||
case_root_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC"
|
||||
case_path = case_root_path + "/TEST10K_FLT_LGR_NNC.EGRID"
|
||||
case = rips_instance.project.load_case(path=case_path)
|
||||
|
||||
view = case.views()[0] if case.views() else case.create_view()
|
||||
|
||||
# Test at time step 0
|
||||
visibility_ts0 = view.visible_cells(time_step=0)
|
||||
assert len(visibility_ts0) > 0
|
||||
|
||||
# Test at time step 1 (if it exists)
|
||||
visibility_ts1 = view.visible_cells(time_step=1)
|
||||
assert len(visibility_ts1) > 0
|
||||
|
||||
# Both should have the same number of cells
|
||||
assert len(visibility_ts0) == len(visibility_ts1)
|
||||
@@ -4,6 +4,9 @@ ResInsight 3d view module
|
||||
|
||||
import Commands_pb2 as Cmd
|
||||
|
||||
import uuid
|
||||
import rips.project
|
||||
|
||||
import rips.case # Circular import of Case, which already imports View. Use full name.
|
||||
from .pdmobject import add_method
|
||||
from .resinsight_classes import (
|
||||
@@ -211,6 +214,37 @@ def case(self):
|
||||
return None
|
||||
|
||||
|
||||
@add_method(View)
|
||||
def visible_cells(self, time_step=0):
|
||||
"""Get the visibility status of all cells in the view
|
||||
|
||||
Arguments:
|
||||
time_step (int): The time step to get visibility for. Defaults to 0.
|
||||
|
||||
Returns:
|
||||
List[int]: A list where 1 represents a visible cell and 0 represents an invisible cell
|
||||
"""
|
||||
|
||||
# Generate temporary key for key-value store
|
||||
visibility_key = f"{uuid.uuid4()}_visibility"
|
||||
|
||||
# Get the project
|
||||
project = self.ancestor(rips.project.Project)
|
||||
try:
|
||||
# Call internal method to store visibility data
|
||||
self.visible_cells_internal(visibility_key=visibility_key, time_step=time_step)
|
||||
|
||||
# Retrieve visibility data from key-value store
|
||||
visibility_values = project.key_values(visibility_key)
|
||||
|
||||
# Convert floats to integers (1 for visible, 0 for invisible)
|
||||
return [int(v) for v in visibility_values]
|
||||
|
||||
finally:
|
||||
# Clean up temporary key from key-value store
|
||||
project.remove_key_values(visibility_key)
|
||||
|
||||
|
||||
@add_method(ViewWindow)
|
||||
def export_snapshot(self, prefix="", export_folder=""):
|
||||
"""Export snapshot for the current view
|
||||
|
||||
Reference in new issue
Block a user