Surfaces And Visualization

This page shows Python examples from the surfaces_and_visualization folder.

Create Intersection

create_intersection.py
 1# Load ResInsight Processing Server Client Library
 2import rips
 3
 4resinsight = rips.Instance.find()
 5
 6# The coordinates in this example is based on the Drogon test case from Equinor
 7file_path = "e:/models/from_equinor_sftp/drogon-real0-iter3/DROGON-0.EGRID"
 8
 9case = resinsight.project.load_case(file_path)
10
11view = case.create_view()
12view.set_time_step(2)
13
14intersection_coll = resinsight.project.descendants(rips.IntersectionCollection)[0]
15
16# Add a CurveIntersection and set coordinates for the polyline
17intersection = intersection_coll.add_new_object(rips.CurveIntersection)
18intersection.points = [
19    [45854, 595757, 1500],
20    [46493, 534259.1, 1500],
21    [46598, 590044.1, 1500],
22]
23intersection.update()
24
25# Add a new modeled well path
26well_path_coll = resinsight.project.well_path_collection()
27well_path = well_path_coll.add_new_object(rips.ModeledWellPath)
28well_path.name = "Test Well-1"
29well_path.update()
30
31# Set reference coordinate
32geometry = well_path.well_path_geometry()
33reference_point = geometry.reference_point
34reference_point[0] = 458580
35reference_point[1] = 5935514
36reference_point[2] = 1742
37geometry.update()  # Commit updates back to ResInsight
38
39# Create the first well target at the reference point
40coord = [0, 0, 0]
41geometry.append_well_target(coord)
42
43# Append well target with fixed azimuth
44coord = [2229.10, -833.74, -74.70]
45target = geometry.append_well_target(
46    coord, use_fixed_azimuth=True, fixed_azimuth_value=45.1
47)
48
49# Append well target with fixed inclination
50coord = [3403.15, -1938.61, -80.93]
51target = geometry.append_well_target(
52    coord, use_fixed_inclination=True, fixed_inclination_value=115.2
53)
54
55coord = [4577.21, -3043.47, -87.15]
56target = geometry.append_well_target(coord)
57geometry.update()
58
59# Read out estimated dogleg and azimuth/inclination for well targets
60for w in geometry.well_path_targets():
61    print(
62        "DL1:{}   DL2:{}   Azi: {}   Incl: {}".format(
63            w.estimated_dogleg1,
64            w.estimated_dogleg2,
65            w.estimated_azimuth,
66            w.estimated_inclination,
67        )
68    )
69
70# Add a curve intersection based on the modeled well path
71well_path_intersection = intersection_coll.add_new_object(rips.CurveIntersection)
72well_path_intersection.type = "CS_WELL_PATH"
73well_path_intersection.well_path = well_path
74well_path_intersection.update()

Create Polygon

create_polygon.py
 1###################################################################################
 2# This example will connect to ResInsight, find bounding box and add a polygon
 3#
 4###################################################################################
 5
 6# Import the ResInsight Processing Server Module
 7import rips
 8
 9# Connect to ResInsight
10resinsight = rips.Instance.find()
11if resinsight is not None:
12    # Get a list of all cases
13    cases = resinsight.project.cases()
14
15    for c in cases:
16        print("Case name: " + c.name)
17
18        # create a polygon which is same a the bounding box in x and y.
19        # depth is set to middle of the bounding box
20        bbox = c.reservoir_boundingbox()
21        depth = bbox.max_z - ((bbox.max_z - bbox.min_z) / 2.0)
22
23        coordinates = []
24        coordinates.append([bbox.min_x, bbox.min_y, depth])
25        coordinates.append([bbox.max_x, bbox.min_y, depth])
26        coordinates.append([bbox.max_x, bbox.max_y, depth])
27        coordinates.append([bbox.min_x, bbox.max_y, depth])
28
29        polygon_collection = resinsight.project.descendants(rips.PolygonCollection)[0]
30        p = polygon_collection.create_polygon(
31            name="{} bounding box".format(c.name), coordinates=coordinates
32        )
33        print("Coordinates for {}:".format(p.name))
34        for coord in p.coordinates:
35            print(coord)

Create Regular Surface

create_regular_surface.py
 1######################################################################
 2# This script creates a regular surface for each case
 3######################################################################
 4import rips
 5import math
 6
 7
 8def create_x_surface(nx, ny):
 9    surface = []
10    for j in range(ny):
11        for i in range(nx):
12            surface.append(float(i))
13    return surface
14
15
16def create_wave_surface(nx, ny):
17    # Fill the coordinate and wave pattern arrays
18    surface = []
19    for j in range(ny):
20        for i in range(nx):
21            # Create wave pattern - combining multiple sine waves
22            x = -5 + 10 * i / (nx - 1)
23            y = -5 + 10 * j / (ny - 1)
24            offset = (
25                math.sin(x**2 + y**2)
26                + 0.5 * math.sin(2 * x) * math.cos(2 * y)
27                + 25.0 * math.cos(5 * x + 2 * y)
28            )
29            surface.append(-depth + offset)
30    return surface
31
32
33resinsight = rips.Instance.find()
34
35project = resinsight.project
36
37
38if resinsight is not None:
39    # Get a list of all cases
40    cases = resinsight.project.cases()
41
42    for c in cases:
43        bbox = c.reservoir_boundingbox()
44        depth = bbox.max_z - ((bbox.max_z - bbox.min_z) / 2.0)
45
46        origin_x = bbox.min_x
47        origin_y = bbox.min_y
48
49        name = "{} surface".format(c.name)
50
51        nx = 200
52        ny = 100
53
54        increment_x = (bbox.max_x - bbox.min_x) / float(nx)
55        increment_y = (bbox.max_y - bbox.min_y) / float(ny)
56
57        surface_collection = resinsight.project.descendants(rips.SurfaceCollection)[0]
58
59        # Create a surface at a given depth
60        s = surface_collection.new_regular_surface(
61            name=name,
62            origin_x=origin_x,
63            origin_y=origin_y,
64            depth=-depth,
65            nx=nx,
66            ny=ny,
67            increment_x=increment_x,
68            increment_y=increment_y,
69        )
70
71        # Rotate the resulting surface
72        s.rotation = 45.0
73        s.update()
74
75        # Add one property
76        s.set_property("first_property", create_x_surface(nx, ny))
77
78        # Add a wave surface
79        s.set_property("wave", create_wave_surface(nx, ny))
80
81        # Use the wave as depth for the surface
82        s.set_property_as_depth("wave")

Generate Ensemble Surface

generate_ensemble_surface.py
 1# Load ResInsight Processing Server Client Library
 2import rips
 3import tempfile
 4from os.path import expanduser
 5from pathlib import Path
 6
 7# Connect to ResInsight instance
 8resinsight = rips.Instance.find()
 9
10
11home_dir = expanduser("~")
12
13export_folder = tempfile.mkdtemp()
14
15directory_path = "resprojects/webviz-subsurface-testdata/reek_history_match/"
16# directory_path = "e:/gitroot/webviz-subsurface-testdata/reek_history_match"
17
18
19case_file_paths = []
20num_realizations = 9
21num_iterations = 4
22
23
24for realization in range(0, num_realizations):
25    for iteration in range(0, num_iterations):
26        realization_dir = "realization-" + str(realization)
27        iteration_dir = "iter-" + str(iteration)
28        egrid_name = "eclipse/model/5_R001_REEK-" + str(realization) + ".EGRID"
29        path = Path(
30            home_dir, directory_path, realization_dir, iteration_dir, egrid_name
31        )
32        case_file_paths.append(path)
33
34k_indexes = [4, 10]
35
36for path in case_file_paths:
37    # Load a case
38    path_name = path.as_posix()
39    case = resinsight.project.load_case(path_name)
40
41    if resinsight.project.has_warnings():
42        for warning in resinsight.project.warnings():
43            print(warning)
44
45    surface_collection = resinsight.project.descendants(rips.SurfaceCollection)[0]
46
47    for k_index in k_indexes:
48        print("Generating surface K layer " + str(k_index) + " for case " + path_name)
49
50        surface = surface_collection.new_surface(case, k_index)
51        print("Surface: ", surface)
52
53        parent_path = path.parent
54        export_folder_path = Path(parent_path, "surfaceexport")
55        export_folder_path.mkdir(parents=True, exist_ok=True)
56
57        export_file = Path(export_folder_path, "surf_" + str(k_index) + ".ts")
58        print("Exporting to " + export_file.as_posix())
59        surface.export_to_file(export_file.as_posix())
60
61    # Close project to avoid aggregated memory usage
62    # Can be replaced when case.close() is implemented
63    resinsight.project.close()

Generate Ensemble Surface Optimized

generate_ensemble_surface_optimized.py
 1# Load ResInsight Processing Server Client Library
 2import rips
 3import tempfile
 4from os.path import expanduser
 5from pathlib import Path
 6
 7# Connect to ResInsight instance
 8resinsight = rips.Instance.find()
 9
10
11home_dir = expanduser("~")
12
13export_folder = tempfile.mkdtemp()
14
15directory_path = "resprojects/webviz-subsurface-testdata/reek_history_match/"
16# directory_path = "e:/gitroot/webviz-subsurface-testdata/reek_history_match"
17
18
19case_file_paths = []
20num_realizations = 9
21num_iterations = 4
22
23
24for realization in range(0, num_realizations):
25    for iteration in range(0, num_iterations):
26        realization_dir = "realization-" + str(realization)
27        iteration_dir = "iter-" + str(iteration)
28        egrid_name = "eclipse/model/5_R001_REEK-" + str(realization) + ".EGRID"
29        path = Path(
30            home_dir, directory_path, realization_dir, iteration_dir, egrid_name
31        )
32        case_file_paths.append(path)
33
34k_indexes = [4, 10]
35
36command_router = resinsight.command_router
37
38for path in case_file_paths:
39    path_name = path.as_posix()
40
41    command_router.extract_surfaces(path_name, k_indexes)

Surface Import

surface_import.py
 1# Load ResInsight Processing Server Client Library
 2import rips
 3
 4# Connect to ResInsight instance
 5resinsight = rips.Instance.find()
 6print("ResInsight version: " + resinsight.version_string())
 7
 8# Example code
 9
10# get the project
11project = resinsight.project
12
13# get the topmost surface folder from the project
14surfacefolder = project.surface_folder()
15
16# list of surface files to load
17filenames = ["surface1.ts", "surface2.ts", "surface3.ts"]
18
19# Load the files into the top level
20for surffile in filenames:
21    surface = surfacefolder.import_surface(surffile)
22    if surface is None:
23        print("Could not import the surface " + surffile)
24
25# add a subfolder
26subfolder = surfacefolder.add_folder("ExampleFolder")
27
28# load the same surface multiple times using increasing depth offsets
29# store them in the new subfolder we just created
30for offset in range(0, 200, 20):
31    surface = subfolder.import_surface("mysurface.ts")
32    if surface:
33        surface.depth_offset = offset
34        surface.update()
35    else:
36        print("Could not import surface.")
37
38# get an existing subfolder
39existingfolder = project.surface_folder("ExistingFolder")
40if existingfolder is None:
41    print("Could not find the specified folder.")

View Example

view_example.py
 1#############################################################
 2# This example will alter the views of all cases
 3# By setting the background color and toggle the grid box
 4# Also clones the first view
 5#############################################################
 6import rips
 7
 8# Connect to ResInsight instance
 9resinsight = rips.Instance.find()
10
11# Check if connection worked
12if resinsight is not None:
13    # Get a list of all cases
14    cases = resinsight.project.cases()
15    for case in cases:
16        # Get a list of all views
17        views = case.views()
18        for view in views:
19            # Set some parameters for the view
20            view.show_grid_box = not view.show_grid_box
21            view.background_color = "#3388AA"
22            # Update the view in ResInsight
23            view.update()
24        # Clone the first view
25        new_view = views[0].clone()
26        new_view.background_color = "#FFAA33"
27        new_view.update()
28        view.show_grid_box = False
29        view.set_visible(False)
30        view.update()