ResInsight/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ExportSnapshots.py
Gaute Lindkvist 7bfe4f4bfe
#4603 Python: add case Id to exportSnapshots (#4604)
* #4603 Python: add case Id to exportSnapshots
* Fixup after review
2019-08-21 15:11:29 +02:00

44 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

############################################################################
# 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.views()[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(type='VIEWS', caseId=case.id) # ALL, VIEWS or PLOTS default is 'ALL'