#13982 Python: Demonstrate string form alongside StrEnum in examples and tests

The property/porosity/data-type arguments accept either a typed StrEnum
(rips.PropertyType.DYNAMIC_NATIVE) or a plain string ("DYNAMIC_NATIVE").
Keep both forms visible to users:

- soil_average_sync.py and input_prop_test_sync.py now use string
  arguments and point at their _async counterparts for the typed-enum
  form. The sync/async examples otherwise mirror each other, so each
  pair documents one form.

- Add test_10k_property_strings to exercise available_properties,
  active_cell_property, grid_property, and set_active_cell_property
  (including data_type="INTEGER") with strings only, so a future
  refactor that narrows the accepted types would fail the suite.
This commit is contained in:
Kristian Bendiksen committed 2026-05-13 13:47:40 +02:00
1 parent e7608536cf
commit b775f42057
3 files changed
+40 -7

No files matched your search

@@ -2,6 +2,11 @@
# This example generates a derived property in an synchronous manner
# Meaning it completes reading each result before calculating the derived result
# See InputPropTestAsync for how to do this asynchronously instead.
#
# Property/porosity/result types accept either a typed enum
# (rips.PropertyType.STATIC_NATIVE) or a plain string ("STATIC_NATIVE"). This
# example uses the string form; see input_prop_test_async.py for the typed-enum
# form.
########################################################################################
import rips
import time
@@ -12,9 +17,9 @@ start = time.time()
case = resinsight.project.cases()[0]
# Read poro result into list
poro_results = case.active_cell_property(rips.PropertyType.STATIC_NATIVE, "PORO", 0)
poro_results = case.active_cell_property("STATIC_NATIVE", "PORO", 0)
# Read permx result into list
permx_results = case.active_cell_property(rips.PropertyType.STATIC_NATIVE, "PERMX", 0)
permx_results = case.active_cell_property("STATIC_NATIVE", "PERMX", 0)
# Generate output result
results = []
@@ -23,9 +28,7 @@ for poro, permx in zip(poro_results, permx_results):
try:
# Send back output result
case.set_active_cell_property(
results, rips.PropertyType.GENERATED, "POROPERMXSY", 0
)
case.set_active_cell_property(results, "GENERATED", "POROPERMXSY", 0)
except grpc.RpcError as e:
print("Exception Received: ", e)
@@ -34,4 +37,4 @@ end = time.time()
print("Time elapsed: ", end - start)
print("Transferred all results back")
view = case.views()[0].apply_cell_result(rips.ResultType.GENERATED, "POROPERMXSY")
view = case.views()[0].apply_cell_result("GENERATED", "POROPERMXSY")
@@ -1,5 +1,9 @@
###########################################################################################
# This example will synchronously calculate the average value for SOIL for all time steps
#
# Property/porosity types accept either a typed enum (rips.PropertyType.DYNAMIC_NATIVE) or
# a plain string ("DYNAMIC_NATIVE"). This example uses the string form; see
# soil_average_async.py for the typed-enum form.
###########################################################################################
import rips
import time
@@ -17,7 +21,7 @@ time_steps = case.time_steps()
averages = []
for i in range(0, len(time_steps)):
# Get a list of all the results for time step i
results = case.active_cell_property(rips.PropertyType.DYNAMIC_NATIVE, "SOIL", i)
results = case.active_cell_property("DYNAMIC_NATIVE", "SOIL", i)
mysum = sum(results)
averages.append(mysum / len(results))
@@ -158,6 +158,32 @@ def test_10k_set_integer_grid_property(rips_instance, initialize_test):
assert expected == int(actual)
def test_10k_property_strings(rips_instance, initialize_test):
# Backward-compat coverage: the property/porosity/data-type arguments accept
# plain strings as an alternative to the typed StrEnum classes. This test
# exercises only the string form end-to-end so a future refactor that
# accidentally narrows the accepted types would be caught.
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=casePath)
available = case.available_properties("STATIC_NATIVE", "MATRIX_MODEL")
assert "PORO" in available
assert "PERMX" in available
poro = case.active_cell_property("STATIC_NATIVE", "PORO", 0)
assert len(poro) > 0
grid_poro = case.grid_property("STATIC_NATIVE", "PORO", 0)
assert len(grid_poro) > 0
integer_values = [int(v * 100) for v in poro]
case.set_active_cell_property(
integer_values, "GENERATED", "MY_STRING_DISCRETE", 0, data_type="INTEGER"
)
round_trip = case.active_cell_property("GENERATED", "MY_STRING_DISCRETE", 0)
assert len(round_trip) == len(integer_values)
def test_exportPropertyInView(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(case_path)