mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-12 16:32:12 -05:00
#4462 Python Fix examples to run well with either install module or without
This commit is contained in:
1 parent
17821ade6c
commit
fe2d352f84
14 files changed
+100
-47
No files matched your search
@@ -28,6 +28,7 @@ message ReplaceCaseRequest
|
|||||||
message ReplaceSourceCasesRequest
|
message ReplaceSourceCasesRequest
|
||||||
{
|
{
|
||||||
string gridListFile = 1;
|
string gridListFile = 1;
|
||||||
|
int32 caseGroupId = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ExportMultiCaseRequest
|
message ExportMultiCaseRequest
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
import ResInsight
|
import rips
|
||||||
|
|
||||||
resInsight = ResInsight.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
|
||||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
|
||||||
|
|
||||||
case = resInsight.project.case(id = 0)
|
case = resInsight.project.case(id = 0)
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
import tempfile
|
||||||
import ResInsight
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
|
import rips
|
||||||
|
|
||||||
# Load instance
|
# Load instance
|
||||||
resInsight = ResInsight.Instance.find()
|
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()
|
#resInsight.commands.exportWellPaths()
|
||||||
|
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
|
||||||
|
print("Temporary folder: ", tmpdirname)
|
||||||
|
resInsight.commands.setExportFolder(type='SNAPSHOTS', path=tmpdirname)
|
||||||
|
resInsight.commands.exportSnapshots()
|
||||||
|
print(os.listdir(tmpdirname))
|
||||||
|
assert(len(os.listdir(tmpdirname)) > 0)
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
|
|
||||||
import ResInsight
|
import rips
|
||||||
|
|
||||||
resInsight = ResInsight.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,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
import ResInsight
|
import rips
|
||||||
|
|
||||||
def createResult(poroChunks, permxChunks):
|
def createResult(poroChunks, permxChunks):
|
||||||
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
|
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
|
||||||
@@ -11,7 +11,7 @@ def createResult(poroChunks, permxChunks):
|
|||||||
yield resultChunk
|
yield resultChunk
|
||||||
|
|
||||||
|
|
||||||
resInsight = ResInsight.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
import ResInsight
|
import rips
|
||||||
|
|
||||||
resInsight = ResInsight.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
|
|
||||||
import ResInsight
|
import rips
|
||||||
|
|
||||||
resInsight = ResInsight.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
if resInsight is not None:
|
if resInsight is not None:
|
||||||
cases = resInsight.project.selectedCases()
|
cases = resInsight.project.selectedCases()
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
import ResInsight
|
import rips
|
||||||
|
|
||||||
resInsight = ResInsight.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
|
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
totalCellCount = case.cellCount().reservoir_cell_count
|
totalCellCount = case.cellCount().reservoir_cell_count
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
import ResInsight
|
import rips
|
||||||
|
|
||||||
def createResult(soilChunks, porvChunks):
|
def createResult(soilChunks, porvChunks):
|
||||||
for (soilChunk, porvChunk) in zip(soilChunks, porvChunks):
|
for (soilChunk, porvChunk) in zip(soilChunks, porvChunks):
|
||||||
@@ -14,7 +14,7 @@ def createResult(soilChunks, porvChunks):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
resInsight = ResInsight.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
case = resInsight.project.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
timeStepInfo = case.timeSteps()
|
timeStepInfo = case.timeSteps()
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||||
import ResInsight
|
import rips
|
||||||
|
|
||||||
resInsight = ResInsight.Instance.find()
|
resInsight = rips.Instance.find()
|
||||||
case = resInsight.case(id=0)
|
case = resInsight.project.case(id=0)
|
||||||
|
|
||||||
porvChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
|
porvChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
|
||||||
porvResults = []
|
porvResults = []
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ class Case:
|
|||||||
|
|
||||||
def cellCount(self, porosityModel='MATRIX_MODEL'):
|
def cellCount(self, porosityModel='MATRIX_MODEL'):
|
||||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||||
request = Case_pb2.CellInfoRequest(request_case=self.request,
|
request = Case_pb2.CellInfoRequest(case_request=self.request,
|
||||||
porosity_model=porosityModel)
|
porosity_model=porosityModel)
|
||||||
return self.stub.GetCellCount(request)
|
return self.stub.GetCellCount(request)
|
||||||
|
|
||||||
def cellInfoForActiveCells(self, porosityModel='MATRIX_MODEL'):
|
def cellInfoForActiveCells(self, porosityModel='MATRIX_MODEL'):
|
||||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||||
request = Case_pb2.CellInfoRequest(request_case=self.request,
|
request = Case_pb2.CellInfoRequest(case_request=self.request,
|
||||||
porosity_model=porosityModel)
|
porosity_model=porosityModel)
|
||||||
return self.stub.GetCellInfoForActiveCells(request)
|
return self.stub.GetCellInfoForActiveCells(request)
|
||||||
|
|
||||||
|
|||||||
@@ -7,37 +7,81 @@ import Commands_pb2_grpc as CmdRpc
|
|||||||
|
|
||||||
class Commands:
|
class Commands:
|
||||||
def __init__(self, channel):
|
def __init__(self, channel):
|
||||||
|
self.channel = channel
|
||||||
self.commands = CmdRpc.CommandsStub(channel)
|
self.commands = CmdRpc.CommandsStub(channel)
|
||||||
|
|
||||||
def execute(self, commandParams):
|
def execute(self, **commandParams):
|
||||||
try:
|
try:
|
||||||
return self.commands.Execute(commandParams)
|
return self.commands.Execute(Cmd.CommandParams(**commandParams))
|
||||||
except grpc.RpcError as e:
|
except grpc.RpcError as e:
|
||||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||||
print("Command not found")
|
print("Command not found", commandParams.keys())
|
||||||
else:
|
else:
|
||||||
print("Other error")
|
print("Other error", e)
|
||||||
|
|
||||||
def setTimeStep(self, caseId, timeStep):
|
########################
|
||||||
return self.execute(Cmd.CommandParams(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep)))
|
# Case Control Commands
|
||||||
|
########################
|
||||||
def setMainWindowSize(self, width, height):
|
|
||||||
return self.execute(Cmd.CommandParams(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height)))
|
|
||||||
|
|
||||||
def openProject(self, path):
|
def openProject(self, path):
|
||||||
return self.execute(Cmd.CommandParams(openProject=Cmd.FilePathRequest(path=path)))
|
return self.execute(openProject=Cmd.FilePathRequest(path=path))
|
||||||
|
|
||||||
|
def closeProject(self):
|
||||||
|
return self.execute(closeProject=Empty())
|
||||||
|
|
||||||
|
def setStartDir(self, path):
|
||||||
|
return self.execute(setStartDir=Cmd.FilePathRequest(path=path))
|
||||||
|
|
||||||
def loadCase(self, path):
|
def loadCase(self, path):
|
||||||
commandReply = self.execute(Cmd.CommandParams(loadCase=Cmd.FilePathRequest(path=path)))
|
commandReply = self.execute(loadCase=Cmd.FilePathRequest(path=path))
|
||||||
assert commandReply.HasField("loadCaseResult")
|
assert commandReply.HasField("loadCaseResult")
|
||||||
return commandReply.loadCaseResult.id
|
return commandReply.loadCaseResult.id
|
||||||
|
|
||||||
def closeProject(self):
|
def replaceCase(self, path, caseId=0):
|
||||||
return self.execute(Cmd.CommandParams(closeProject=Empty()))
|
return self.execute(replaceCase=Cmd.ReplaceCaseRequest(newGridFile=path,
|
||||||
|
caseId=caseId))
|
||||||
|
|
||||||
|
def replaceSourceCases(self, gridListFile, caseGroupId=0):
|
||||||
|
return self.execute(replaceSourceCases=Cmd.ReplaceSourceCasesRequest(gridListFile=gridListFile,
|
||||||
|
caseGroupId=caseGroupId))
|
||||||
|
##################
|
||||||
|
# Export Commands
|
||||||
|
##################
|
||||||
|
|
||||||
|
def exportSnapshots(self, type = 'ALL', prefix=''):
|
||||||
|
return self.execute(exportSnapshots=Cmd.ExportSnapshotsRequest(type=type,
|
||||||
|
prefix=prefix))
|
||||||
|
|
||||||
def exportWellPaths(self, wellPaths=[], mdStepSize=5.0):
|
def exportWellPaths(self, wellPaths=[], mdStepSize=5.0):
|
||||||
if isinstance(wellPaths, str):
|
if isinstance(wellPaths, str):
|
||||||
wellPathArray = [str]
|
wellPathArray = [str]
|
||||||
elif isinstance(wellPaths, list):
|
elif isinstance(wellPaths, list):
|
||||||
wellPathArray = wellPaths
|
wellPathArray = wellPaths
|
||||||
return self.execute(Cmd.CommandParams(exportWellPaths=Cmd.ExportWellPathRequest(wellPathNames=wellPathArray, mdStepSize=mdStepSize)))
|
return self.execute(exportWellPaths=Cmd.ExportWellPathRequest(wellPathNames=wellPathArray, mdStepSize=mdStepSize))
|
||||||
|
|
||||||
|
def exportVisibleCells(self, caseId, viewName, exportKeyword='FLUXNUM', visibleActiveCellsValue=1, hiddenActiveCellsValue=0, inactiveCellsValue=0):
|
||||||
|
return self.execute(exportVisibleCells=Cmd.ExportVisibleCellsRequest(caseId=caseId,
|
||||||
|
viewName=viewName,
|
||||||
|
exportKeyword=exportKeyword,
|
||||||
|
visibleActiveCellsValue=visibleActiveCellsValue,
|
||||||
|
hiddenActiveCellsValue=hiddenActiveCellsValue,
|
||||||
|
inactiveCellsValue=inactiveCellsValue))
|
||||||
|
def setExportFolder(self, type, path, createFolder=False):
|
||||||
|
return self.execute(setExportFolder=Cmd.SetExportFolderRequest(type=type,
|
||||||
|
path=path,
|
||||||
|
createFolder=createFolder))
|
||||||
|
|
||||||
|
def runOctaveScript(self, path, cases):
|
||||||
|
caseIds = []
|
||||||
|
for case in cases:
|
||||||
|
caseIds.append(case.id)
|
||||||
|
return self.execute(runOctaveScript=Cmd.RunOctaveScriptRequest(path=path,
|
||||||
|
caseIds=caseIds))
|
||||||
|
|
||||||
|
def setMainWindowSize(self, width, height):
|
||||||
|
return self.execute(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height))
|
||||||
|
|
||||||
|
def setTimeStep(self, caseId, timeStep):
|
||||||
|
return self.execute(setTimeStep=Cmd.SetTimeStepParams(caseId=caseId, timeStep=timeStep))
|
||||||
|
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .Case import Case
|
from .Case import Case
|
||||||
|
from .Commands import Commands
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user