Export And Plotting
This page shows Python examples from the export_and_plotting folder.
Alter Wbs Plot
alter_wbs_plot.py
1# Load ResInsight Processing Server Client Library
2import rips
3import tempfile
4
5# Connect to ResInsight instance
6resinsight = rips.Instance.find()
7
8# Get the project
9project = resinsight.project
10
11# Find all the well bore stability plots in the project
12wbsplots = project.descendants(rips.WellBoreStabilityPlot)
13
14# Chose a sensible output folder
15dirname = tempfile.gettempdir()
16
17# Loop through all Well Bore Stability plots
18for wbsplot in wbsplots:
19 # Set depth type a parameter and export snapshot
20 wbsplot.depth_type = "TRUE_VERTICAL_DEPTH_RKB"
21
22 # Example of setting parameters for existing plots
23 params = wbsplot.parameters()
24 params.user_poisson_ratio = 0.12345
25 params.update()
26 wbsplot.update()
27 wbsplot.export_snapshot(export_folder=dirname)
Create Wbs Plot
create_wbs_plot.py
1import os
2
3# Load ResInsight Processing Server Client Library
4import rips
5
6# Connect to ResInsight instance
7resInsight = rips.Instance.find()
8
9# Get all GeoMech cases
10cases = resInsight.project.descendants(rips.GeoMechCase)
11
12# Get all well paths
13well_paths = resInsight.project.well_paths()
14
15# Ensure there's at least one well path
16if len(well_paths) < 1:
17 print("No well paths in project")
18 exit(1)
19
20# Create a set of WbsParameters
21params = rips.WbsParameters()
22params.user_poisson_ratio = 0.23456
23params.user_ucs = 123
24
25# Loop through all cases
26for case in cases:
27 assert isinstance(case, rips.GeoMechCase)
28 min_res_depth, max_res_depth = case.reservoir_depth_range()
29
30 # Find a good output path
31 case_path = case.file_path
32 folder_name = os.path.dirname(case_path)
33
34 # Import formation names
35 case.import_formation_names(
36 formation_files=[
37 "D:/Projects/ResInsight-regression-test/ModelData/norne/Norne_ATW2013.lyr"
38 ]
39 )
40
41 # create a folder to hold the snapshots
42 dirname = os.path.join(folder_name, "snapshots")
43 print("Exporting to: " + dirname)
44
45 for well_path in well_paths[0:4]: # Loop through the first five well paths
46 # Create plot with parameters
47 wbsplot = case.create_well_bore_stability_plot(
48 well_path=well_path.name, time_step=0, parameters=params
49 )
Export Contour Maps
export_contour_maps.py
1# Load ResInsight Processing Server Client Library
2import rips
3import tempfile
4import pathlib
5
6# Connect to ResInsight instance
7resInsight = rips.Instance.find()
8
9# Data will be written to temp
10tmpdir = pathlib.Path(tempfile.gettempdir())
11
12# Find all eclipse contour maps of the project
13contour_maps = resInsight.project.descendants(rips.EclipseContourMap)
14print("Number of eclipse contour maps:", len(contour_maps))
15
16# Export the contour maps to a text file
17for index, contour_map in enumerate(contour_maps):
18 filename = "eclipse_contour_map" + str(index) + ".txt"
19 filepath = tmpdir / filename
20 print("Exporting to:", filepath)
21 contour_map.export_to_text(str(filepath))
22
23# The contour maps is also available for a Case
24cases = resInsight.project.cases()
25for case in cases:
26 contour_maps = case.descendants(rips.GeoMechContourMap)
27 # Export the contour maps to a text file
28 for index, contour_map in enumerate(contour_maps):
29 filename = "geomech_contour_map" + str(index) + ".txt"
30 filepath = tmpdir / filename
31 print("Exporting to:", filepath)
32 contour_map.export_to_text(str(filepath))
Export Plots
export_plots.py
1# Import the tempfile module
2import tempfile
3
4# Load ResInsight Processing Server Client Library
5import rips
6
7# Connect to ResInsight instance
8resInsight = rips.Instance.find()
9
10# Get a list of all plots
11plots = resInsight.project.plots()
12
13export_folder = tempfile.mkdtemp()
14
15print("Exporting to: " + export_folder)
16
17for plot in plots:
18 plot.export_snapshot(export_folder=export_folder)
19 plot.export_snapshot(export_folder=export_folder, output_format="PDF")
20 if isinstance(plot, rips.WellLogPlot):
21 plot.export_data_as_las(export_folder=export_folder)
22 plot.export_data_as_ascii(export_folder=export_folder)
Export Snapshots
export_snapshots.py
1############################################################################
2# This script will export snapshots for two properties in every loaded case
3# And put them in a snapshots folder in the same folder as the case grid
4############################################################################
5import os
6import rips
7
8# Load instance
9resinsight = rips.Instance.find()
10cases = resinsight.project.cases()
11
12# Set main window size
13resinsight.set_main_window_size(width=800, height=500)
14
15n = 5 # every n-th time_step for snapshot
16property_list = ["SOIL", "PRESSURE"] # list of parameter for snapshot
17
18print("Looping through cases")
19for case in cases:
20 print("Case name: ", case.name)
21 print("Case id: ", case.id)
22 # Get grid path and its folder name
23 case_path = case.file_path
24 folder_name = os.path.dirname(case_path)
25
26 # create a folder to hold the snapshots
27 dirname = os.path.join(folder_name, "snapshots")
28
29 if os.path.exists(dirname) is False:
30 os.mkdir(dirname)
31
32 print("Exporting to folder: " + dirname)
33 resinsight.set_export_folder(export_type="SNAPSHOTS", path=dirname)
34
35 time_steps = case.time_steps()
36 print("Number of time_steps: " + str(len(time_steps)))
37
38 for view in case.views():
39 for property in property_list:
40 view.apply_cell_result(
41 result_type="DYNAMIC_NATIVE", result_variable=property
42 )
43 for time_step in range(0, len(time_steps), 10):
44 view.set_time_step(time_step=time_step)
45 view.export_snapshot()
Headless Plot Export
headless_plot_export.py
1import os
2
3import rips
4
5use_platform_offscreen = True
6if use_platform_offscreen:
7 # To use offscreen, the path to fonts must be specified in the environment variable QT_QPA_FONTDIR="C:/windows/fonts"
8 resinsight = rips.Instance.launch(
9 command_line_parameters=["-platform", "offscreen", "--size", 1200, 1000]
10 )
11
12 qpa_fontdir = os.environ["QT_QPA_FONTDIR"]
13 print("Environment var QT_QPA_FONTDIR : " + qpa_fontdir)
14else:
15 resinsight = rips.Instance.find()
16
17summary_filename = "NORNE.SMSPEC"
18
19project = resinsight.project
20summary_case = project.import_summary_case(summary_filename)
21
22summary_plot_collection = project.descendants(rips.SummaryPlotCollection)[0]
23
24summary_plot_collection.new_summary_plot(summary_cases=[summary_case], address="FOPR")
25summary_plot_collection.new_summary_plot(
26 summary_cases=[summary_case], address="WOPR:A*;WOPR:B*"
27)
28
29plots = resinsight.project.plots()
30for plot in plots:
31 plot.export_snapshot()
32 # plot.export_snapshot(output_format="PDF")
33
34resinsight.exit()
New Summary Plot
new_summary_plot.py
1# Load ResInsight Processing Server Client Library
2import rips
3
4# Connect to ResInsight instance
5resinsight = rips.Instance.find()
6# Example code
7project = resinsight.project
8
9summary_cases = project.descendants(rips.SummaryCase)
10summary_plot_collection = project.descendants(rips.SummaryPlotCollection)[0]
11if len(summary_cases) > 0:
12 summary_plot = summary_plot_collection.new_summary_plot(
13 summary_cases=summary_cases, address="FOP*"
14 )
Summary Cases
summary_cases.py
1# Load ResInsight Processing Server Client Library
2import rips
3
4# Connect to ResInsight instance
5resinsight = rips.Instance.find()
6# Example code
7
8# Specific summary case with case_id = 1
9summary_case = resinsight.project.summary_case(case_id=1)
10summary_case.print_object_info()
11
12# All summary cases
13summary_cases = resinsight.project.summary_cases()
14for summary_case in summary_cases:
15 print("Summary case found: ", summary_case.short_name)
Summary Vectors
summary_vectors.py
1import rips
2import time
3
4resinsight = rips.Instance.find()
5
6project = resinsight.project
7
8# Use the following commented lines to import a file from disk
9# filename = "path/to/file/1_R001_REEK-0.SMSPEC"
10# summary_case = project.import_summary_case(filename)
11
12# Assumes at least one summery case loaded with case_id 1
13summary_case = project.summary_case(1)
14if summary_case is None:
15 print("No summary case found")
16 exit()
17
18vector_name = "FOPT"
19summary_data = summary_case.summary_vector_values(vector_name)
20
21print("Data for summary vector " + vector_name)
22print(summary_data.values)
23
24time_steps = summary_case.available_time_steps()
25print(time_steps.values)
26
27summary_data_sampled = summary_case.resample_values("FOPT", "QUARTER")
28print("\nResampled data")
29
30for t, value in zip(summary_data_sampled.time_steps, summary_data_sampled.values):
31 print(time.strftime("%a, %d %b %Y ", time.gmtime(t)) + " | " + str(value))
32
33test_values = summary_data.values
34offset = test_values[len(test_values) - 1] / 10
35
36for index, item in enumerate(test_values):
37 test_values[index] = test_values[index] + offset
38
39summary_case.set_summary_values("FOPT_M1", "myUnit", test_values)
40
41for index, item in enumerate(test_values):
42 test_values[index] = test_values[index] + offset
43summary_case.set_summary_values("FOPT_M2", "myUnit", test_values)
44
45for index, item in enumerate(test_values):
46 test_values[index] = test_values[index] + offset
47summary_case.set_summary_values("FOPT_M3", "myUnit", test_values)
48
49for index, item in enumerate(test_values):
50 test_values[index] = test_values[index] + offset
51summary_case.set_summary_values("FOPT_M4", "myUnit", test_values)