This commit is contained in:
Gaute Lindkvist
2019-09-19 13:48:03 +02:00
parent 9bc2781817
commit 9a0f135431
7 changed files with 123 additions and 124 deletions

View File

@@ -48,7 +48,7 @@ class Case (PdmObject):
return 0 return 0
def grid_path(self): def grid_path(self):
return self.getValue("CaseFileName") return self.get_value("CaseFileName")
def grid(self, index): 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
@@ -132,9 +132,9 @@ class Case (PdmObject):
""" """
active_cell_info_chunks = self.cell_info_for_active_cells_async() active_cell_info_chunks = self.cell_info_for_active_cells_async()
received_active_cells = [] received_active_cells = []
for activeCellChunk in active_cell_info_chunks: for active_cell_chunk in active_cell_info_chunks:
for activeCell in activeCellChunk.data: for active_cell in active_cell_chunk.data:
received_active_cells.append(activeCell) received_active_cells.append(active_cell)
return received_active_cells return received_active_cells
def time_steps(self): def time_steps(self):
@@ -162,10 +162,10 @@ class Case (PdmObject):
def views(self): def views(self):
"""Get a list of views belonging to a case""" """Get a list of views belonging to a case"""
pdm_objects = self.children("ReservoirViews") pdm_objects = self.children("ReservoirViews")
viewList = [] view_list = []
for pdm_object in pdm_objects: for pdm_object in pdm_objects:
viewList.append(View(pdm_object)) view_list.append(View(pdm_object))
return viewList return view_list
def view(self, id): def view(self, id):
"""Get a particular view belonging to a case by providing view id """Get a particular view belonging to a case by providing view id

View File

@@ -14,11 +14,10 @@ class GridCaseGroup (PdmObject):
Operate on a ResInsight case group specified by a Case Group Id integer. Operate on a ResInsight case group specified by a Case Group Id integer.
Attributes: Attributes:
id (int): Grid Case Group Id corresponding to case group Id in ResInsight project. group_id (int): Grid Case Group Id corresponding to case group Id in ResInsight project.
name (str): Case name
""" """
def __init__(self, pdm_object): def __init__(self, pdm_object):
self.groupId = pdm_object.getValue("GroupId") self.group_id = pdm_object.get_value("GroupId")
PdmObject.__init__(self, pdm_object.pb2Object, pdm_object.channel) PdmObject.__init__(self, pdm_object.pb2Object, pdm_object.channel)
def statistics_cases(self): def statistics_cases(self):
@@ -28,10 +27,10 @@ class GridCaseGroup (PdmObject):
def views(self): def views(self):
"""Get a list of views belonging to a grid case group""" """Get a list of views belonging to a grid case group"""
pbm_objects = self.descendants("ReservoirView") pdm_objects = self.descendants("ReservoirView")
view_list = [] view_list = []
for pbm_object in pbm_objects: for pdm_object in pdm_objects:
view_list.append(View(pbm_object)) view_list.append(View(pdm_object))
return view_list return view_list
def view(self, id): def view(self, id):

View File

@@ -9,10 +9,10 @@ import PdmObject_pb2
import PdmObject_pb2_grpc import PdmObject_pb2_grpc
class PdmObject: class PdmObject:
def __init__(self, pb2Object, channel): def __init__(self, pb2_object, channel):
self.pb2Object = pb2Object self.pb2_object = pb2_object
self.channel = channel self.channel = channel
self.pdmObjectStub = PdmObject_pb2_grpc.PdmObjectServiceStub(self.channel) self.pdm_object_stub = PdmObject_pb2_grpc.PdmObjectServiceStub(self.channel)
def address(self): def address(self):
"""Get the unique address of the PdmObject """Get the unique address of the PdmObject
@@ -21,59 +21,59 @@ class PdmObject:
A 64-bit unsigned integer address A 64-bit unsigned integer address
""" """
return self.pb2Object.address return self.pb2_object.address
def classKeyword(self): def class_keyword(self):
"""Get the class keyword in the ResInsight Data Model for the given PdmObject""" """Get the class keyword in the ResInsight Data Model for the given PdmObject"""
return self.pb2Object.class_keyword return self.pb2_object.class_keyword
def keywords(self): def keywords(self):
"""Get a list of all parameter keywords available in the object""" """Get a list of all parameter keywords available in the object"""
listOfKeywords = [] list_of_keywords = []
for keyword in self.pb2Object.parameters: for keyword in self.pb2_object.parameters:
listOfKeywords.append(keyword) list_of_keywords.append(keyword)
return listOfKeywords return list_of_keywords
def printObjectInfo(self): def print_object_info(self):
"""Print the structure and data content of the PdmObject""" """Print the structure and data content of the PdmObject"""
print ("Class Keyword: " + self.classKeyword()) print ("Class Keyword: " + self.class_keyword())
for keyword in self.keywords(): for keyword in self.keywords():
print(keyword + " [" + type(self.getValue(keyword)).__name__ + "]: " + str(self.getValue(keyword))) print(keyword + " [" + type(self.get_value(keyword)).__name__ + "]: " + str(self.get_value(keyword)))
def __toValue(self, value): def __to_value(self, value):
if value.lower() == 'false': if value.lower() == 'false':
return False return False
elif value.lower() == 'true': elif value.lower() == 'true':
return True return True
else: else:
try: try:
intVal = int(value) int_val = int(value)
return intVal return int_val
except ValueError: except ValueError:
try: try:
floatVal = float(value) float_val = float(value)
return floatVal return float_val
except ValueError: except ValueError:
# We may have a string. Strip internal start and end quotes # We may have a string. Strip internal start and end quotes
value = value.strip('\"') value = value.strip('\"')
if self.__islist(value): if self.__islist(value):
return self.__makelist(value) return self.__makelist(value)
return value return value
def __fromValue(self, value): def __from_value(self, value):
if isinstance(value, bool): if isinstance(value, bool):
if value: if value:
return "true" return "true"
else: else:
return "false" return "false"
elif isinstance(value, list): elif isinstance(value, list):
listofstrings = [] list_of_strings = []
for val in value: for val in value:
listofstrings.append(self.__fromValue('\"' + val + '\"')) list_of_strings.append(self.__from_value('\"' + val + '\"'))
return "[" + ", ".join(listofstrings) + "]" return "[" + ", ".join(list_of_strings) + "]"
else: else:
return str(value) return str(value)
def getValue(self, keyword): def get_value(self, keyword):
"""Get the value associated with the provided keyword """Get the value associated with the provided keyword
Arguments: Arguments:
keyword(str): A string containing the parameter keyword keyword(str): A string containing the parameter keyword
@@ -81,72 +81,72 @@ class PdmObject:
Returns: Returns:
The value of the parameter. Can be int, str or list. The value of the parameter. Can be int, str or list.
""" """
value = self.pb2Object.parameters[keyword] value = self.pb2_object.parameters[keyword]
return self.__toValue(value) return self.__to_value(value)
def __islist(self, value): def __islist(self, value):
return value.startswith("[") and value.endswith("]") return value.startswith("[") and value.endswith("]")
def __makelist(self, liststring): def __makelist(self, list_string):
liststring = liststring.lstrip("[") list_string = list_string.lstrip("[")
liststring = liststring.rstrip("]") list_string = list_string.rstrip("]")
strings = liststring.split(", ") strings = list_string.split(", ")
values = [] values = []
for string in strings: for string in strings:
values.append(self.__toValue(string)) values.append(self.__to_value(string))
return values return values
def setValue(self, keyword, value): def set_value(self, keyword, value):
"""Set the value associated with the provided keyword """Set the value associated with the provided keyword
Arguments: Arguments:
keyword(str): A string containing the parameter keyword keyword(str): A string containing the parameter keyword
value(varying): A value matching the type of the parameter. value(varying): A value matching the type of the parameter.
See keyword documentation and/or printObjectInfo() to find See keyword documentation and/or print_object_info() to find
the correct data type. the correct data type.
""" """
self.pb2Object.parameters[keyword] = self.__fromValue(value) self.pb2_object.parameters[keyword] = self.__from_value(value)
def descendants(self, classKeyword): def descendants(self, class_keyword):
"""Get a list of all project tree descendants matching the class keyword """Get a list of all project tree descendants matching the class keyword
Arguments: Arguments:
classKeyword[str]: A class keyword matching the type of class wanted class_keyword[str]: A class keyword matching the type of class wanted
Returns: Returns:
A list of PdmObjects matching the keyword provided A list of PdmObjects matching the keyword provided
""" """
request = PdmObject_pb2.PdmDescendantObjectRequest(object=self.pb2Object, child_keyword=classKeyword) request = PdmObject_pb2.PdmDescendantObjectRequest(object=self.pb2_object, child_keyword=class_keyword)
objectList = self.pdmObjectStub.GetDescendantPdmObjects(request).objects object_list = self.pdm_object_stub.GetDescendantPdmObjects(request).objects
childList = [] child_list = []
for object in objectList: for object in object_list:
childList.append(PdmObject(object, self.channel)) child_list.append(PdmObject(object, self.channel))
return childList return child_list
def children(self, childField): def children(self, child_field):
"""Get a list of all direct project tree children inside the provided childField """Get a list of all direct project tree children inside the provided child_field
Arguments: Arguments:
childField[str]: A field name child_field[str]: A field name
Returns: Returns:
A list of PdmObjects inside the childField A list of PdmObjects inside the child_field
""" """
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2Object, child_field=childField) request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2_object, child_field=child_field)
objectList = self.pdmObjectStub.GetChildPdmObjects(request).objects object_list = self.pdm_object_stub.GetChildPdmObjects(request).objects
childList = [] child_list = []
for object in objectList: for object in object_list:
childList.append(PdmObject(object, self.channel)) child_list.append(PdmObject(object, self.channel))
return childList return child_list
def ancestor(self, classKeyword): def ancestor(self, class_keyword):
"""Find the first ancestor that matches the provided classKeyword """Find the first ancestor that matches the provided class_keyword
Arguments: Arguments:
classKeyword[str]: A class keyword matching the type of class wanted class_keyword[str]: A class keyword matching the type of class wanted
""" """
request = PdmObject_pb2.PdmParentObjectRequest(object=self.pb2Object, parent_keyword=classKeyword) request = PdmObject_pb2.PdmParentObjectRequest(object=self.pb2_object, parent_keyword=class_keyword)
return PdmObject(self.pdmObjectStub.GetAncestorPdmObject(request), self.channel) return PdmObject(self.pdm_object_stub.GetAncestorPdmObject(request), self.channel)
def update(self): def update(self):
"""Sync all fields from the Python Object to ResInsight""" """Sync all fields from the Python Object to ResInsight"""
self.pdmObjectStub.UpdateExistingPdmObject(self.pb2Object) self.pdm_object_stub.UpdateExistingPdmObject(self.pb2_object)
# def createChild(self, childField, childClassKeyword): # def createChild(self, child_field, childClassKeyword):
# childRequest = PdmObject_pb2.CreatePdmChildObjectRequest(object=self.pb2Object, child_field=childField, child_class=childClassKeyword) # childRequest = PdmObject_pb2.CreatePdmChildObjectRequest(object=self.pb2Object, child_field=child_field, child_class=childClassKeyword)
# return PdmObject(self.pdmObjectStub.CreateChildPdmObject(childRequest), self.channel) # return PdmObject(self.pdmObjectStub.CreateChildPdmObject(childRequest), self.channel)

View File

@@ -11,19 +11,19 @@ for casePath in casePaths:
caseGroup = resinsight.project.create_grid_case_group(casePaths=casePaths) caseGroup = resinsight.project.create_grid_case_group(casePaths=casePaths)
caseGroup.printObjectInfo() caseGroup.print_object_info()
#statCases = caseGroup.statistics_cases() #statCases = caseGroup.statistics_cases()
#caseIds = [] #caseIds = []
#for statCase in statCases: #for statCase in statCases:
# statCase.setValue("DynamicPropertiesToCalculate", ["SWAT"]) # statCase.set_value("DynamicPropertiesToCalculate", ["SWAT"])
# statCase.update() # statCase.update()
# caseIds.append(statCase.getValue("CaseId")) # caseIds.append(statCase.get_value("CaseId"))
resinsight.commands.compute_case_group_statistics(caseGroupId=caseGroup.groupId) resinsight.commands.compute_case_group_statistics(caseGroupId=caseGroup.groupId)
view = caseGroup.views()[0] view = caseGroup.views()[0]
cellResult = view.cellResult() cellResult = view.cellResult()
cellResult.setValue("ResultVariable", "PRESSURE_DEV") cellResult.set_value("ResultVariable", "PRESSURE_DEV")
cellResult.update() cellResult.update()

View File

@@ -10,25 +10,25 @@ class View (PdmObject):
""" """
def __init__(self, pbmObject): def __init__(self, pbmObject):
self.id = pbmObject.getValue("ViewId") self.id = pbmObject.get_value("ViewId")
PdmObject.__init__(self, pbmObject.pb2Object, pbmObject.channel) PdmObject.__init__(self, pbmObject.pb2Object, pbmObject.channel)
def showGridBox(self): def showGridBox(self):
"""Check if the grid box is meant to be shown in the view""" """Check if the grid box is meant to be shown in the view"""
return self.getValue("ShowGridBox") return self.get_value("ShowGridBox")
def setShowGridBox(self, value): def setShowGridBox(self, value):
"""Set if the grid box is meant to be shown in the view""" """Set if the grid box is meant to be shown in the view"""
self.setValue("ShowGridBox", value) self.set_value("ShowGridBox", value)
def backgroundColor(self): def backgroundColor(self):
"""Get the current background color in the view""" """Get the current background color in the view"""
return self.getValue("ViewBackgroundColor") return self.get_value("ViewBackgroundColor")
def setBackgroundColor(self, bgColor): def setBackgroundColor(self, bgColor):
"""Set the background color in the view""" """Set the background color in the view"""
self.setValue("ViewBackgroundColor", bgColor) self.set_value("ViewBackgroundColor", bgColor)
def cellResult(self): def cellResult(self):
"""Retrieve the current cell results""" """Retrieve the current cell results"""
@@ -50,8 +50,8 @@ class View (PdmObject):
resultVariable (str): String representing the result variable. resultVariable (str): String representing the result variable.
""" """
cellResult = self.cellResult() cellResult = self.cellResult()
cellResult.setValue("ResultType", resultType) cellResult.set_value("ResultType", resultType)
cellResult.setValue("ResultVariable", resultVariable) cellResult.set_value("ResultVariable", resultVariable)
cellResult.update() cellResult.update()
def applyFlowDiagnosticsCellResult(self, def applyFlowDiagnosticsCellResult(self,
@@ -77,12 +77,12 @@ class View (PdmObject):
Requires selectionMode to be 'FLOW_TR_BY_SELECTION'. Requires selectionMode to be 'FLOW_TR_BY_SELECTION'.
""" """
cellResult = self.cellResult() cellResult = self.cellResult()
cellResult.setValue("ResultType", "FLOW_DIAGNOSTICS") cellResult.set_value("ResultType", "FLOW_DIAGNOSTICS")
cellResult.setValue("ResultVariable", resultVariable) cellResult.set_value("ResultVariable", resultVariable)
cellResult.setValue("FlowTracerSelectionMode", selectionMode) cellResult.set_value("FlowTracerSelectionMode", selectionMode)
if selectionMode == 'FLOW_TR_BY_SELECTION': if selectionMode == 'FLOW_TR_BY_SELECTION':
cellResult.setValue("SelectedInjectorTracers", injectors) cellResult.set_value("SelectedInjectorTracers", injectors)
cellResult.setValue("SelectedProducerTracers", producers) cellResult.set_value("SelectedProducerTracers", producers)
cellResult.update() cellResult.update()
def case(self): def case(self):
@@ -92,7 +92,7 @@ class View (PdmObject):
pdmCase = self.ancestor("ResInsightGeoMechCase") pdmCase = self.ancestor("ResInsightGeoMechCase")
if pdmCase is None: if pdmCase is None:
return None return None
return rips.Case(self.channel, pdmCase.getValue("CaseId")) return rips.Case(self.channel, pdmCase.get_value("CaseId"))
def clone(self): def clone(self):
"""Clone the current view""" """Clone the current view"""

View File

@@ -22,60 +22,60 @@ def test_OneCase(rips_instance, initialize_test):
assert(len(cases) is 1) assert(len(cases) is 1)
def test_MultipleCases(rips_instance, initialize_test): def test_MultipleCases(rips_instance, initialize_test):
casePaths = [] case_paths = []
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID") case_paths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID") case_paths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
casePaths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID") case_paths.append(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID")
caseNames = [] case_names = []
for casePath in casePaths: for case_path in case_paths:
caseName = os.path.splitext(os.path.basename(casePath))[0] case_name = os.path.splitext(os.path.basename(case_path))[0]
caseNames.append(caseName) case_names.append(case_name)
rips_instance.project.load_case(path=casePath) rips_instance.project.load_case(path=case_path)
cases = rips_instance.project.cases() cases = rips_instance.project.cases()
assert(len(cases) == len(caseNames)) assert(len(cases) == len(case_names))
for i, caseName in enumerate(caseNames): for i, case_name in enumerate(case_names):
assert(caseName == cases[i].name) assert(case_name == cases[i].name)
def test_10k(rips_instance, initialize_test): def test_10k(rips_instance, initialize_test):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=casePath) case = rips_instance.project.load_case(path=case_path)
assert(case.grid_count() == 2) assert(case.grid_count() == 2)
cellCountInfo = case.cell_count() cell_count_info = case.cell_count()
assert(cellCountInfo.active_cell_count == 11125) assert(cell_count_info.active_cell_count == 11125)
assert(cellCountInfo.reservoir_cell_count == 316224) assert(cell_count_info.reservoir_cell_count == 316224)
timeSteps = case.time_steps() time_steps = case.time_steps()
assert(len(timeSteps) == 9) assert(len(time_steps) == 9)
daysSinceStart = case.days_since_start() days_since_start = case.days_since_start()
assert(len(daysSinceStart) == 9) assert(len(days_since_start) == 9)
def test_PdmObject(rips_instance, initialize_test): def test_PdmObject(rips_instance, initialize_test):
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=casePath) case = rips_instance.project.load_case(path=case_path)
assert(case.id == 0) assert(case.id == 0)
assert(case.address() is not 0) assert(case.address() is not 0)
assert(case.classKeyword() == "EclipseCase") assert(case.class_keyword() == "EclipseCase")
caseId = case.getValue('CaseId') case_id = case.get_value('CaseId')
assert(caseId == case.id) assert(case_id == case.id)
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux") @pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
def test_brugge_0010(rips_instance, initialize_test): def test_brugge_0010(rips_instance, initialize_test):
casePath = dataroot.PATH + "/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID" case_path = dataroot.PATH + "/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID"
case = rips_instance.project.load_case(path=casePath) case = rips_instance.project.load_case(path=case_path)
assert(case.grid_count() == 1) assert(case.grid_count() == 1)
cellCountInfo = case.cell_count() cellCountInfo = case.cell_count()
assert(cellCountInfo.active_cell_count == 43374) assert(cellCountInfo.active_cell_count == 43374)
assert(cellCountInfo.reservoir_cell_count == 60048) assert(cellCountInfo.reservoir_cell_count == 60048)
timeSteps = case.time_steps() time_steps = case.time_steps()
assert(len(timeSteps) == 11) assert(len(time_steps) == 11)
daysSinceStart = case.days_since_start() days_since_start = case.days_since_start()
assert(len(daysSinceStart) == 11) assert(len(days_since_start) == 11)
@pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux") @pytest.mark.skipif(sys.platform.startswith('linux'), reason="Brugge is currently exceptionally slow on Linux")
def test_replaceCase(rips_instance, initialize_test): def test_replaceCase(rips_instance, initialize_test):
project = rips_instance.project.open(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp") project = rips_instance.project.open(dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp")
casePath = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID" case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
case = project.case(id=0) case = project.case(id=0)
assert(case is not None) assert(case is not None)
assert(case.name == "TEST10K_FLT_LGR_NNC") assert(case.name == "TEST10K_FLT_LGR_NNC")
@@ -83,7 +83,7 @@ def test_replaceCase(rips_instance, initialize_test):
cases = rips_instance.project.cases() cases = rips_instance.project.cases()
assert(len(cases) is 1) assert(len(cases) is 1)
rips_instance.commands.replace_case(newGridFile=casePath, caseId=case.id) rips_instance.commands.replace_case(new_grid_file=case_path, case_id=case.id)
cases = rips_instance.project.cases() cases = rips_instance.project.cases()
assert(len(cases) is 1) assert(len(cases) is 1)
case = project.case(id=0) case = project.case(id=0)

View File

@@ -10,7 +10,7 @@ import rips
import dataroot import dataroot
def test_exportSnapshots(rips_instance, initialize_test): def test_exportSnapshots(rips_instance, initialize_test):
if not rips_instance.isGui(): if not rips_instance.is_gui():
pytest.skip("Cannot run test without a GUI") pytest.skip("Cannot run test without a GUI")
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"