mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4462 Python Fix examples to run well with either install module or without
This commit is contained in:
parent
17821ade6c
commit
fe2d352f84
@ -28,6 +28,7 @@ message ReplaceCaseRequest
|
||||
message ReplaceSourceCasesRequest
|
||||
{
|
||||
string gridListFile = 1;
|
||||
int32 caseGroupId = 2;
|
||||
}
|
||||
|
||||
message ExportMultiCaseRequest
|
||||
|
@ -1,5 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
resInsight = rips.Instance.find()
|
||||
|
@ -1,11 +1,9 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
|
||||
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
|
||||
resInsight = rips.Instance.find()
|
||||
|
||||
case = resInsight.project.case(id = 0)
|
||||
|
||||
|
@ -1,12 +1,19 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
import tempfile
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
# Load instance
|
||||
resInsight = ResInsight.Instance.find()
|
||||
resInsight = rips.Instance.find()
|
||||
|
||||
# Run a couple of commands
|
||||
resInsight.commands.setTimeStep(caseId=0, timeStep=3)
|
||||
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 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()
|
||||
print("Number of cases found: ", len(cases))
|
||||
for case in cases:
|
||||
|
@ -1,7 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
def createResult(poroChunks, permxChunks):
|
||||
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
|
||||
@ -11,7 +11,7 @@ def createResult(poroChunks, permxChunks):
|
||||
yield resultChunk
|
||||
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
resInsight = rips.Instance.find()
|
||||
case = resInsight.project.case(id=0)
|
||||
|
||||
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
||||
|
@ -1,9 +1,9 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
resInsight = rips.Instance.find()
|
||||
|
||||
case = resInsight.project.case(id=0)
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import sys
|
||||
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:
|
||||
cases = resInsight.project.selectedCases()
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
resInsight = rips.Instance.find()
|
||||
|
||||
case = resInsight.project.case(id=0)
|
||||
totalCellCount = case.cellCount().reservoir_cell_count
|
||||
|
@ -1,7 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
def createResult(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)
|
||||
timeStepInfo = case.timeSteps()
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../api'))
|
||||
import ResInsight
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
||||
import rips
|
||||
|
||||
resInsight = ResInsight.Instance.find()
|
||||
case = resInsight.case(id=0)
|
||||
resInsight = rips.Instance.find()
|
||||
case = resInsight.project.case(id=0)
|
||||
|
||||
porvChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORV', 0)
|
||||
porvResults = []
|
||||
|
@ -41,13 +41,13 @@ class Case:
|
||||
|
||||
def cellCount(self, porosityModel='MATRIX_MODEL'):
|
||||
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)
|
||||
return self.stub.GetCellCount(request)
|
||||
|
||||
def cellInfoForActiveCells(self, porosityModel='MATRIX_MODEL'):
|
||||
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)
|
||||
return self.stub.GetCellInfoForActiveCells(request)
|
||||
|
||||
|
@ -7,37 +7,81 @@ import Commands_pb2_grpc as CmdRpc
|
||||
|
||||
class Commands:
|
||||
def __init__(self, channel):
|
||||
self.channel = channel
|
||||
self.commands = CmdRpc.CommandsStub(channel)
|
||||
|
||||
def execute(self, commandParams):
|
||||
|
||||
def execute(self, **commandParams):
|
||||
try:
|
||||
return self.commands.Execute(commandParams)
|
||||
return self.commands.Execute(Cmd.CommandParams(**commandParams))
|
||||
except grpc.RpcError as e:
|
||||
if e.code() == grpc.StatusCode.NOT_FOUND:
|
||||
print("Command not found")
|
||||
print("Command not found", commandParams.keys())
|
||||
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)))
|
||||
|
||||
def setMainWindowSize(self, width, height):
|
||||
return self.execute(Cmd.CommandParams(setMainWindowSize=Cmd.SetMainWindowSizeParams(width=width, height=height)))
|
||||
########################
|
||||
# Case Control Commands
|
||||
########################
|
||||
|
||||
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):
|
||||
commandReply = self.execute(Cmd.CommandParams(loadCase=Cmd.FilePathRequest(path=path)))
|
||||
commandReply = self.execute(loadCase=Cmd.FilePathRequest(path=path))
|
||||
assert commandReply.HasField("loadCaseResult")
|
||||
return commandReply.loadCaseResult.id
|
||||
|
||||
def closeProject(self):
|
||||
return self.execute(Cmd.CommandParams(closeProject=Empty()))
|
||||
|
||||
def replaceCase(self, path, caseId=0):
|
||||
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):
|
||||
if isinstance(wellPaths, str):
|
||||
wellPathArray = [str]
|
||||
elif isinstance(wellPaths, list):
|
||||
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
|
||||
|
||||
from .Case import Case
|
||||
from .Commands import Commands
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user