Ejemplo n.º 1
0
def makeTableFromLinearFunction(function,coords,time_list,name=None,columnUnits=None):
    """Constructs a table consisting of two columns.
    The first column contains a time list and the second column contains function values for space coordinates coords and times defined in the time list."""
    verifyType(time_list,ListType)
    from functions import LinearFunction
    memberShip(function,LinearFunction)
    nb_coeff = function.getNbCoefficients()
    coeffs = function.getCoefficients()
    if name:
        verifyType(name,StringType)
        tab=Table(name)
        pass
    else:
        tab = Table('Table')
        pass
    if columnUnits:
        listTypeCheck(columnUnits, StringType)
        if len(columnUnits) !=2:
            raise Exception("makeTableFromLinearFunction creates a two columns table : time and value. You have to give two units")
        tab.setColumnUnits(columnUnits)
        pass
    value_list = []
    for t in time_list:
        coo = coords + [t]
        value = function.eval(coo)
        value_list.append(value)
        pass
    tab.addColumn('time',time_list)
    tab.addColumn('value',value_list)
    return tab
Ejemplo n.º 2
0
    def setFormationReaction(self, formationReaction):
        """
        Set a formation reaction
          Input :
            formationReaction (list of tuple (string,float), ex : [('Al[3+]',1),('F[-]',2.)])
        """
        listTypeCheck(formationReaction, TupleType)
        for x in formationReaction:
            if type(x[0]) != StringType:
                raise Exception(" the first argument of the formationReaction must be a string ")
            if type(x[1]) not in [FloatType, IntType]:
                raise Exception(" the second argument of the formationReaction must be a string or a float")

        self.formationReaction = formationReaction
Ejemplo n.º 3
0
 def setFormationReaction(self,formationReaction):
     """
     Set a formation reaction
       Input :
         formationReaction (list of tuple (string,float), ex : [('Al[3+]',1),('F[-]',2.)])
     """
     listTypeCheck(formationReaction,TupleType)
     for x in formationReaction:
         if type(x[0]) != StringType:
             raise Exception(" the first argument of the formationReaction must be a string ")
         if type(x[1]) not in [FloatType,IntType]:
             raise Exception(" the second argument of the formationReaction must be a string or a float")
         
     self.formationReaction = formationReaction
Ejemplo n.º 4
0
 def amult(self, value, components='ALL'):
     new_field = self.duplicate()
     if components == 'ALL':
         #raise self.values[0,0]
         try:
             new_field.values = self.values * value
         except:
             nb_zones = self.getNbZones()
             nb_compo = self.getNbComponents()
             for f in range(nb_zones):
                 val = []
                 for i in range(nb_compo):
                     try:
                         val.append(self.values[f, i].amult(value))
                     except:
                         ##                             print 'value',value
                         ##                             print 'f,i,self.values[f,i]',f,i,self.values[f,i]
                         val.append(self.values[f, i] * value)
                         pass
                     pass
                 new_field.appendZoneValues(val)
                 pass
             #new_field.values = self.values.amult(value)
         pass
     else:
         components = toList(components)
         listTypeCheck(components, int)
         nb_zones = self.getNbZones()
         nb_compo = self.getNbComponents()
         for f in range(nb_zones):
             val = []
             for i in range(nb_compo):
                 if i in components:
                     try:
                         val.append(self.values[f, i] * value)
                     except:
                         ##                             print 'value',value
                         ##                             print 'f,i,self.values[f,i]',f,i,self.values[f,i]
                         val.append(self.values[f, i].amult(value))
                 else:
                     val.append(self.values[f, i])
                     pass
                 pass
             new_field.appendZoneValues(val)
             pass
         pass
     return new_field
Ejemplo n.º 5
0
    def amult(self,value,components='ALL'):
        new_field = self.duplicate()
        if components=='ALL':
            #raise self.values[0,0]
            try:
                new_field.values = self.values*value
            except:
                nb_zones = self.getNbZones()
                nb_compo = self.getNbComponents()
                for f in range(nb_zones):
                    val=[]
                    for i in range(nb_compo):
                        try:
                            val.append(self.values[f,i].amult(value))
                        except:
##                             print 'value',value
##                             print 'f,i,self.values[f,i]',f,i,self.values[f,i]
                            val.append(self.values[f,i]*value)
                            pass
                        pass
                    new_field.appendZoneValues(val)
                    pass
                #new_field.values = self.values.amult(value)
            pass
        else:
            components=toList(components)
            listTypeCheck(components,int)
            nb_zones = self.getNbZones()
            nb_compo = self.getNbComponents()
            for f in range(nb_zones):
                val=[]
                for i in range(nb_compo):
                    if i in components:
                        try:
                            val.append(self.values[f,i]*value)
                        except:
##                             print 'value',value
##                             print 'f,i,self.values[f,i]',f,i,self.values[f,i]
                            val.append(self.values[f,i].amult(value))
                    else:
                        val.append(self.values[f,i])
                        pass
                    pass
                new_field.appendZoneValues(val)
                pass
            pass
        return new_field
Ejemplo n.º 6
0
def makeTableFromLinearFunction(function,coords,time_list,name=None,columnUnits=None):
    """Constructs a table consisting of two columns.
    The first column contains a time list and the second column contains function values for space coordinates coords and times defined in the time list."""
    verifyType(time_list,ListType)
    from functions import LinearFunction
    memberShip(function,LinearFunction)
    nb_coeff = function.getNbCoefficients()
    coeffs = function.getCoefficients()
    if name:
        verifyType(name,StringType)
        tab=Table(name)
        pass
    else:
        tab = Table('Table')
        pass
    if columnUnits:
        listTypeCheck(columnUnits, StringType)
        if len(columnUnits) !=2:
            raise Exception("makeTableFromLinearFunction creates a two columns table : time and value. You have to give two units")
        tab.setColumnUnits(columnUnits)
        pass
    value_list = []
    for t in time_list:
        coo = coords + [t]
        value = function.eval(coo)
        value_list.append(value)
        pass
    tab.addColumn('time',time_list)
    tab.addColumn('value',value_list)
    return tab







        
            
Ejemplo n.º 7
0
 def extractSubTable(self,**dico):
     """ Creates a subtable in different ways ordered by dico keys.
     1/ if somebody wants a table with several columns, the possibilities are:
          column = a number
          columns = a number (for only one column)
                  or
                  a list of numbers (where can be only
                                     one number)
          fromcolumn = a number
          tocolumn = a number
          columnname = 'a good column name'
          columnnames = a list of column names
     2/ if somebody wants a table with several rows, the possibilities are:
          row   = a number
          rows  = a number (for only one column)
                  or
                  a list of numbers (where can be only
                                     one number)
          fromrow = a number
          torow = a number
          withvaluesincolumn = a tuple (list of values, number of column
                                        or its name, a precision if wanted)
     """
     #
     if not len(dico):
         return self.copy()
     elif len(dico)>1:
         msg='only one argument allowed.'
         raise msg
     #
     cle=list(dico.keys())[0]
     val=dico[cle]
     cle=cle.lower()
     if cle=='withvaluesincolumn':
         model,numeroColonne=val[0],val[1]
         listTypeCheck(model,[IntType,FloatType])
         model=[float(x) for x in model]
         verifyType(numeroColonne,[StringType,\
                    IntType,FloatType])
         tttitres=self.getColumnNames()
         ttunits = self.getColumnUnits()
         if type(numeroColonne) is StringType:
             for tit in tttitres:
                 if tit==numeroColonne: numCol=tttitres.index(tit)
                 pass
         else:
             if numeroColonne>=len(tttitres):
                 msg='The table does not have\n'
                 msg+='that number of columns : %s'%numeroColonne
                 raise msg
             numCol=numeroColonne
             pass
             
         if len(val)==3:
             eps=val[2]
             pass
         else:
             eps=1.e-15
             pass
         new=Table(self.getName(),tttitres,ttunits)
         nlig=self.getNbRows()
         ip=0
         comp=[float(x) for x in self.getColumn(numCol)]
         for ip in range(len(model)):
             for i in range(len(comp)):
                 value=comp[i]
                 if ip==1 and i==len(comp)-1:
                     pass
                 if areClose(value,model[ip],eps,'rel'):
                     new.addRow(self.getRow(i))
                     pass
                 if ip==len(model):
                     break
                 pass
             pass
         pass           
     else:
         valeurs=toList(val)
         tttitres=self.getColumnNames()
         ttunits = self.getColumnUnits()
         for st in ['row','column']:
             if st=='row':nn=self.getNbRows()
             if st=='column':nn=self.getNbColumns()
             if cle.find(st)>=0:
                 cleOk=st
                 pass
             if cle==st:
                 if len(valeurs) != 1:
                     raise Exception(" list length problem within the extractSubTable function")
                 pass
             if cle=='from'+st:
                 valeurs=valeurs[valeurs[0]:nn-1]
                 pass
             if cle=='to'+st:
                 valeurs=valeurs[0:valeurs[0]]
                 pass
             if cle.find('name')>=0:
                 newv=[]
                 for v in valeurs:
                     for tit in tttitres:
                         if tit==v:
                             newv.append(tttitres.index(tit))
                             break
                         pass
                     pass
                 valeurs=newv
                 pass
             pass
         if cleOk=='row':
             newtitres=tttitres
             newunits = ttunits
             pass
         if cleOk=='column':
             newtitres=[]
             newunits = []
             for i in valeurs:
                 newtitres.append(tttitres[i])
                 if len(ttunits): newunits.append(ttunits[i])
                 pass
             pass
         new=Table(self.getName(),newtitres,newunits)
         for i in valeurs:
             if cleOk=='row':
                 liste=self.getRow(i)
                 new.addRow(liste)
                 pass
             if cleOk=='column':
                 liste=self.getColumn(i)
                 new.addColumnValues(liste)
                 pass
             pass
         pass
     return new