mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Python: Update API documentation
This commit is contained in:
parent
213591f522
commit
d9d9e388da
@ -22,6 +22,7 @@ class GridCaseGroup (PdmObject):
|
|||||||
PdmObject.__init__(self, pdmObject.pb2Object, pdmObject.channel)
|
PdmObject.__init__(self, pdmObject.pb2Object, pdmObject.channel)
|
||||||
|
|
||||||
def statisticsCases(self):
|
def statisticsCases(self):
|
||||||
|
"""Get a list of all statistics cases in the Grid Case Group"""
|
||||||
statCaseCollection = self.children("StatisticsCaseCollection")[0]
|
statCaseCollection = self.children("StatisticsCaseCollection")[0]
|
||||||
return statCaseCollection.children("Reservoirs")
|
return statCaseCollection.children("Reservoirs")
|
||||||
|
|
||||||
|
@ -15,18 +15,27 @@ class PdmObject:
|
|||||||
self.pdmObjectStub = PdmObject_pb2_grpc.PdmObjectServiceStub(self.channel)
|
self.pdmObjectStub = PdmObject_pb2_grpc.PdmObjectServiceStub(self.channel)
|
||||||
|
|
||||||
def address(self):
|
def address(self):
|
||||||
|
"""Get the unique address of the PdmObject
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A 64-bit unsigned integer address
|
||||||
|
"""
|
||||||
|
|
||||||
return self.pb2Object.address
|
return self.pb2Object.address
|
||||||
|
|
||||||
def classKeyword(self):
|
def classKeyword(self):
|
||||||
|
"""Get the class keyword in the ResInsight Data Model for the given PdmObject"""
|
||||||
return self.pb2Object.class_keyword
|
return self.pb2Object.class_keyword
|
||||||
|
|
||||||
def keywords(self):
|
def keywords(self):
|
||||||
|
"""Get a list of all parameter keywords available in the object"""
|
||||||
listOfKeywords = []
|
listOfKeywords = []
|
||||||
for keyword in self.pb2Object.parameters:
|
for keyword in self.pb2Object.parameters:
|
||||||
listOfKeywords.append(keyword)
|
listOfKeywords.append(keyword)
|
||||||
return listOfKeywords
|
return listOfKeywords
|
||||||
|
|
||||||
def printObjectInfo(self):
|
def printObjectInfo(self):
|
||||||
|
"""Print the structure and data content of the PdmObject"""
|
||||||
print ("Class Keyword: " + self.classKeyword())
|
print ("Class Keyword: " + self.classKeyword())
|
||||||
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.getValue(keyword)).__name__ + "]: " + str(self.getValue(keyword)))
|
||||||
@ -65,6 +74,13 @@ class PdmObject:
|
|||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
def getValue(self, keyword):
|
def getValue(self, keyword):
|
||||||
|
"""Get the value associated with the provided keyword
|
||||||
|
Arguments:
|
||||||
|
keyword(str): A string containing the parameter keyword
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The value of the parameter. Can be int, str or list.
|
||||||
|
"""
|
||||||
value = self.pb2Object.parameters[keyword]
|
value = self.pb2Object.parameters[keyword]
|
||||||
return self.__toValue(value)
|
return self.__toValue(value)
|
||||||
|
|
||||||
@ -81,9 +97,23 @@ class PdmObject:
|
|||||||
return values
|
return values
|
||||||
|
|
||||||
def setValue(self, keyword, value):
|
def setValue(self, keyword, value):
|
||||||
|
"""Set the value associated with the provided keyword
|
||||||
|
Arguments:
|
||||||
|
keyword(str): A string containing the parameter keyword
|
||||||
|
value(varying): A value matching the type of the parameter.
|
||||||
|
See keyword documentation and/or printObjectInfo() to find
|
||||||
|
the correct data type.
|
||||||
|
"""
|
||||||
self.pb2Object.parameters[keyword] = self.__fromValue(value)
|
self.pb2Object.parameters[keyword] = self.__fromValue(value)
|
||||||
|
|
||||||
def descendants(self, classKeyword):
|
def descendants(self, classKeyword):
|
||||||
|
"""Get a list of all project tree descendants matching the class keyword
|
||||||
|
Arguments:
|
||||||
|
classKeyword[str]: A class keyword matching the type of class wanted
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A list of PdmObjects matching the keyword provided
|
||||||
|
"""
|
||||||
request = PdmObject_pb2.PdmDescendantObjectRequest(object=self.pb2Object, child_keyword=classKeyword)
|
request = PdmObject_pb2.PdmDescendantObjectRequest(object=self.pb2Object, child_keyword=classKeyword)
|
||||||
objectList = self.pdmObjectStub.GetDescendantPdmObjects(request).objects
|
objectList = self.pdmObjectStub.GetDescendantPdmObjects(request).objects
|
||||||
childList = []
|
childList = []
|
||||||
@ -92,6 +122,12 @@ class PdmObject:
|
|||||||
return childList
|
return childList
|
||||||
|
|
||||||
def children(self, childField):
|
def children(self, childField):
|
||||||
|
"""Get a list of all direct project tree children inside the provided childField
|
||||||
|
Arguments:
|
||||||
|
childField[str]: A field name
|
||||||
|
Returns:
|
||||||
|
A list of PdmObjects inside the childField
|
||||||
|
"""
|
||||||
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2Object, child_field=childField)
|
request = PdmObject_pb2.PdmChildObjectRequest(object=self.pb2Object, child_field=childField)
|
||||||
objectList = self.pdmObjectStub.GetChildPdmObjects(request).objects
|
objectList = self.pdmObjectStub.GetChildPdmObjects(request).objects
|
||||||
childList = []
|
childList = []
|
||||||
@ -100,10 +136,15 @@ class PdmObject:
|
|||||||
return childList
|
return childList
|
||||||
|
|
||||||
def ancestor(self, classKeyword):
|
def ancestor(self, classKeyword):
|
||||||
|
"""Find the first ancestor that matches the provided classKeyword
|
||||||
|
Arguments:
|
||||||
|
classKeyword[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.pb2Object, parent_keyword=classKeyword)
|
||||||
return PdmObject(self.pdmObjectStub.GetAncestorPdmObject(request), self.channel)
|
return PdmObject(self.pdmObjectStub.GetAncestorPdmObject(request), self.channel)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
"""Sync all fields from the Python Object to ResInsight"""
|
||||||
self.pdmObjectStub.UpdateExistingPdmObject(self.pb2Object)
|
self.pdmObjectStub.UpdateExistingPdmObject(self.pb2Object)
|
||||||
|
|
||||||
# def createChild(self, childField, childClassKeyword):
|
# def createChild(self, childField, childClassKeyword):
|
||||||
|
@ -117,6 +117,7 @@ class Project (PdmObject):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def gridCaseGroups(self):
|
def gridCaseGroups(self):
|
||||||
|
"""Get a list of all grid case groups in the project"""
|
||||||
caseGroups = self.descendants("RimIdenticalGridCaseGroup");
|
caseGroups = self.descendants("RimIdenticalGridCaseGroup");
|
||||||
|
|
||||||
caseGroupList = []
|
caseGroupList = []
|
||||||
@ -138,5 +139,11 @@ class Project (PdmObject):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def createGridCaseGroup(self, casePaths):
|
def createGridCaseGroup(self, casePaths):
|
||||||
|
"""Create a new grid case group from the provided case paths
|
||||||
|
Arguments:
|
||||||
|
casePaths(list): a list of paths to the cases to be loaded and included in the group
|
||||||
|
Returns:
|
||||||
|
A new grid case group object
|
||||||
|
"""
|
||||||
groupId, groupName = Commands(self.channel).createGridCaseGroup(casePaths)
|
groupId, groupName = Commands(self.channel).createGridCaseGroup(casePaths)
|
||||||
return self.gridCaseGroup(groupId)
|
return self.gridCaseGroup(groupId)
|
Loading…
Reference in New Issue
Block a user