Instance And Project Management

This page shows Python examples from the instance_and_project_management folder.

Command Example

command_example.py
 1###############################################################################
 2# This example will show setting time step, window size and export snapshots and properties
 3###############################################################################
 4import os
 5import tempfile
 6import rips
 7
 8# Load instance
 9resinsight = rips.Instance.find()
10
11# Set window sizes
12resinsight.set_main_window_size(width=800, height=500)
13resinsight.set_plot_window_size(width=1000, height=1000)
14
15
16# Retrieve first case
17case = resinsight.project.cases()[0]
18
19# Get a view
20view1 = case.views()[0]
21
22# Clone the view
23view2 = view1.clone()
24
25# Set the time step for view1 only
26view1.set_time_step(time_step=2)
27
28# Set cell result to SOIL
29view1.apply_cell_result(result_type="DYNAMIC_NATIVE", result_variable="SOIL")
30
31
32# Create a temporary directory which will disappear at the end of this script
33# If you want to keep the files, provide a good path name instead of tmpdirname
34with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
35    print("Temporary folder: ", tmpdirname)
36
37    # Set export folder for snapshots and properties
38    resinsight.set_export_folder(export_type="SNAPSHOTS", path=tmpdirname)
39    resinsight.set_export_folder(export_type="PROPERTIES", path=tmpdirname)
40
41    # Export all snapshots
42    resinsight.project.export_snapshots()
43
44    assert len(os.listdir(tmpdirname)) > 0
45
46    # Export properties in the view
47    view1.export_property()
48
49    # Check that the exported file exists
50    expected_file_name = case.name + "-" + str("3D_View") + "-" + "T2" + "-SOIL"
51    full_path = tmpdirname + "/" + expected_file_name
52
53    # Print contents of temporary folder
54    print(os.listdir(tmpdirname))
55
56    assert os.path.exists(full_path)

Launch Load Case Snapshot Exit

launch_load_case_snapshot_exit.py
 1# Access to environment variables
 2import os
 3
 4# Load ResInsight Processing Server Client Library
 5import rips
 6
 7# Connect to ResInsight instance
 8resinsight = rips.Instance.launch()
 9
10# This requires the TestModels to be installed with ResInsight (RESINSIGHT_BUNDLE_TESTMODELS):
11resinsight_exe_path = os.environ.get("RESINSIGHT_EXECUTABLE")
12
13# Get the TestModels path from the executable path
14resinsight_install_path = os.path.dirname(resinsight_exe_path)
15test_models_path = os.path.join(resinsight_install_path, "TestModels")
16path_name = os.path.join(
17    test_models_path, "TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
18)
19
20# Load an example case. Needs to be replaced with a valid path!
21case = resinsight.project.load_case(path_name)
22
23# Get a view
24view1 = case.views()[0]
25
26# Set the time step for view1 only
27view1.set_time_step(time_step=2)
28
29# Set cell result to SOIL
30view1.apply_cell_result(result_type="DYNAMIC_NATIVE", result_variable="SOIL")
31
32# Set export folder for snapshots and properties
33resinsight.set_export_folder(export_type="SNAPSHOTS", path="e:/temp")
34resinsight.set_export_folder(export_type="PROPERTIES", path="e:/temp")
35
36# Export all snapshots
37resinsight.project.export_snapshots()
38
39# Export properties in the view
40view1.export_property()
41
42resinsight.exit()

Launch With Commandline Options

launch_with_commandline_options.py
 1# Load ResInsight Processing Server Client Library
 2import rips
 3
 4# Launch ResInsight with last project file and a Window size of 600x1000 pixels
 5resinsight = rips.Instance.launch(
 6    command_line_parameters=["--last", "--size", 600, 1000]
 7)
 8# Get a list of all cases
 9cases = resinsight.project.cases()
10
11print("Got " + str(len(cases)) + " cases: ")
12for case in cases:
13    print("Case name: " + case.name)
14    print("Case grid path: " + case.file_path)

Open Project

open_project.py
 1# Access to environment variables and path tools
 2import os
 3
 4# Load ResInsight Processing Server Client Library
 5import rips
 6
 7# Connect to ResInsight instance
 8resinsight = rips.Instance.find()
 9
10# This requires the TestModels to be installed with ResInsight (RESINSIGHT_BUNDLE_TESTMODELS):
11resinsight_exe_path = os.environ.get("RESINSIGHT_EXECUTABLE")
12
13# Get the TestModels path from the executable path
14resinsight_install_path = os.path.dirname(resinsight_exe_path)
15test_models_path = os.path.join(resinsight_install_path, "TestModels")
16path_name = os.path.join(test_models_path, "TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp")
17
18# Open a project
19resinsight.project.open(path_name)

Save Project

save_project.py
 1# Access to environment variables and path tools
 2import os
 3
 4# Load ResInsight Processing Server Client Library
 5import rips
 6
 7# Connect to ResInsight instance
 8resinsight = rips.Instance.find()
 9
10# This requires the TestModels to be installed with ResInsight (RESINSIGHT_BUNDLE_TESTMODELS):
11resinsight_exe_path = os.environ.get("RESINSIGHT_EXECUTABLE")
12
13# Get the TestModels path from the executable path
14resinsight_install_path = os.path.dirname(resinsight_exe_path)
15test_models_path = os.path.join(resinsight_install_path, "TestModels")
16path_name = os.path.join(
17    test_models_path, "TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
18)
19case = resinsight.project.load_case(path_name)
20
21# Save the project to file
22home_dir = os.path.expanduser("~")
23project_path = home_dir + "/new-project.rsp"
24print("Saving project to: ", project_path)
25resinsight.project.save(project_path)