mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4597 Python: add exportSnapshots example and more comments in examples
This commit is contained in:
parent
edfb39c9b7
commit
6c0e2bb3ad
@ -173,6 +173,7 @@ if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
|
|||||||
"rips/PythonExamples/CommandExample.py"
|
"rips/PythonExamples/CommandExample.py"
|
||||||
"rips/PythonExamples/CaseGridGroup.py"
|
"rips/PythonExamples/CaseGridGroup.py"
|
||||||
"rips/PythonExamples/CaseInfoStreamingExample.py"
|
"rips/PythonExamples/CaseInfoStreamingExample.py"
|
||||||
|
"rips/PythonExamples/ExportSnapshots.py"
|
||||||
"rips/PythonExamples/ErrorHandling.py"
|
"rips/PythonExamples/ErrorHandling.py"
|
||||||
"rips/PythonExamples/SoilPorvAsync.py"
|
"rips/PythonExamples/SoilPorvAsync.py"
|
||||||
"rips/PythonExamples/SoilPorvSync.py"
|
"rips/PythonExamples/SoilPorvSync.py"
|
||||||
@ -186,7 +187,7 @@ if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
|
|||||||
"rips/PythonExamples/InputPropTestAsync.py"
|
"rips/PythonExamples/InputPropTestAsync.py"
|
||||||
"rips/PythonExamples/SoilAverageAsync.py"
|
"rips/PythonExamples/SoilAverageAsync.py"
|
||||||
"rips/PythonExamples/SoilAverageSync.py"
|
"rips/PythonExamples/SoilAverageSync.py"
|
||||||
"rips/PythonExamples/SoilAverageNoComm.py"
|
"rips/PythonExamples/ViewExample.py"
|
||||||
"rips/tests/test_cases.py"
|
"rips/tests/test_cases.py"
|
||||||
"rips/tests/test_commands.py"
|
"rips/tests/test_commands.py"
|
||||||
"rips/tests/test_grids.py"
|
"rips/tests/test_grids.py"
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
|
###################################################################################
|
||||||
|
# This example will connect to ResInsight, retrieve a list of cases and print info
|
||||||
|
###################################################################################
|
||||||
|
|
||||||
|
# Import the ResInsight Processing Server Module
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
|
# Connect to ResInsight
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
if resInsight is not None:
|
if resInsight is not None:
|
||||||
|
# Get a list of all cases
|
||||||
cases = resInsight.project.cases()
|
cases = resInsight.project.cases()
|
||||||
|
|
||||||
print ("Got " + str(len(cases)) + " cases: ")
|
print ("Got " + str(len(cases)) + " cases: ")
|
||||||
for case in cases:
|
for case in cases:
|
||||||
print(case.name)
|
print("Case name: " + case.name)
|
||||||
views = case.views()
|
print("Case grid path: " + case.gridPath())
|
||||||
for view in views:
|
|
||||||
view.setShowGridBox(not view.showGridBox())
|
|
||||||
view.setBackgroundColor("#3388AA")
|
|
||||||
view.update()
|
|
||||||
|
@ -1,22 +1,27 @@
|
|||||||
|
###############################################################################
|
||||||
|
# This example will get the cell info for the active cells for the first case
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Import the ResInsight Processing Server Module
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
|
# Connect to ResInsight
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
|
||||||
|
# Get the case with id == 0. This will fail if your project doesn't have a case with id == 0
|
||||||
case = resInsight.project.case(id = 0)
|
case = resInsight.project.case(id = 0)
|
||||||
|
|
||||||
|
# Get the cell count object
|
||||||
cellCounts = case.cellCount()
|
cellCounts = case.cellCount()
|
||||||
print("Number of active cells: " + str(cellCounts.active_cell_count))
|
print("Number of active cells: " + str(cellCounts.active_cell_count))
|
||||||
|
print("Total number of reservoir cells: " + str(cellCounts.reservoir_cell_count))
|
||||||
|
|
||||||
activeCellInfoChunks = case.cellInfoForActiveCells()
|
# Get information for all active cells
|
||||||
|
activeCellInfos = case.cellInfoForActiveCells()
|
||||||
|
|
||||||
#print("Number of grids: " + str(gridCount))
|
# A simple check on the size of the cell info
|
||||||
#print(gridDimensions)
|
assert(cellCounts.active_cell_count == len(activeCellInfos))
|
||||||
|
|
||||||
receivedActiveCells = []
|
# Print information for the first active cell
|
||||||
for activeCellChunk in activeCellInfoChunks:
|
|
||||||
for activeCell in activeCellChunk.data:
|
|
||||||
receivedActiveCells.append(activeCell)
|
|
||||||
|
|
||||||
assert(cellCounts.active_cell_count == len(receivedActiveCells))
|
|
||||||
print("First active cell: ")
|
print("First active cell: ")
|
||||||
print(receivedActiveCells[0])
|
print(activeCellInfos[0])
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
###############################################################################
|
||||||
|
# This example will run a few ResInsight command file commands
|
||||||
|
# .. which are exposed in the Python interface.
|
||||||
|
# Including setting time step, window size and export snapshots and properties
|
||||||
|
###############################################################################
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import rips
|
import rips
|
||||||
@ -8,16 +13,29 @@ resInsight = rips.Instance.find()
|
|||||||
# Run a couple of commands
|
# Run a couple of commands
|
||||||
resInsight.commands.setTimeStep(caseId=0, timeStep=3)
|
resInsight.commands.setTimeStep(caseId=0, timeStep=3)
|
||||||
resInsight.commands.setMainWindowSize(width=800, height=500)
|
resInsight.commands.setMainWindowSize(width=800, height=500)
|
||||||
#resInsight.commands.exportWellPaths()
|
|
||||||
|
# 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:
|
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||||
print("Temporary folder: ", tmpdirname)
|
print("Temporary folder: ", tmpdirname)
|
||||||
|
|
||||||
|
# Set export folder for snapshots and properties
|
||||||
resInsight.commands.setExportFolder(type='SNAPSHOTS', path=tmpdirname)
|
resInsight.commands.setExportFolder(type='SNAPSHOTS', path=tmpdirname)
|
||||||
resInsight.commands.setExportFolder(type='PROPERTIES', path=tmpdirname)
|
resInsight.commands.setExportFolder(type='PROPERTIES', path=tmpdirname)
|
||||||
|
|
||||||
|
# Export snapshots
|
||||||
resInsight.commands.exportSnapshots()
|
resInsight.commands.exportSnapshots()
|
||||||
|
|
||||||
|
# Print contents of temporary folder
|
||||||
print(os.listdir(tmpdirname))
|
print(os.listdir(tmpdirname))
|
||||||
|
|
||||||
assert(len(os.listdir(tmpdirname)) > 0)
|
assert(len(os.listdir(tmpdirname)) > 0)
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
|
# Export properties in the view
|
||||||
resInsight.commands.exportPropertyInViews(0, "3D View", 0)
|
resInsight.commands.exportPropertyInViews(0, "3D View", 0)
|
||||||
|
|
||||||
|
# Check that the exported file exists
|
||||||
expectedFileName = case.name + "-" + str("3D_View") + "-" + "T3" + "-SOIL"
|
expectedFileName = case.name + "-" + str("3D_View") + "-" + "T3" + "-SOIL"
|
||||||
fullPath = tmpdirname + "/" + expectedFileName
|
fullPath = tmpdirname + "/" + expectedFileName
|
||||||
assert(os.path.exists(fullPath))
|
assert(os.path.exists(fullPath))
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
###################################################################
|
||||||
|
# This example demonstrates the use of ResInsight exceptions
|
||||||
|
# for proper error handling
|
||||||
|
###################################################################
|
||||||
|
|
||||||
import rips
|
import rips
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
############################################################################
|
||||||
|
# This script will export snapshots for two properties in every loaded case
|
||||||
|
# And put them in a snapshots folder in the same folder as the case grid
|
||||||
|
############################################################################
|
||||||
|
import os
|
||||||
|
import rips
|
||||||
|
|
||||||
|
# Load instance
|
||||||
|
resInsight = rips.Instance.find()
|
||||||
|
cases = resInsight.project.cases()
|
||||||
|
|
||||||
|
# Set main window size
|
||||||
|
resInsight.commands.setMainWindowSize(width=800, height=500)
|
||||||
|
|
||||||
|
n = 5 # every n-th timestep for snapshot
|
||||||
|
property_list = ['SOIL', 'PRESSURE'] # list of parameter for snapshot
|
||||||
|
|
||||||
|
print ("Looping through cases")
|
||||||
|
for case in cases:
|
||||||
|
# Get grid path and its folder name
|
||||||
|
casepath = case.gridPath()
|
||||||
|
foldername = os.path.dirname(casepath)
|
||||||
|
|
||||||
|
# create a folder to hold the snapshots
|
||||||
|
dirname = os.path.join(foldername, 'snapshots')
|
||||||
|
|
||||||
|
if os.path.exists(dirname) is False:
|
||||||
|
os.mkdir(dirname)
|
||||||
|
|
||||||
|
print ("Exporting to folder: " + dirname)
|
||||||
|
resInsight.commands.setExportFolder(type='SNAPSHOTS', path=dirname)
|
||||||
|
|
||||||
|
timeSteps = case.timeSteps()
|
||||||
|
tss_snapshot = range(0, len(timeSteps), n)
|
||||||
|
print(case.name, case.id, 'Number of timesteps: ' + str(len(timeSteps)))
|
||||||
|
print('Number of timesteps for snapshoting: ' + str(len(tss_snapshot)))
|
||||||
|
|
||||||
|
view = case.view(id = 0)
|
||||||
|
for property in property_list:
|
||||||
|
view.applyCellResult(resultType='DYNAMIC_NATIVE', resultVariable=property)
|
||||||
|
for ts_snapshot in tss_snapshot:
|
||||||
|
resInsight.commands.setTimeStep(caseId = case.id, timeStep = ts_snapshot)
|
||||||
|
resInsight.commands.exportSnapshots('VIEWS') # ‘ALL’, ‘VIEWS’ or ‘PLOTS’ default is 'ALL'
|
@ -1,6 +1,11 @@
|
|||||||
|
######################################################################################
|
||||||
|
# This example prints information about the grids of all cases in the current project
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
|
||||||
cases = resInsight.project.cases()
|
cases = resInsight.project.cases()
|
||||||
print("Number of cases found: ", len(cases))
|
print("Number of cases found: ", len(cases))
|
||||||
for case in cases:
|
for case in cases:
|
||||||
|
@ -1,24 +1,38 @@
|
|||||||
|
########################################################################################
|
||||||
|
# This example generates a derived property in an asynchronous manner
|
||||||
|
# Meaning it does not wait for all the data for each stage to be read before proceeding
|
||||||
|
########################################################################################
|
||||||
import rips
|
import rips
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
# Internal function for creating a result from a small chunk of poro and permx results
|
||||||
|
# The return value of the function is a generator for the results rather than the result itself.
|
||||||
def createResult(poroChunks, permxChunks):
|
def createResult(poroChunks, permxChunks):
|
||||||
|
# Loop through all the chunks of poro and permx in order
|
||||||
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
|
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
|
||||||
resultChunk = []
|
resultChunk = []
|
||||||
|
# Loop through all the values inside the chunks, in order
|
||||||
for (poro, permx) in zip(poroChunk.values, permxChunk.values):
|
for (poro, permx) in zip(poroChunk.values, permxChunk.values):
|
||||||
resultChunk.append(poro * permx)
|
resultChunk.append(poro * permx)
|
||||||
|
# Return a generator object that behaves like a Python iterator
|
||||||
yield resultChunk
|
yield resultChunk
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
start = time.time()
|
start = time.time()
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
|
# Get a generator for the poro results. The generator will provide a chunk each time it is iterated
|
||||||
poroChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PORO', 0)
|
poroChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PORO', 0)
|
||||||
|
# Get a generator for the permx results. The generator will provide a chunk each time it is iterated
|
||||||
permxChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PERMX', 0)
|
permxChunks = case.properties.activeCellPropertyAsync('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.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks),
|
case.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks),
|
||||||
'GENERATED', 'POROPERMXAS', 0)
|
'GENERATED', 'POROPERMXAS', 0)
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print("Time elapsed: ", end - start)
|
print("Time elapsed: ", end - start)
|
||||||
|
print("Transferred all results back")
|
||||||
print("Transferred all results back")
|
view = case.views()[0].applyCellResult('GENERATED', 'POROPERMXAS')
|
@ -1,3 +1,8 @@
|
|||||||
|
########################################################################################
|
||||||
|
# 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.
|
||||||
|
########################################################################################
|
||||||
import rips
|
import rips
|
||||||
import time
|
import time
|
||||||
import grpc
|
import grpc
|
||||||
@ -6,14 +11,18 @@ resInsight = rips.Instance.find()
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
|
# Read poro result into list
|
||||||
poroResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
poroResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
||||||
|
# Read permx result into list
|
||||||
permxResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
|
permxResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
|
||||||
|
|
||||||
|
# Generate output result
|
||||||
results = []
|
results = []
|
||||||
for (poro, permx) in zip(poroResults, permxResults):
|
for (poro, permx) in zip(poroResults, permxResults):
|
||||||
results.append(poro * permx)
|
results.append(poro * permx)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Send back output result
|
||||||
case.properties.setActiveCellProperty(results, 'GENERATED', 'POROPERMXSY', 0)
|
case.properties.setActiveCellProperty(results, 'GENERATED', 'POROPERMXSY', 0)
|
||||||
except grpc.RpcError as e:
|
except grpc.RpcError as e:
|
||||||
print("Exception Received: ", e)
|
print("Exception Received: ", e)
|
||||||
@ -21,4 +30,6 @@ except grpc.RpcError as e:
|
|||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print("Time elapsed: ", end - start)
|
print("Time elapsed: ", end - start)
|
||||||
print("Transferred all results back")
|
print("Transferred all results back")
|
||||||
|
|
||||||
|
view = case.views()[0].applyCellResult('GENERATED', 'POROPERMXSY')
|
@ -1,3 +1,6 @@
|
|||||||
|
#######################################
|
||||||
|
# This example connects to ResInsight
|
||||||
|
#######################################
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
############################################################################
|
||||||
|
# This example returns the currently selected cases in ResInsight
|
||||||
|
# Because running this script in the GUI takes away the selection
|
||||||
|
# This script does not run successfully from within the ResInsight GUI
|
||||||
|
# And will need to be run from the command line separately from ResInsight
|
||||||
|
############################################################################
|
||||||
|
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
######################################################################
|
||||||
|
# This script applies a cell result to the first view in the project
|
||||||
|
######################################################################
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
######################################################################
|
||||||
|
# This script applies a flow diagnostics cell result to the first view in the project
|
||||||
|
######################################################################
|
||||||
|
|
||||||
# Load ResInsight Processing Server Client Library
|
# Load ResInsight Processing Server Client Library
|
||||||
import rips
|
import rips
|
||||||
# Connect to ResInsight instance
|
# Connect to ResInsight instance
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
######################################################################
|
||||||
|
# This script sets values for SOIL for all grid cells in the first case in the project
|
||||||
|
######################################################################
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
###########################################################################################
|
||||||
|
# This example will asynchronously calculate the average value for SOIL for all time steps
|
||||||
|
###########################################################################################
|
||||||
|
|
||||||
import rips
|
import rips
|
||||||
import itertools
|
import itertools
|
||||||
import time
|
import time
|
||||||
@ -5,16 +9,23 @@ import time
|
|||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
case = resInsight.project.case(id=0)
|
|
||||||
grid = case.grid(index = 0)
|
|
||||||
|
|
||||||
|
# Get the case with case id 0
|
||||||
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
|
# Get a list of all time steps
|
||||||
timeSteps = case.timeSteps()
|
timeSteps = case.timeSteps()
|
||||||
|
|
||||||
averages = []
|
averages = []
|
||||||
for i in range(0, len(timeSteps)):
|
for i in range(0, len(timeSteps)):
|
||||||
|
# Get the results from time step i asynchronously
|
||||||
|
# It actually returns a generator object almost immediately
|
||||||
resultChunks = case.properties.activeCellPropertyAsync('DYNAMIC_NATIVE', 'SOIL', i)
|
resultChunks = case.properties.activeCellPropertyAsync('DYNAMIC_NATIVE', 'SOIL', i)
|
||||||
mysum = 0.0
|
mysum = 0.0
|
||||||
count = 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 resultChunks:
|
for chunk in resultChunks:
|
||||||
mysum += sum(chunk.values)
|
mysum += sum(chunk.values)
|
||||||
count += len(chunk.values)
|
count += len(chunk.values)
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
averages = []
|
|
||||||
for i in range(0, 10):
|
|
||||||
values = []
|
|
||||||
|
|
||||||
sum = 0.0
|
|
||||||
count = 0
|
|
||||||
for j in range(0, 1199516):
|
|
||||||
sum += j
|
|
||||||
count += 1
|
|
||||||
|
|
||||||
averages.append(sum / count)
|
|
||||||
|
|
||||||
print (averages)
|
|
@ -1,3 +1,6 @@
|
|||||||
|
###########################################################################################
|
||||||
|
# This example will synchronously calculate the average value for SOIL for all time steps
|
||||||
|
###########################################################################################
|
||||||
import rips
|
import rips
|
||||||
import itertools
|
import itertools
|
||||||
import time
|
import time
|
||||||
@ -6,15 +9,17 @@ resInsight = rips.Instance.find()
|
|||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
grid = case.grid(index = 0)
|
|
||||||
|
|
||||||
|
# Get the case with case id 0
|
||||||
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
|
# Get a list of all time steps
|
||||||
timeSteps = case.timeSteps()
|
timeSteps = case.timeSteps()
|
||||||
|
|
||||||
averages = []
|
averages = []
|
||||||
allResults = []
|
|
||||||
for i in range(0, len(timeSteps)):
|
for i in range(0, len(timeSteps)):
|
||||||
|
# Get a list of all the results for time step i
|
||||||
results = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
|
results = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
|
||||||
allResults.append(results)
|
|
||||||
mysum = sum(results)
|
mysum = sum(results)
|
||||||
averages.append(mysum/len(results))
|
averages.append(mysum/len(results))
|
||||||
|
|
||||||
|
@ -1,32 +1,47 @@
|
|||||||
|
##############################################################################
|
||||||
|
# This example will create a derived result for each time step asynchronously
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
import rips
|
import rips
|
||||||
import time
|
import time
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
|
# Internal function for creating a result from a small chunk of soil and porv results
|
||||||
|
# The return value of the function is a generator for the results rather than the result itself.
|
||||||
def createResult(soilChunks, porvChunks):
|
def createResult(soilChunks, porvChunks):
|
||||||
for (soilChunk, porvChunk) in zip(soilChunks, porvChunks):
|
for (soilChunk, porvChunk) in zip(soilChunks, porvChunks):
|
||||||
resultChunk = []
|
resultChunk = []
|
||||||
number = 0
|
number = 0
|
||||||
npSoilChunk = np.array(soilChunk.values)
|
for (soilValue, porvValue) in zip(soilChunk.values, porvChunk.values):
|
||||||
npPorvChunk = np.array(porvChunk.values)
|
resultChunk.append(soilValue * porvValue)
|
||||||
yield npSoilChunk + npPorvChunk
|
# Return a Python generator
|
||||||
|
yield resultChunk
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
start = time.time()
|
start = time.time()
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
timeStepInfo = case.timeSteps()
|
timeStepInfo = case.timeSteps()
|
||||||
|
|
||||||
|
# Get a generator for the porv results. The generator will provide a chunk each time it is iterated
|
||||||
porvChunks = case.properties.activeCellPropertyAsync('STATIC_NATIVE', 'PORV', 0)
|
porvChunks = case.properties.activeCellPropertyAsync('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
|
||||||
|
# ... to match the soil chunks
|
||||||
porvArray = []
|
porvArray = []
|
||||||
for porvChunk in porvChunks:
|
for porvChunk in porvChunks:
|
||||||
porvArray.append(porvChunk)
|
porvArray.append(porvChunk)
|
||||||
|
|
||||||
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
|
||||||
soilChunks = case.properties.activeCellPropertyAsync('DYNAMIC_NATIVE', 'SOIL', i)
|
soilChunks = case.properties.activeCellPropertyAsync('DYNAMIC_NATIVE', 'SOIL', i)
|
||||||
input_iterator = createResult(soilChunks, iter(porvArray))
|
# Create the generator object for the SOIL * PORV derived result
|
||||||
case.properties.setActiveCellPropertyAsync(input_iterator, 'GENERATED', 'SOILPORVAsync', i)
|
result_generator = createResult(soilChunks, iter(porvArray))
|
||||||
|
# Send back the result asynchronously with a generator object
|
||||||
|
case.properties.setActiveCellPropertyAsync(result_generator, 'GENERATED', 'SOILPORVAsync', i)
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print("Time elapsed: ", end - start)
|
print("Time elapsed: ", end - start)
|
||||||
|
|
||||||
print("Transferred all results back")
|
print("Transferred all results back")
|
||||||
|
|
||||||
|
view = case.views()[0].applyCellResult('GENERATED', 'SOILPORVAsync')
|
@ -1,3 +1,7 @@
|
|||||||
|
##############################################################################
|
||||||
|
# This example will create a derived result for each time step synchronously
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
import rips
|
import rips
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -5,18 +9,25 @@ resInsight = rips.Instance.find()
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
|
# Read the full porv result
|
||||||
porvResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
|
porvResults = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
|
||||||
timeStepInfo = case.timeSteps()
|
timeStepInfo = case.timeSteps()
|
||||||
|
|
||||||
for i in range (0, len(timeStepInfo)):
|
for i in range (0, len(timeStepInfo)):
|
||||||
|
# Read the full SOIl result for time step i
|
||||||
soilResults = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
|
soilResults = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
|
||||||
|
|
||||||
|
# Generate the result by looping through both lists in order
|
||||||
results = []
|
results = []
|
||||||
for (soil, porv) in zip(soilResults, porvResults):
|
for (soil, porv) in zip(soilResults, porvResults):
|
||||||
results.append(soil * porv)
|
results.append(soil * porv)
|
||||||
|
|
||||||
|
# Send back result
|
||||||
case.properties.setActiveCellProperty(results, 'GENERATED', 'SOILPORVSync', i)
|
case.properties.setActiveCellProperty(results, 'GENERATED', 'SOILPORVSync', i)
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print("Time elapsed: ", end - start)
|
print("Time elapsed: ", end - start)
|
||||||
|
|
||||||
print("Transferred all results back")
|
print("Transferred all results back")
|
||||||
|
|
||||||
|
view = case.views()[0].applyCellResult('GENERATED', 'SOILPORVSync')
|
@ -0,0 +1,21 @@
|
|||||||
|
#############################################################
|
||||||
|
# This example will alter the views of all cases
|
||||||
|
# By setting the background color and toggle the grid box
|
||||||
|
#############################################################
|
||||||
|
import rips
|
||||||
|
# Connect to ResInsight instance
|
||||||
|
resInsight = rips.Instance.find()
|
||||||
|
|
||||||
|
# Check if connection worked
|
||||||
|
if resInsight is not None:
|
||||||
|
# Get a list of all cases
|
||||||
|
cases = resInsight.project.cases()
|
||||||
|
for case in cases:
|
||||||
|
# Get a list of all views
|
||||||
|
views = case.views()
|
||||||
|
for view in views:
|
||||||
|
# Set some parameters for the view
|
||||||
|
view.setShowGridBox(not view.showGridBox())
|
||||||
|
view.setBackgroundColor("#3388AA")
|
||||||
|
# Update the view in ResInsight
|
||||||
|
view.update()
|
Loading…
Reference in New Issue
Block a user