Example #1
0
    def getProperty (self, name):
        handle = tpc.getPluginProperty (self.plugin, name)
        if handle == 0:
            raise ValueError ("Property: " + name + " does not exist")
        
        value = tpc.getProperty (handle)
        
        if tpc.getPropertyType(handle) == "telluriumData":
            return DataSeries (value)
        
        elif tpc.getPropertyType(handle) == "stringList":
            return value.split(',')
        
        elif tpc.getPropertyType(handle) == "vector<int>":
            val = value.strip('{}')
            val = val.split(',')
            return map(int, val)

        elif tpc.getPropertyType(handle) == "matrix":
            dblArray = tpc.getDataArray(value)
            
            rSize = tpc.getMatrixNumRows(value)
            cSize = tpc.getMatrixNumCols(value)            
            length = rSize*cSize            
            shape = (rSize, cSize)                                    
                                    
            arrPtr = ctypes.cast(dblArray, ctypes.POINTER(ctypes.c_double * length))                                                            
            a = np.ctypeslib.as_array((ctypes.c_double * length).from_address(ctypes.addressof(arrPtr.contents)))      
                              
            a= a.reshape(rSize,cSize)                              
            return a            
            
        else:
           return value
Example #2
0
 def setProperty(self, name, value):
     if (isinstance(value, DataSeries)):
         if not tpc.setPluginProperty(self.plugin, name, value.data):
             raise TypeError("Unable to locate property: ", name)
     else:
         handle = tpc.getPluginProperty(self.plugin, name)
         if handle == 0:
             raise ValueError("Unable to locate property: ", name)
         t1 = tpc.getPropertyType(handle)
         if (t1 == "listOfProperties"):
             if isinstance(value, list):
                 if len(value) != 2:
                     raise TypeError(
                         "Expecting two elements in the property list")
                 if not isinstance(value[0], str):
                     raise TypeError(
                         "Expecting property name in first element of list")
                 if (not isinstance(value[1], float)) and (isinstance(
                         value[1], int)):
                     raise TypeError(
                         "Expecting floating value in second element of list"
                     )
                 para1 = tpc.createProperty(value[0], "double", "",
                                            value[1])
                 tpc.addPropertyToList(handle, para1)
             else:
                 raise TypeError("Expecting a list in setProperty")
         else:
             tpc.setPluginProperty(self.plugin, name, value)
Example #3
0
 def listOfPropertyHints (self):
     nameList = tpc.getListOfPluginPropertyNames (self.plugin)
     aList = []
     for i in range (0, len (nameList)):
         name = nameList[i]
         handle = tpc.getPluginProperty(self.plugin, nameList[i])
         descr = tpc.getPropertyHint(handle)
         aList.append ([name, descr])
     return aList
Example #4
0
 def listOfPropertyHints(self):
     nameList = tpc.getListOfPluginPropertyNames(self.plugin)
     aList = []
     for i in range(0, len(nameList)):
         name = nameList[i]
         handle = tpc.getPluginProperty(self.plugin, nameList[i])
         descr = tpc.getPropertyHint(handle)
         aList.append([name, descr])
     return aList
Example #5
0
 def listOfProperties (self):
     if not self:
         return []
     nameList = tpc.getListOfPluginPropertyNames (self.plugin)
     aList = []
     for i in range (0, len (nameList)):
         name = nameList[i]
         handle = tpc.getPluginProperty(self.plugin, nameList[i])
         hint = tpc.getPropertyHint(handle)
         aList.append ([name, hint])
     return aList
Example #6
0
 def listOfProperties(self):
     if not self:
         return []
     nameList = tpc.getListOfPluginPropertyNames(self.plugin)
     aList = []
     for i in range(0, len(nameList)):
         name = nameList[i]
         handle = tpc.getPluginProperty(self.plugin, nameList[i])
         hint = tpc.getPropertyHint(handle)
         aList.append([name, hint])
     return aList
Example #7
0
 def setProperty(self, name, value):
     if (isinstance (value, DataSeries)):
        if not tpc.setPluginProperty (self.plugin, name, value.data):
           raise TypeError ("Unable to locate property: ", name)
     else:
        handle  = tpc.getPluginProperty(self.plugin, name);
        if handle == 0:
           raise ValueError ("Unable to locate property: ", name)
        t1 = tpc.getPropertyType (handle)
        if (t1 == "listOfProperties"):
           if isinstance (value, list):
              if len(value) != 2:
                 raise TypeError ("Expecting two elements in the property list")
              if not isinstance(value[0], str):
                  raise TypeError("Expecting property name in first element of list")
              if (not isinstance(value[1], float)) and (isinstance(value[1], int)):
                  raise TypeError("Expecting floating value in second element of list")
              para1 = tpc.createProperty(value[0], "double", "", value[1])
              tpc.addPropertyToList (handle, para1)
           else:
              raise  TypeError ("Expecting a list in setProperty")
        else:
           tpc.setPluginProperty (self.plugin, name, value)
Example #8
0
    def getProperty(self, name):
        handle = tpc.getPluginProperty(self.plugin, name)
        if handle == 0:
            raise ValueError("Property: " + name + " does not exist")

        value = tpc.getProperty(handle)

        if tpc.getPropertyType(handle) == "telluriumData":
            return DataSeries(value)

        elif tpc.getPropertyType(handle) == "stringList":
            return value.split(',')

        elif tpc.getPropertyType(handle) == "vector<int>":
            val = value.strip('{}')
            val = val.split(',')
            return map(int, val)

        elif tpc.getPropertyType(handle) == "matrix":
            dblArray = tpc.getDataArray(value)

            rSize = tpc.getMatrixNumRows(value)
            cSize = tpc.getMatrixNumCols(value)
            length = rSize * cSize
            shape = (rSize, cSize)

            arrPtr = ctypes.cast(dblArray,
                                 ctypes.POINTER(ctypes.c_double * length))
            a = np.ctypeslib.as_array((ctypes.c_double * length).from_address(
                ctypes.addressof(arrPtr.contents)))

            a = a.reshape(rSize, cSize)
            return a

        else:
            return value