mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 23:46:00 -06:00
Python: fix up some examples
This commit is contained in:
parent
6701e13664
commit
055cb732db
@ -156,6 +156,8 @@ if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
||||
"rips/Project.py"
|
||||
"rips/Properties.py"
|
||||
"rips/Instance.py"
|
||||
"rips/examples/AppInfo.py"
|
||||
"rips/examples/InstanceExample.py"
|
||||
"rips/examples/CommandExample.py"
|
||||
"rips/examples/CaseInfoStreamingExample.py"
|
||||
"rips/examples/SoilPorvAsync.py"
|
||||
|
@ -17,9 +17,9 @@ class Case:
|
||||
methods in Project: loadCase, case, allCases, selectedCases
|
||||
|
||||
Attributes:
|
||||
id(int): Case Id corresponding to case Id in ResInsight project.
|
||||
name(string): Case name
|
||||
groupId(int): Case Group id
|
||||
id (int): Case Id corresponding to case Id in ResInsight project.
|
||||
name (str): Case name
|
||||
groupId (int): Case Group id
|
||||
"""
|
||||
def __init__(self, channel, id):
|
||||
self.channel = channel
|
||||
@ -43,7 +43,13 @@ class Case:
|
||||
return 0
|
||||
|
||||
def grid(self, index):
|
||||
"""Get Grid of a given index. Returns a rips Grid object"""
|
||||
"""Get Grid of a given index. Returns a rips Grid object
|
||||
|
||||
Arguments:
|
||||
index (int): The grid index
|
||||
|
||||
Returns: Grid object
|
||||
"""
|
||||
return Grid(index, self)
|
||||
|
||||
def grids(self):
|
||||
@ -58,7 +64,7 @@ class Case:
|
||||
total number of cells
|
||||
|
||||
Arguments:
|
||||
porosityModel(string): String representing an enum.
|
||||
porosityModel (str): String representing an enum.
|
||||
must be 'MATRIX_MODEL' or 'FRACTURE_MODEL'.
|
||||
Returns:
|
||||
Cell Count object with the following integer attributes:
|
||||
@ -72,9 +78,11 @@ class Case:
|
||||
|
||||
def cellInfoForActiveCells(self, porosityModel='MATRIX_MODEL'):
|
||||
"""Get Stream of cell info objects for current case
|
||||
|
||||
Arguments:
|
||||
porosityModel(string): String representing an enum.
|
||||
porosityModel(str): String representing an enum.
|
||||
must be 'MATRIX_MODEL' or 'FRACTURE_MODEL'.
|
||||
|
||||
Returns:
|
||||
Stream of cell info objects with the following attributes:
|
||||
grid_index(int): grid the cell belongs to
|
||||
@ -82,6 +90,7 @@ class Case:
|
||||
coarsening_box_index(int): the coarsening box index
|
||||
local_ijk(Vec3i: i(int), j(int), k(int)): local cell index in i, j, k directions.
|
||||
parent_ijk(Vec3i: i(int), j(int), k(int)): cell index in parent grid in i, j, k.
|
||||
|
||||
"""
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
request = Case_pb2.CellInfoRequest(case_request=self.request,
|
||||
|
@ -16,8 +16,9 @@ class Commands:
|
||||
https://resinsight.org/docs/commandfile/
|
||||
|
||||
The differences are:
|
||||
1. Enum values have to be provided as strings. I.e. "ALL" instead of ALL.
|
||||
2. Booleans have to be specified as correct Python. True instead of true.
|
||||
* Enum values have to be provided as strings. I.e. "ALL" instead of ALL.
|
||||
* Booleans have to be specified as correct Python. True instead of true.
|
||||
|
||||
"""
|
||||
def __init__(self, channel):
|
||||
self.channel = channel
|
||||
@ -37,24 +38,61 @@ class Commands:
|
||||
########################
|
||||
|
||||
def openProject(self, path):
|
||||
"""Open a project
|
||||
|
||||
Arguments:
|
||||
path (str): path to project file
|
||||
|
||||
|
||||
"""
|
||||
return self.__execute(openProject=Cmd.FilePathRequest(path=path))
|
||||
|
||||
def closeProject(self):
|
||||
"""Close the current project (and reopen empty one)"""
|
||||
return self.__execute(closeProject=Empty())
|
||||
|
||||
def setStartDir(self, path):
|
||||
"""Set current start directory
|
||||
|
||||
Arguments:
|
||||
path (str): path to directory
|
||||
|
||||
"""
|
||||
return self.__execute(setStartDir=Cmd.FilePathRequest(path=path))
|
||||
|
||||
def loadCase(self, path):
|
||||
"""Load a case
|
||||
|
||||
Arguments:
|
||||
path (str): path to EGRID file
|
||||
|
||||
Returns:
|
||||
A Case object
|
||||
|
||||
"""
|
||||
commandReply = self.__execute(loadCase=Cmd.FilePathRequest(path=path))
|
||||
assert commandReply.HasField("loadCaseResult")
|
||||
return Case(self.channel, commandReply.loadCaseResult.id)
|
||||
|
||||
def replaceCase(self, path, caseId=0):
|
||||
return self.__execute(replaceCase=Cmd.ReplaceCaseRequest(newGridFile=path,
|
||||
def replaceCase(self, newGridFile, caseId=0):
|
||||
"""Replace the given case with a new case loaded from file
|
||||
|
||||
Arguments:
|
||||
newGridFile (str): path to EGRID file
|
||||
caseId (int): case Id to replace
|
||||
|
||||
"""
|
||||
return self.__execute(replaceCase=Cmd.ReplaceCaseRequest(newGridFile=newGridFile,
|
||||
caseId=caseId))
|
||||
|
||||
def replaceSourceCases(self, gridListFile, caseGroupId=0):
|
||||
"""Replace all source cases within a case group
|
||||
|
||||
Arguments:
|
||||
gridListFile (str): path to file containing a list of cases
|
||||
caseGroupId (int): id of the case group to replace
|
||||
|
||||
"""
|
||||
return self.__execute(replaceSourceCases=Cmd.ReplaceSourceCasesRequest(gridListFile=gridListFile,
|
||||
caseGroupId=caseGroupId))
|
||||
##################
|
||||
@ -62,13 +100,36 @@ class Commands:
|
||||
##################
|
||||
|
||||
def exportMultiCaseSnapshots(self, gridListFile):
|
||||
"""Export snapshots for a set of cases
|
||||
|
||||
Arguments:
|
||||
gridListFile (str): Path to a file containing a list of grids to export snapshot for
|
||||
|
||||
"""
|
||||
return self.__execute(exportMultiCaseSnapshot=Cmd.ExportMultiCaseRequest(gridListFile=gridListFile))
|
||||
|
||||
def exportSnapshots(self, type = 'ALL', prefix=''):
|
||||
""" Export snapshots of a given type
|
||||
|
||||
Arguments:
|
||||
type (str): Enum string ('ALL', 'VIEWS' or 'PLOTS')
|
||||
prefix (str): Exported file name prefix
|
||||
|
||||
"""
|
||||
return self.__execute(exportSnapshots=Cmd.ExportSnapshotsRequest(type=type,
|
||||
prefix=prefix))
|
||||
|
||||
def exportProperty(self, caseId, timeStep, property, eclipseKeyword=property, undefinedValue=0.0, exportFile=property):
|
||||
""" Export an Eclipse property
|
||||
|
||||
Arguments:
|
||||
caseId (int): case id
|
||||
timeStep (int): time step index
|
||||
property (str): property to export
|
||||
eclipseKeyword (str): Eclipse keyword used as text in export header. Defaults to the value of property parameter.
|
||||
undefinedValue (double): Value to use for undefined values. Defaults to 0.0
|
||||
exportFile (str): Filename for export. Defaults to the value of property parameter
|
||||
"""
|
||||
return self.__execute(exportProperty=Cmd.ExportPropertyRequest(caseId=caseId,
|
||||
timeStep=timeStep,
|
||||
property=property,
|
||||
|
@ -17,11 +17,11 @@ class Instance:
|
||||
"""The ResInsight Instance class. Use to launch or find existing ResInsight instances
|
||||
|
||||
Attributes:
|
||||
launched(bool): Tells us whether the application was launched as a new process.
|
||||
launched (bool): Tells us whether the application was launched as a new process.
|
||||
If the application was launched we may need to close it when exiting the script.
|
||||
app(App): Application information object. Set when creating an instance.
|
||||
commands(Commands): Command executor. Set when creating an instance.
|
||||
project(Project): Current project in ResInsight.
|
||||
app (App): Application information object. Set when creating an instance.
|
||||
commands (Commands): Command executor. Set when creating an instance.
|
||||
project (Project): Current project in ResInsight.
|
||||
Set when creating an instance and updated when opening/closing projects.
|
||||
"""
|
||||
|
||||
@ -83,8 +83,8 @@ class Instance:
|
||||
RESINSIGHT_GRPC_PORT to RESINSIGHT_GRPC_PORT+20
|
||||
|
||||
Args:
|
||||
startPort(int): start searching from this port
|
||||
endPort(int): search up to but not including this port
|
||||
startPort (int): start searching from this port
|
||||
endPort (int): search up to but not including this port
|
||||
"""
|
||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||
if portEnv:
|
||||
|
@ -23,8 +23,8 @@ class Project:
|
||||
def open(self, path):
|
||||
"""Open a new project from the given path
|
||||
|
||||
Argument:
|
||||
path(string): path to project file
|
||||
Arguments:
|
||||
path(str): path to project file
|
||||
|
||||
"""
|
||||
Commands(self.channel).openProject(path)
|
||||
@ -84,7 +84,7 @@ class Project:
|
||||
"""Load a new case from the given file path
|
||||
|
||||
Arguments:
|
||||
path(string): file path to case
|
||||
path(str): file path to case
|
||||
Returns:
|
||||
A rips Case object
|
||||
"""
|
||||
|
@ -55,18 +55,20 @@ class Properties:
|
||||
def available(self, propertyType, porosityModel = 'MATRIX_MODEL'):
|
||||
"""Get a list of available properties
|
||||
|
||||
Arguments:
|
||||
propertyType(string): string corresponding to propertyType enum
|
||||
Can be one of the following:
|
||||
'DYNAMIC_NATIVE'
|
||||
'STATIC_NATIVE'
|
||||
'SOURSIMRL'
|
||||
'GENERATED'
|
||||
'INPUT_PROPERTY'
|
||||
'FORMATION_NAMES'
|
||||
'FLOW_DIAGNOSTICS'
|
||||
'INJECTION_FLOODING'
|
||||
porosityModel(string): 'MATRIX_MODEL' or 'FRACTURE_MODEL'.
|
||||
Arguments:
|
||||
propertyType (str): string corresponding to propertyType enum.
|
||||
|
||||
Can be one of the following:
|
||||
|
||||
'DYNAMIC_NATIVE'
|
||||
'STATIC_NATIVE'
|
||||
'SOURSIMRL'
|
||||
'GENERATED'
|
||||
'INPUT_PROPERTY'
|
||||
'FORMATION_NAMES'
|
||||
'FLOW_DIAGNOSTICS'
|
||||
'INJECTION_FLOODING'
|
||||
porosityModel(str): 'MATRIX_MODEL' or 'FRACTURE_MODEL'.
|
||||
"""
|
||||
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
@ -80,10 +82,10 @@ class Properties:
|
||||
"""Get a cell property for all active cells. Async, so returns an iterator
|
||||
|
||||
Arguments:
|
||||
propertyType(string): string enum. See available()
|
||||
propertyName(string): name of an Eclipse property
|
||||
propertyType(str): string enum. See available()
|
||||
propertyName(str): name of an Eclipse property
|
||||
timeStep(int): the time step for which to get the property for
|
||||
porosityModel(string): string enum. See available()
|
||||
porosityModel(str): string enum. See available()
|
||||
|
||||
Returns:
|
||||
An iterator to a chunk object containing an array of double values
|
||||
@ -103,11 +105,11 @@ class Properties:
|
||||
"""Get a cell property for all grid cells. Async, so returns an iterator
|
||||
|
||||
Arguments:
|
||||
propertyType(string): string enum. See available()
|
||||
propertyName(string): name of an Eclipse property
|
||||
propertyType(str): string enum. See available()
|
||||
propertyName(str): name of an Eclipse property
|
||||
timeStep(int): the time step for which to get the property for
|
||||
gridIndex(int): index to the grid we're getting values for
|
||||
porosityModel(string): string enum. See available()
|
||||
porosityModel(str): string enum. See available()
|
||||
|
||||
Returns:
|
||||
An iterator to a chunk object containing an array of double values
|
||||
@ -129,10 +131,10 @@ class Properties:
|
||||
|
||||
Arguments:
|
||||
values_iterator(iterator): an iterator to the properties to be set
|
||||
propertyType(string): string enum. See available()
|
||||
propertyName(string): name of an Eclipse property
|
||||
propertyType(str): string enum. See available()
|
||||
propertyName(str): name of an Eclipse property
|
||||
timeStep(int): the time step for which to get the property for
|
||||
porosityModel(string): string enum. See available()
|
||||
porosityModel(str): string enum. See available()
|
||||
"""
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
@ -155,10 +157,10 @@ class Properties:
|
||||
|
||||
Arguments:
|
||||
values(list): a list of double precision floating point numbers
|
||||
propertyType(string): string enum. See available()
|
||||
propertyName(string): name of an Eclipse property
|
||||
propertyType(str): string enum. See available()
|
||||
propertyName(str): name of an Eclipse property
|
||||
timeStep(int): the time step for which to get the property for
|
||||
porosityModel(string): string enum. See available()
|
||||
porosityModel(str): string enum. See available()
|
||||
"""
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
@ -181,11 +183,11 @@ class Properties:
|
||||
|
||||
Arguments:
|
||||
values(list): a list of double precision floating point numbers
|
||||
propertyType(string): string enum. See available()
|
||||
propertyName(string): name of an Eclipse property
|
||||
propertyType(str): string enum. See available()
|
||||
propertyName(str): name of an Eclipse property
|
||||
timeStep(int): the time step for which to get the property for
|
||||
gridIndex(int): index to the grid we're setting values for
|
||||
porosityModel(string): string enum. See available()
|
||||
porosityModel(str): string enum. See available()
|
||||
"""
|
||||
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)
|
||||
porosityModelEnum = Case_pb2.PorosityModelType.Value(porosityModel)
|
||||
|
@ -3,3 +3,6 @@ from .Case import Case
|
||||
from .Grid import Grid
|
||||
from .Properties import Properties
|
||||
from .Instance import Instance
|
||||
from .App import App
|
||||
from .Commands import Commands
|
||||
from .Project import Project
|
@ -0,0 +1,10 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
resInsight = rips.Instance.find()
|
||||
if resInsight is not None:
|
||||
print(resInsight.app.versionString())
|
||||
print("Is this a console run?", resInsight.app.isConsole())
|
@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
|
||||
import rips
|
||||
import time
|
||||
|
||||
@ -11,7 +12,6 @@ def createResult(poroChunks, permxChunks):
|
||||
resultChunk.append(poro * permx)
|
||||
yield resultChunk
|
||||
|
||||
|
||||
resInsight = rips.Instance.find()
|
||||
start = time.time()
|
||||
case = resInsight.project.case(id=0)
|
||||
@ -19,7 +19,8 @@ case = resInsight.project.case(id=0)
|
||||
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
|
||||
permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
|
||||
|
||||
case.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks), 'GENERATED', 'POROPERMXAS', 0)
|
||||
case.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks),
|
||||
'GENERATED', 'POROPERMXAS', 0)
|
||||
|
||||
end = time.time()
|
||||
print("Time elapsed: ", end - start)
|
||||
|
@ -1,6 +1,7 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
|
||||
import rips
|
||||
import time
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||
import rips
|
||||
|
||||
resInsight = rips.Instance.find()
|
||||
|
||||
if resInsight is None:
|
||||
print('ERROR: could not find ResInsight')
|
@ -6,7 +6,7 @@ with open('README.md') as f:
|
||||
with open('LICENSE') as f:
|
||||
license = f.read()
|
||||
|
||||
RIPS_DIST_VERSION = '8'
|
||||
RIPS_DIST_VERSION = '9'
|
||||
|
||||
setup(
|
||||
name='rips',
|
||||
|
Loading…
Reference in New Issue
Block a user