Add Python linting using black (#7276)

This commit is contained in:
Magne Sjaastad
2021-01-26 20:48:01 +01:00
committed by GitHub
parent 0ec612ae86
commit 1bacd41037
61 changed files with 1331 additions and 966 deletions

View File

@@ -7,12 +7,12 @@
import rips
# Connect to ResInsight
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all cases
cases = resinsight.project.cases()
print ("Got " + str(len(cases)) + " cases: ")
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print("Case id: " + str(case.id))
print("Case name: " + case.name)
@@ -26,11 +26,14 @@ if resinsight is not None:
print("Month: " + str(t.month))
if isinstance(case, rips.EclipseCase):
print ("Getting coarsening info for case: ", case.name, case.id)
print("Getting coarsening info for case: ", case.name, case.id)
coarsening_info = case.coarsening_info()
if coarsening_info:
print("Coarsening information:")
for c in coarsening_info:
print("[{}, {}, {}] - [{}, {}, {}]".format(c.min.x, c.min.y, c.min.z,
c.max.x, c.max.y, c.max.z))
print(
"[{}, {}, {}] - [{}, {}, {}]".format(
c.min.x, c.min.y, c.min.z, c.max.x, c.max.y, c.max.z
)
)

View File

@@ -7,7 +7,7 @@
import rips
# Connect to ResInsight
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all wells
cases = resinsight.project.cases()
@@ -24,4 +24,13 @@ if resinsight is not None:
for (tidx, timestep) in enumerate(timesteps):
status = sim_well.status(tidx)
cells = sim_well.cells(tidx)
print("timestep: " + str(tidx) + " type: " + status.well_type + " open: " + str(status.is_open) + " cells:" + str(len(cells)))
print(
"timestep: "
+ str(tidx)
+ " type: "
+ status.well_type
+ " open: "
+ str(status.is_open)
+ " cells:"
+ str(len(cells))
)

View File

@@ -7,11 +7,11 @@
import rips
# Connect to ResInsight
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all wells
wells = resinsight.project.well_paths()
print ("Got " + str(len(wells)) + " wells: ")
print("Got " + str(len(wells)) + " wells: ")
for well in wells:
print("Well name: " + well.name)

View File

@@ -23,7 +23,5 @@ for wbsplot in wbsplots:
params = wbsplot.parameters()
params.user_poisson_ratio = 0.12345
params.update()
wbsplot.update()
wbsplot.update()
wbsplot.export_snapshot(export_folder=dirname)

View File

@@ -1,21 +1,27 @@
import os
import rips
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
case_paths = []
case_paths.append("C:/Users/lindk/source/repos/ResInsight/TestModels/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID")
case_paths.append("C:/Users/lindk/source/repos/ResInsight/TestModels/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID")
case_paths.append(
"C:/Users/lindk/source/repos/ResInsight/TestModels/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
)
case_paths.append(
"C:/Users/lindk/source/repos/ResInsight/TestModels/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID"
)
for case_path in case_paths:
assert os.path.exists(case_path), "You need to set valid case paths for this script to work"
assert os.path.exists(
case_path
), "You need to set valid case paths for this script to work"
case_group = resinsight.project.create_grid_case_group(case_paths=case_paths)
case_group.print_object_info()
#stat_cases = caseGroup.statistics_cases()
#case_ids = []
#for stat_case in stat_cases:
# stat_cases = caseGroup.statistics_cases()
# case_ids = []
# for stat_case in stat_cases:
# stat_case.set_dynamic_properties_to_calculate(["SWAT"])
# case_ids.append(stat_case.id)
@@ -24,4 +30,3 @@ case_group.compute_statistics()
view = case_group.views()[0]
cell_result = view.cell_result()
cell_result.set_result_variable("PRESSURE_DEV")

View File

@@ -6,7 +6,7 @@
import rips
# Connect to ResInsight
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
# Get the first case. This will fail if you haven't loaded any cases
case = resinsight.project.cases()[0]
@@ -20,7 +20,7 @@ print("Total number of reservoir cells: " + str(cell_counts.reservoir_cell_count
active_cell_infos = case.cell_info_for_active_cells()
# A simple check on the size of the cell info
assert(cell_counts.active_cell_count == len(active_cell_infos))
assert cell_counts.active_cell_count == len(active_cell_infos)
# Print information for the first active cell
print("First active cell: ")

View File

@@ -3,15 +3,13 @@
######################################################################
import rips
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
view = resinsight.project.views()[0]
results = view.cell_result_data()
print ("Number of result values: ", len(results))
print("Number of result values: ", len(results))
newresults = []
for i in range(0, len(results)):
newresults.append(results[i] * -1.0)
view.set_cell_result_data(newresults)

View File

@@ -26,23 +26,23 @@ view2 = view1.clone()
view1.set_time_step(time_step=2)
# Set cell result to SOIL
view1.apply_cell_result(result_type='DYNAMIC_NATIVE', result_variable='SOIL')
view1.apply_cell_result(result_type="DYNAMIC_NATIVE", result_variable="SOIL")
# Create a temporary directory which will disappear at the end of this script
# If you want to keep the files, provide a good path name instead of tmpdirname
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
print("Temporary folder: ", tmpdirname)
# Set export folder for snapshots and properties
resinsight.set_export_folder(export_type='SNAPSHOTS', path=tmpdirname)
resinsight.set_export_folder(export_type='PROPERTIES', path=tmpdirname)
resinsight.set_export_folder(export_type="SNAPSHOTS", path=tmpdirname)
resinsight.set_export_folder(export_type="PROPERTIES", path=tmpdirname)
# Export all snapshots
resinsight.project.export_snapshots()
assert(len(os.listdir(tmpdirname)) > 0)
assert len(os.listdir(tmpdirname)) > 0
# Export properties in the view
view1.export_property()
@@ -53,5 +53,4 @@ with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
# Print contents of temporary folder
print(os.listdir(tmpdirname))
assert(os.path.exists(full_path))
assert os.path.exists(full_path)

View File

@@ -19,8 +19,10 @@ print("Facies properties file path:", facies_properties_file_path)
# Create stim plan model template
fmt_collection = project.descendants(rips.StimPlanModelTemplateCollection)[0]
stim_plan_model_template = fmt_collection.new_stim_plan_model_template(elastic_properties_file_path=elastic_properties_file_path,
facies_properties_file_path=facies_properties_file_path)
stim_plan_model_template = fmt_collection.new_stim_plan_model_template(
elastic_properties_file_path=elastic_properties_file_path,
facies_properties_file_path=facies_properties_file_path,
)
stim_plan_model_template.overburden_formation = "Garn"
stim_plan_model_template.overburden_facies = "Shale"
stim_plan_model_template.underburden_formation = "Garn"
@@ -49,7 +51,9 @@ non_net_layers.update()
# Add some scaling factors
elastic_properties = stim_plan_model_template.elastic_properties()
elastic_properties.add_property_scaling(formation="Garn", facies="Calcite", property="YOUNGS_MODULUS", scale=1.44)
elastic_properties.add_property_scaling(
formation="Garn", facies="Calcite", property="YOUNGS_MODULUS", scale=1.44
)
well_name = "B-2 H"
@@ -73,20 +77,24 @@ export_folder = tempfile.gettempdir()
stim_plan_models = []
# Create and export a StimPlan model for each depth
measured_depths = [ 3200.0, 3400.0, 3600.0 ]
measured_depths = [3200.0, 3400.0, 3600.0]
for measured_depth in measured_depths:
# Create stim plan model at a give measured depth
stim_plan_model = stim_plan_model_collection.new_stim_plan_model(eclipse_case=case,
time_step=time_step,
well_path=well_path,
measured_depth=measured_depth,
stim_plan_model_template=stim_plan_model_template)
stim_plan_model = stim_plan_model_collection.new_stim_plan_model(
eclipse_case=case,
time_step=time_step,
well_path=well_path,
measured_depth=measured_depth,
stim_plan_model_template=stim_plan_model_template,
)
stim_plan_models.append(stim_plan_model)
# Make the well name safer to use as a directory path
well_name_part = well_name.replace(" ", "_")
directory_path = Path(export_folder) / '{}_{}'.format(well_name_part, int(measured_depth))
directory_path = Path(export_folder) / "{}_{}".format(
well_name_part, int(measured_depth)
)
# Create the folder
directory_path.mkdir(parents=True, exist_ok=True)
@@ -95,14 +103,17 @@ for measured_depth in measured_depths:
stim_plan_model.export_to_file(directory_path=directory_path.as_posix())
# Create a fracture mode plot
stim_plan_model_plot_collection = project.descendants(rips.StimPlanModelPlotCollection)[0]
stim_plan_model_plot = stim_plan_model_plot_collection.new_stim_plan_model_plot(stim_plan_model=stim_plan_model)
stim_plan_model_plot_collection = project.descendants(
rips.StimPlanModelPlotCollection
)[0]
stim_plan_model_plot = stim_plan_model_plot_collection.new_stim_plan_model_plot(
stim_plan_model=stim_plan_model
)
print("Exporting fracture model plot to: ", directory_path)
stim_plan_model_plot.export_snapshot(export_folder=directory_path.as_posix())
print("Setting measured depth and perforation length.")
stim_plan_models[0].measured_depth = 3300.0
stim_plan_models[0].perforation_length = 123.445

View File

@@ -3,6 +3,7 @@ import grpc
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resInsight = rips.Instance.find()
@@ -24,7 +25,7 @@ params.user_ucs = 123
# Loop through all cases
for case in cases:
assert(isinstance(case, rips.GeoMechCase))
assert isinstance(case, rips.GeoMechCase)
min_res_depth, max_res_depth = case.reservoir_depth_range()
# Find a good output path
@@ -32,12 +33,18 @@ for case in cases:
folder_name = os.path.dirname(case_path)
# Import formation names
case.import_formation_names(formation_files=['D:/Projects/ResInsight-regression-test/ModelData/norne/Norne_ATW2013.lyr'])
case.import_formation_names(
formation_files=[
"D:/Projects/ResInsight-regression-test/ModelData/norne/Norne_ATW2013.lyr"
]
)
# create a folder to hold the snapshots
dirname = os.path.join(folder_name, 'snapshots')
dirname = os.path.join(folder_name, "snapshots")
print("Exporting to: " + dirname)
for well_path in well_paths[0:4]: # Loop through the first five well paths
for well_path in well_paths[0:4]: # Loop through the first five well paths
# Create plot with parameters
wbsplot = case.create_well_bore_stability_plot(well_path=well_path.name, time_step=0, parameters=params)
wbsplot = case.create_well_bore_stability_plot(
well_path=well_path.name, time_step=0, parameters=params
)

View File

@@ -1,5 +1,5 @@
###################################################################
# This example demonstrates the use of ResInsight exceptions
# This example demonstrates the use of ResInsight exceptions
# for proper error handling
###################################################################
@@ -7,7 +7,7 @@ import rips
import grpc
import tempfile
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
case = None
@@ -15,62 +15,69 @@ case = None
try:
case = resinsight.project.load_case("Nonsense")
except grpc.RpcError as e:
print("Expected Server Exception Received while loading case: ", e.code(), e.details())
print(
"Expected Server Exception Received while loading case: ", e.code(), e.details()
)
# Try loading well paths from a non-existing folder. We should get a grpc.RpcError exception from the server
try:
well_path_files = resinsight.project.import_well_paths(well_path_folder="NONSENSE/NONSENSE")
well_path_files = resinsight.project.import_well_paths(
well_path_folder="NONSENSE/NONSENSE"
)
except grpc.RpcError as e:
print("Expected Server Exception Received while loading wellpaths: ", e.code(), e.details())
print(
"Expected Server Exception Received while loading wellpaths: ",
e.code(),
e.details(),
)
# Try loading well paths from an existing but empty folder. We should get a warning.
try:
with tempfile.TemporaryDirectory() as tmpdirname:
well_path_files = resinsight.project.import_well_paths(well_path_folder=tmpdirname)
assert(len(well_path_files) == 0)
assert(resinsight.project.has_warnings())
well_path_files = resinsight.project.import_well_paths(
well_path_folder=tmpdirname
)
assert len(well_path_files) == 0
assert resinsight.project.has_warnings()
print("Should get warnings below")
for warning in resinsight.project.warnings():
print (warning)
print(warning)
except grpc.RpcError as e:
print("Unexpected Server Exception caught!!!", e)
case = resinsight.project.case(case_id=0)
if case is not None:
results = case.active_cell_property('STATIC_NATIVE', 'PORO', 0)
results = case.active_cell_property("STATIC_NATIVE", "PORO", 0)
active_cell_count = len(results)
# Send the results back to ResInsight inside try / except construct
try:
case.set_active_cell_property(results, 'GENERATED', 'POROAPPENDED', 0)
try:
case.set_active_cell_property(results, "GENERATED", "POROAPPENDED", 0)
print("Everything went well as expected")
except: # Match any exception, but it should not happen
except: # Match any exception, but it should not happen
print("Ooops!")
# Add another value, so this is outside the bounds of the active cell result storage
results.append(1.0)
# This time we should get a grpc.RpcError exception, which is a server side error.
try:
case.set_active_cell_property(results, 'GENERATED', 'POROAPPENDED', 0)
try:
case.set_active_cell_property(results, "GENERATED", "POROAPPENDED", 0)
print("Everything went well??")
except grpc.RpcError as e:
print("Expected Server Exception Received: ", e)
except IndexError:
print ("Got index out of bounds error. This shouldn't happen here")
print("Got index out of bounds error. This shouldn't happen here")
# With a chunk size exactly matching the active cell count the server will not
# be able to see any error as it will successfully close the stream after receiving
# the correct number of values, even if the python client has more chunks to send
case.chunk_size = active_cell_count
try:
case.set_active_cell_property(results, 'GENERATED', 'POROAPPENDED', 0)
try:
case.set_active_cell_property(results, "GENERATED", "POROAPPENDED", 0)
print("Everything went well??")
except grpc.RpcError as e:
print("Got unexpected server exception", e, "This should not happen now")
except IndexError:
print ("Got expected index out of bounds error on client side")
print("Got expected index out of bounds error on client side")

View File

@@ -1,7 +1,9 @@
# Import the tempfile module
import tempfile
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resInsight = rips.Instance.find()
@@ -13,8 +15,8 @@ export_folder = tempfile.mkdtemp()
print("Exporting to: " + export_folder)
for plot in plots:
plot.export_snapshot(export_folder=export_folder)
plot.export_snapshot(export_folder=export_folder, output_format='PDF')
if isinstance(plot, rips.WellLogPlot):
plot.export_data_as_las(export_folder=export_folder)
plot.export_data_as_ascii(export_folder=export_folder)
plot.export_snapshot(export_folder=export_folder)
plot.export_snapshot(export_folder=export_folder, output_format="PDF")
if isinstance(plot, rips.WellLogPlot):
plot.export_data_as_las(export_folder=export_folder)
plot.export_data_as_ascii(export_folder=export_folder)

View File

@@ -12,33 +12,35 @@ cases = resinsight.project.cases()
# Set main window size
resinsight.set_main_window_size(width=800, height=500)
n = 5 # every n-th time_step for snapshot
property_list = ['SOIL', 'PRESSURE'] # list of parameter for snapshot
n = 5 # every n-th time_step for snapshot
property_list = ["SOIL", "PRESSURE"] # list of parameter for snapshot
print ("Looping through cases")
print("Looping through cases")
for case in cases:
print("Case name: ", case.name)
print("Case id: ", case.id)
# Get grid path and its folder name
case_path = case.file_path
folder_name = os.path.dirname(case_path)
# create a folder to hold the snapshots
dirname = os.path.join(folder_name, 'snapshots')
dirname = os.path.join(folder_name, "snapshots")
if os.path.exists(dirname) is False:
os.mkdir(dirname)
print ("Exporting to folder: " + dirname)
resinsight.set_export_folder(export_type='SNAPSHOTS', path=dirname)
print("Exporting to folder: " + dirname)
resinsight.set_export_folder(export_type="SNAPSHOTS", path=dirname)
time_steps = case.time_steps()
print('Number of time_steps: ' + str(len(time_steps)))
print("Number of time_steps: " + str(len(time_steps)))
for view in case.views():
if view.is_eclipse_view():
for property in property_list:
view.apply_cell_result(result_type='DYNAMIC_NATIVE', result_variable=property)
view.apply_cell_result(
result_type="DYNAMIC_NATIVE", result_variable=property
)
for time_step in range(0, len(time_steps), 10):
view.set_time_step(time_step = time_step)
view.set_time_step(time_step=time_step)
view.export_snapshot()

View File

@@ -4,7 +4,7 @@
import rips
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
cases = resinsight.project.cases()
print("Number of cases found: ", len(cases))
@@ -14,6 +14,3 @@ for case in cases:
print("Number of grids: ", len(grids))
for grid in grids:
print("Grid dimensions: ", grid.dimensions())

View File

@@ -1,9 +1,12 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resInsight = rips.Instance.find()
well_paths = resInsight.project.import_well_paths(well_path_folder='D:/Projects/ResInsight-regression-test/ModelData/norne/wellpaths')
well_paths = resInsight.project.import_well_paths(
well_path_folder="D:/Projects/ResInsight-regression-test/ModelData/norne/wellpaths"
)
if resInsight.project.has_warnings():
for warning in resInsight.project.warnings():
print(warning)
@@ -12,8 +15,12 @@ if resInsight.project.has_warnings():
for well_path in well_paths:
print("Imported from folder: " + well_path.name)
well_paths = resInsight.project.import_well_paths(well_path_files=['D:/Projects/ResInsight-regression-test/ModelData/Norne_WellPaths/E-3H.json',
'D:/Projects/ResInsight-regression-test/ModelData/Norne_WellPaths/C-1H.json'])
well_paths = resInsight.project.import_well_paths(
well_path_files=[
"D:/Projects/ResInsight-regression-test/ModelData/Norne_WellPaths/E-3H.json",
"D:/Projects/ResInsight-regression-test/ModelData/Norne_WellPaths/C-1H.json",
]
)
if resInsight.project.has_warnings():
for warning in resInsight.project.warnings():
print(warning)
@@ -23,10 +30,12 @@ for well_path in well_paths:
print("Imported from individual files: " + well_path.name)
well_path_names = resInsight.project.import_well_log_files(well_log_folder='D:/Projects/ResInsight-regression-test/ModelData/Norne_PLT_LAS')
well_path_names = resInsight.project.import_well_log_files(
well_log_folder="D:/Projects/ResInsight-regression-test/ModelData/Norne_PLT_LAS"
)
if resInsight.project.has_warnings():
for warning in resInsight.project.warnings():
print(warning)
for well_path_name in well_path_names:
print("Imported well log file for: " + well_path_name)
print("Imported well log file for: " + well_path_name)

View File

@@ -17,22 +17,24 @@ def create_result(poro_chunks, permx_chunks):
# Return a generator object that behaves like a Python iterator
yield resultChunk
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
start = time.time()
case = resinsight.project.cases()[0]
# Get a generator for the poro results. The generator will provide a chunk each time it is iterated
poro_chunks = case.active_cell_property_async('STATIC_NATIVE', 'PORO', 0)
poro_chunks = case.active_cell_property_async("STATIC_NATIVE", "PORO", 0)
# Get a generator for the permx results. The generator will provide a chunk each time it is iterated
permx_chunks = case.active_cell_property_async('STATIC_NATIVE', 'PERMX', 0)
permx_chunks = case.active_cell_property_async("STATIC_NATIVE", "PERMX", 0)
# Send back the result with the result provided by a generator object.
# Iterating the result generator will cause the script to read from the poro and permx generators
# And return the result of each iteration
case.set_active_cell_property_async(create_result(poro_chunks, permx_chunks),
'GENERATED', 'POROPERMXAS', 0)
case.set_active_cell_property_async(
create_result(poro_chunks, permx_chunks), "GENERATED", "POROPERMXAS", 0
)
end = time.time()
print("Time elapsed: ", end - start)
print("Transferred all results back")
view = case.views()[0].apply_cell_result('GENERATED', 'POROPERMXAS')
view = case.views()[0].apply_cell_result("GENERATED", "POROPERMXAS")

View File

@@ -7,14 +7,14 @@ import rips
import time
import grpc
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
start = time.time()
case = resinsight.project.cases()[0]
# Read poro result into list
poro_results = case.active_cell_property('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('STATIC_NATIVE', 'PERMX', 0)
permx_results = case.active_cell_property("STATIC_NATIVE", "PERMX", 0)
# Generate output result
results = []
@@ -23,7 +23,7 @@ for (poro, permx) in zip(poro_results, permx_results):
try:
# Send back output result
case.set_active_cell_property(results, 'GENERATED', 'POROPERMXSY', 0)
case.set_active_cell_property(results, "GENERATED", "POROPERMXSY", 0)
except grpc.RpcError as e:
print("Exception Received: ", e)
@@ -32,4 +32,4 @@ end = time.time()
print("Time elapsed: ", end - start)
print("Transferred all results back")
view = case.views()[0].apply_cell_result('GENERATED', 'POROPERMXSY')
view = case.views()[0].apply_cell_result("GENERATED", "POROPERMXSY")

View File

@@ -3,9 +3,9 @@
#######################################
import rips
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
if resinsight is None:
print('ERROR: could not find ResInsight')
print("ERROR: could not find ResInsight")
else:
print('Successfully connected to ResInsight')
print("Successfully connected to ResInsight")

View File

@@ -1,17 +1,21 @@
# Access to environment variables
import os
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.launch()
# This requires the TestModels to be installed with ResInsight (RESINSIGHT_BUNDLE_TESTMODELS):
resinsight_exe_path = os.environ.get('RESINSIGHT_EXECUTABLE')
resinsight_exe_path = os.environ.get("RESINSIGHT_EXECUTABLE")
# Get the TestModels path from the executable path
resinsight_install_path = os.path.dirname(resinsight_exe_path)
test_models_path = os.path.join(resinsight_install_path, 'TestModels')
path_name = os.path.join(test_models_path, 'TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID')
test_models_path = os.path.join(resinsight_install_path, "TestModels")
path_name = os.path.join(
test_models_path, "TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
)
# Load an example case. Needs to be replaced with a valid path!
case = resinsight.project.load_case(path_name)
@@ -23,11 +27,11 @@ view1 = case.views()[0]
view1.set_time_step(time_step=2)
# Set cell result to SOIL
view1.apply_cell_result(result_type='DYNAMIC_NATIVE', result_variable='SOIL')
view1.apply_cell_result(result_type="DYNAMIC_NATIVE", result_variable="SOIL")
# Set export folder for snapshots and properties
resinsight.set_export_folder(export_type='SNAPSHOTS', path="e:/temp")
resinsight.set_export_folder(export_type='PROPERTIES', path="e:/temp")
resinsight.set_export_folder(export_type="SNAPSHOTS", path="e:/temp")
resinsight.set_export_folder(export_type="PROPERTIES", path="e:/temp")
# Export all snapshots
resinsight.project.export_snapshots()

View File

@@ -1,11 +1,14 @@
# Load ResInsight Processing Server Client Library
import rips
# Launch ResInsight with last project file and a Window size of 600x1000 pixels
resinsight = rips.Instance.launch(command_line_parameters=['--last', '--size', 600, 1000])
resinsight = rips.Instance.launch(
command_line_parameters=["--last", "--size", 600, 1000]
)
# Get a list of all cases
cases = resinsight.project.cases()
print ("Got " + str(len(cases)) + " cases: ")
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print("Case name: " + case.name)
print("Case grid path: " + case.file_path)

View File

@@ -1,17 +1,21 @@
# Access to environment variables and path tools
import os
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# This requires the TestModels to be installed with ResInsight (RESINSIGHT_BUNDLE_TESTMODELS):
resinsight_exe_path = os.environ.get('RESINSIGHT_EXECUTABLE')
resinsight_exe_path = os.environ.get("RESINSIGHT_EXECUTABLE")
# Get the TestModels path from the executable path
resinsight_install_path = os.path.dirname(resinsight_exe_path)
test_models_path = os.path.join(resinsight_install_path, 'TestModels')
path_name = os.path.join(test_models_path, 'TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID')
test_models_path = os.path.join(resinsight_install_path, "TestModels")
path_name = os.path.join(
test_models_path, "TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
)
case = resinsight.project.load_case(path_name)
# Print out lots of information from the case object

View File

@@ -1,5 +1,6 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# Example code
@@ -13,4 +14,4 @@ for wellpath in modeled_well_paths:
reference_point = geometry.reference_point
reference_point[0] += 100
geometry.update()
geometry.print_object_info()
geometry.print_object_info()

View File

@@ -1,5 +1,6 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# Example code
@@ -7,5 +8,7 @@ project = resinsight.project
summary_cases = project.descendants(rips.SummaryCase)
summary_plot_collection = project.descendants(rips.SummaryPlotCollection)[0]
if len(summary_cases) > 0:
summary_plot = summary_plot_collection.new_summary_plot(summary_cases=summary_cases, address="FOP*")
if len(summary_cases) > 0:
summary_plot = summary_plot_collection.new_summary_plot(
summary_cases=summary_cases, address="FOP*"
)

View File

@@ -1,17 +1,19 @@
# Access to environment variables and path tools
import os
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# This requires the TestModels to be installed with ResInsight (RESINSIGHT_BUNDLE_TESTMODELS):
resinsight_exe_path = os.environ.get('RESINSIGHT_EXECUTABLE')
resinsight_exe_path = os.environ.get("RESINSIGHT_EXECUTABLE")
# Get the TestModels path from the executable path
resinsight_install_path = os.path.dirname(resinsight_exe_path)
test_models_path = os.path.join(resinsight_install_path, 'TestModels')
path_name = os.path.join(test_models_path, 'TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp')
test_models_path = os.path.join(resinsight_install_path, "TestModels")
path_name = os.path.join(test_models_path, "TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp")
# Open a project
resinsight.project.open(path_name)

View File

@@ -1,9 +1,12 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# Example code
print("ResInsight version: " + resinsight.version_string())
case = resinsight.project.case(case_id=0)
case.replace(new_grid_file='C:/Users/lindkvis/Projects/ResInsight/TestModels/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID')
case.replace(
new_grid_file="C:/Users/lindkvis/Projects/ResInsight/TestModels/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
)

View File

@@ -7,14 +7,12 @@
import rips
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
if resinsight is not None:
cases = resinsight.project.selected_cases()
print ("Got " + str(len(cases)) + " cases: ")
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print(case.name)
for property in case.available_properties('DYNAMIC_NATIVE'):
for property in case.available_properties("DYNAMIC_NATIVE"):
print(property)

View File

@@ -5,11 +5,11 @@
import rips
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
if resinsight is not None:
cases = resinsight.project.cases()
print ("Got " + str(len(cases)) + " cases: ")
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print(case.name)
cells = case.selected_cells()
@@ -18,19 +18,31 @@ if resinsight is not None:
time_step_info = case.time_steps()
for (idx, cell) in enumerate(cells):
print("Selected cell: [{}, {}, {}] grid: {}".format(cell.ijk.i+1, cell.ijk.j+1, cell.ijk.k+1, cell.grid_index))
print(
"Selected cell: [{}, {}, {}] grid: {}".format(
cell.ijk.i + 1, cell.ijk.j + 1, cell.ijk.k + 1, cell.grid_index
)
)
# Get the grid and dimensions
grid = case.grids()[cell.grid_index]
dimensions = grid.dimensions()
# Map ijk to cell index
cell_index = dimensions.i * dimensions.j * cell.ijk.k + dimensions.i * cell.ijk.j + cell.ijk.i
cell_index = (
dimensions.i * dimensions.j * cell.ijk.k
+ dimensions.i * cell.ijk.j
+ cell.ijk.i
)
# Print the cell center
cell_centers = grid.cell_centers()
cell_center = cell_centers[cell_index]
print("Cell center: [{}, {}, {}]".format(cell_center.x, cell_center.y, cell_center.z))
print(
"Cell center: [{}, {}, {}]".format(
cell_center.x, cell_center.y, cell_center.z
)
)
# Print the cell corners
cell_corners = grid.cell_corners()[cell_index]
@@ -46,5 +58,11 @@ if resinsight is not None:
for (tidx, timestep) in enumerate(time_step_info):
# Read the full SOIL result for time step
soil_results = case.selected_cell_property('DYNAMIC_NATIVE', 'SOIL', tidx)
print("SOIL: {} ({}.{}.{})".format(soil_results[idx], timestep.year, timestep.month, timestep.day))
soil_results = case.selected_cell_property(
"DYNAMIC_NATIVE", "SOIL", tidx
)
print(
"SOIL: {} ({}.{}.{})".format(
soil_results[idx], timestep.year, timestep.month, timestep.day
)
)

View File

@@ -3,7 +3,7 @@
######################################################################
import rips
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
view = resinsight.project.views()[0]
view.apply_cell_result(result_type='STATIC_NATIVE', result_variable='DX')
view.apply_cell_result(result_type="STATIC_NATIVE", result_variable="DX")

View File

@@ -4,15 +4,18 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
view = resinsight.project.view(view_id=1)
#view.apply_flow_diagnostics_cell_result(result_variable='Fraction',
# view.apply_flow_diagnostics_cell_result(result_variable='Fraction',
# selection_mode='FLOW_TR_INJ_AND_PROD')
# Example of setting individual wells. Commented out because well names are case specific.
view.apply_flow_diagnostics_cell_result(result_variable='Fraction',
selection_mode='FLOW_TR_BY_SELECTION',
injectors = ['C-1H', 'C-2H', 'F-2H'],
producers = ['B-1AH', 'B-3H', 'D-1H'])
view.apply_flow_diagnostics_cell_result(
result_variable="Fraction",
selection_mode="FLOW_TR_BY_SELECTION",
injectors=["C-1H", "C-2H", "F-2H"],
producers=["B-1AH", "B-3H", "D-1H"],
)

View File

@@ -3,15 +3,14 @@
######################################################################
import rips
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
case = resinsight.project.case(case_id=0)
total_cell_count = case.cell_count().reservoir_cell_count
values = []
for i in range(0, total_cell_count):
values.append(i % 2 * 0.75);
values.append(i % 2 * 0.75)
print("Applying values to full grid")
case.set_grid_property(values, 'DYNAMIC_NATIVE', 'SOIL', 0)
case.set_grid_property(values, "DYNAMIC_NATIVE", "SOIL", 0)

View File

@@ -6,32 +6,32 @@ import rips
import itertools
import time
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
start = time.time()
start = time.time()
# Get the case with case id 0
case = resinsight.project.case(case_id=0)
case = resinsight.project.case(case_id=0)
# Get a list of all time steps
timeSteps = case.time_steps()
timeSteps = case.time_steps()
averages = []
for i in range(0, len(timeSteps)):
# Get the results from time step i asynchronously
# It actually returns a generator object almost immediately
result_chunks = case.active_cell_property_async('DYNAMIC_NATIVE', 'SOIL', i)
mysum = 0.0
count = 0
result_chunks = case.active_cell_property_async("DYNAMIC_NATIVE", "SOIL", i)
mysum = 0.0
count = 0
# Loop through and append the average. each time we loop resultChunks
# We will trigger a read of the input data, meaning the script will start
# Calculating averages before the whole resultValue for this time step has been received
for chunk in result_chunks:
mysum += sum(chunk.values)
count += len(chunk.values)
for chunk in result_chunks:
mysum += sum(chunk.values)
count += len(chunk.values)
averages.append(mysum/count)
averages.append(mysum / count)
end = time.time()
print("Time elapsed: ", end - start)
print(averages)
print(averages)

View File

@@ -5,23 +5,23 @@ import rips
import itertools
import time
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
start = time.time()
start = time.time()
# Get the case with case id 0
case = resinsight.project.case(case_id=0)
case = resinsight.project.case(case_id=0)
# Get a list of all time steps
time_steps = case.time_steps()
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('DYNAMIC_NATIVE', 'SOIL', i)
mysum = sum(results)
averages.append(mysum/len(results))
results = case.active_cell_property("DYNAMIC_NATIVE", "SOIL", i)
mysum = sum(results)
averages.append(mysum / len(results))
end = time.time()
print("Time elapsed: ", end - start)
print(averages)
print(averages)

View File

@@ -16,13 +16,14 @@ def create_result(soil_chunks, porv_chunks):
# Return a Python generator
yield resultChunk
resinsight = rips.Instance.find()
start = time.time()
case = resinsight.project.cases()[0]
resinsight = rips.Instance.find()
start = time.time()
case = resinsight.project.cases()[0]
timeStepInfo = case.time_steps()
# Get a generator for the porv results. The generator will provide a chunk each time it is iterated
porv_chunks = case.active_cell_property_async('STATIC_NATIVE', 'PORV', 0)
porv_chunks = case.active_cell_property_async("STATIC_NATIVE", "PORV", 0)
# Read the static result into an array, so we don't have to transfer it for each iteration
# Note we use the async method even if we synchronise here, because we need the values chunked
@@ -31,17 +32,19 @@ porv_array = []
for porv_chunk in porv_chunks:
porv_array.append(porv_chunk)
for i in range (0, len(timeStepInfo)):
for i in range(0, len(timeStepInfo)):
# Get a generator object for the SOIL property for time step i
soil_chunks = case.active_cell_property_async('DYNAMIC_NATIVE', 'SOIL', i)
soil_chunks = case.active_cell_property_async("DYNAMIC_NATIVE", "SOIL", i)
# Create the generator object for the SOIL * PORV derived result
result_generator = create_result(soil_chunks, iter(porv_array))
# Send back the result asynchronously with a generator object
case.set_active_cell_property_async(result_generator, 'GENERATED', 'SOILPORVAsync', i)
case.set_active_cell_property_async(
result_generator, "GENERATED", "SOILPORVAsync", i
)
end = time.time()
print("Time elapsed: ", end - start)
print("Transferred all results back")
view = case.views()[0].apply_cell_result('GENERATED', 'SOILPORVAsync')
view = case.views()[0].apply_cell_result("GENERATED", "SOILPORVAsync")

View File

@@ -7,27 +7,27 @@ import time
resinsight = rips.Instance.find()
start = time.time()
case = resinsight.project.cases()[0]
case = resinsight.project.cases()[0]
# Read the full porv result
porv_results = case.active_cell_property('STATIC_NATIVE', 'PORV', 0)
porv_results = case.active_cell_property("STATIC_NATIVE", "PORV", 0)
time_step_info = case.time_steps()
for i in range (0, len(time_step_info)):
for i in range(0, len(time_step_info)):
# Read the full SOIl result for time step i
soil_results = case.active_cell_property('DYNAMIC_NATIVE', 'SOIL', i)
soil_results = case.active_cell_property("DYNAMIC_NATIVE", "SOIL", i)
# Generate the result by looping through both lists in order
results = []
for (soil, porv) in zip(soil_results, porv_results):
results.append(soil * porv)
# Send back result
case.set_active_cell_property(results, 'GENERATED', 'SOILPORVSync', i)
case.set_active_cell_property(results, "GENERATED", "SOILPORVSync", i)
end = time.time()
print("Time elapsed: ", end - start)
print("Transferred all results back")
view = case.views()[0].apply_cell_result('GENERATED', 'SOILPORVSync')
view = case.views()[0].apply_cell_result("GENERATED", "SOILPORVSync")

View File

@@ -1,5 +1,6 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# Example code

View File

@@ -1,5 +1,6 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
print("ResInsight version: " + resinsight.version_string())

View File

@@ -4,6 +4,7 @@
# Also clones the first view
#############################################################
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()