From: Jean-Philippe ARGAUD Date: Mon, 6 Mar 2017 08:30:12 +0000 (+0100) Subject: Python 3 compatibility improvement X-Git-Tag: V8_3_0rc1~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9333de839b7197422ee5be6f174509601d2d8210;p=modules%2Fadao.git Python 3 compatibility improvement --- diff --git a/src/daComposant/daCore/AssimilationStudy.py b/src/daComposant/daCore/AssimilationStudy.py index 1a76247..ac5abc9 100644 --- a/src/daComposant/daCore/AssimilationStudy.py +++ b/src/daComposant/daCore/AssimilationStudy.py @@ -324,7 +324,7 @@ class AssimilationStudy: self.__HO["AppliedToX"] = {} if type(appliedToX) is not dict: raise ValueError("Error: observation operator defined by \"appliedToX\" need a dictionary as argument.") - for key in appliedToX.keys(): + for key in list(appliedToX.keys()): if type( appliedToX[key] ) is type( numpy.matrix([]) ): # Pour le cas où l'on a une vraie matrice self.__HO["AppliedToX"][key] = numpy.matrix( appliedToX[key].A1, numpy.float ).T @@ -633,7 +633,7 @@ class AssimilationStudy: self.__algorithmFile = __import__(str(choice), globals(), locals(), []) self.__algorithmName = str(choice) sys.path = sys_path_tmp ; del sys_path_tmp - except ImportError, e: + except ImportError as e: raise ImportError("The module named \"%s\" was found, but is incorrect at the import stage.\n The import error message is: %s"%(choice,e)) # # Instancie un objet du type élémentaire du fichier @@ -683,7 +683,7 @@ class AssimilationStudy: sys_path_tmp = sys.path ; sys.path.insert(0,module_path) self.__diagnosticFile = __import__(str(choice), globals(), locals(), []) sys.path = sys_path_tmp ; del sys_path_tmp - except ImportError, e: + except ImportError as e: raise ImportError("The module named \"%s\" was found, but is incorrect at the import stage.\n The import error message is: %s"%(choice,e)) # # Instancie un objet du type élémentaire du fichier @@ -876,14 +876,14 @@ class AssimilationStudy: identifiés par les chaînes de caractères. L'algorithme doit avoir été préalablement choisi sinon la méthode renvoie "None". """ - if len( self.__algorithm.keys()) == 0 and len( self.__StoredInputs.keys() ) == 0: + if len(list(self.__algorithm.keys())) == 0 and len(list(self.__StoredInputs.keys())) == 0: return None else: variables = [] - if len( self.__algorithm.keys()) > 0: - variables.extend( self.__algorithm.get().keys() ) - if len( self.__StoredInputs.keys() ) > 0: - variables.extend( self.__StoredInputs.keys() ) + if len( list(self.__algorithm.keys())) > 0: + variables.extend( list(self.__algorithm.get().keys()) ) + if len( list(self.__StoredInputs.keys()) ) > 0: + variables.extend( list(self.__StoredInputs.keys()) ) variables.sort() return variables @@ -990,7 +990,7 @@ class AssimilationStudy: if isinstance(VariableName, str): VariableNames = [VariableName,] elif isinstance(VariableName, list): - VariableNames = map( str, VariableName ) + VariableNames = list(map( str, VariableName )) else: raise ValueError("The observer requires a name or a list of names of variables.") # @@ -1022,7 +1022,7 @@ class AssimilationStudy: if isinstance(VariableName, str): VariableNames = [VariableName,] elif isinstance(VariableName, list): - VariableNames = map( str, VariableName ) + VariableNames = list(map( str, VariableName )) else: raise ValueError("The observer requires a name or a list of names of variables.") # @@ -1079,4 +1079,4 @@ class AssimilationStudy: # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index d5a55d0..a53a9d2 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -957,4 +957,4 @@ def CostFunction3D(_x, # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daCore/ExtendedLogging.py b/src/daComposant/daCore/ExtendedLogging.py index 5b9367f..e9daddc 100644 --- a/src/daComposant/daCore/ExtendedLogging.py +++ b/src/daComposant/daCore/ExtendedLogging.py @@ -139,4 +139,4 @@ class ExtendedLogging(object): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daCore/Persistence.py b/src/daComposant/daCore/Persistence.py index 4692910..e095a38 100644 --- a/src/daComposant/daCore/Persistence.py +++ b/src/daComposant/daCore/Persistence.py @@ -905,4 +905,4 @@ class CompositePersistence(object): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daCore/PlatformInfo.py b/src/daComposant/daCore/PlatformInfo.py index 0858883..78d621b 100644 --- a/src/daComposant/daCore/PlatformInfo.py +++ b/src/daComposant/daCore/PlatformInfo.py @@ -309,4 +309,4 @@ class SystemUsage(object): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daCore/Templates.py b/src/daComposant/daCore/Templates.py index fa3bb96..60b4672 100644 --- a/src/daComposant/daCore/Templates.py +++ b/src/daComposant/daCore/Templates.py @@ -94,56 +94,56 @@ ObserverTemplates = TemplateStorage() ObserverTemplates.store( name = "ValuePrinter", - content = """print info, var[-1]""", + content = """print(str(info)+" "+str(var[-1]))""", fr_FR = "Imprime sur la sortie standard la valeur courante de la variable", en_EN = "Print on standard output the current value of the variable", order = "next", ) ObserverTemplates.store( name = "ValueAndIndexPrinter", - content = """print str(info)+" index %i:"%(len(var)-1), var[-1]""", + content = """print(str(info)+(" index %i:"%(len(var)-1))+" "+str(var[-1]))""", fr_FR = "Imprime sur la sortie standard la valeur courante de la variable, en ajoutant son index", en_EN = "Print on standard output the current value of the variable, adding its index", order = "next", ) ObserverTemplates.store( name = "ValueSeriePrinter", - content = """print info, var[:]""", + content = """print(str(info)+" "+str(var[:]))""", fr_FR = "Imprime sur la sortie standard la série des valeurs de la variable", en_EN = "Print on standard output the value series of the variable", order = "next", ) ObserverTemplates.store( name = "ValueSaver", - content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)""", + content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)""", fr_FR = "Enregistre la valeur courante de la variable dans un fichier du répertoire '/tmp' nommé 'value...txt' selon le nom de la variable et l'étape d'enregistrement", en_EN = "Save the current value of the variable in a file of the '/tmp' directory named 'value...txt' from the variable name and the saving step", order = "next", ) ObserverTemplates.store( name = "ValueSerieSaver", - content = """import numpy, re\nv=numpy.array(var[:], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)""", + content = """import numpy, re\nv=numpy.array(var[:], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)""", fr_FR = "Enregistre la série des valeurs de la variable dans un fichier du répertoire '/tmp' nommé 'value...txt' selon le nom de la variable et l'étape", en_EN = "Save the value series of the variable in a file of the '/tmp' directory named 'value...txt' from the variable name and the saving step", order = "next", ) ObserverTemplates.store( name = "ValuePrinterAndSaver", - content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nprint info,v\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)""", + content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nprint(str(info)+" "+str(v))\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)""", fr_FR = "Imprime sur la sortie standard et, en même temps enregistre dans un fichier, la valeur courante de la variable", en_EN = "Print on standard output and, in the same time save in a file, the current value of the variable", order = "next", ) ObserverTemplates.store( name = "ValueIndexPrinterAndSaver", - content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nprint str(info)+" index %i:"%(len(var)-1),v\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)""", + content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nprint(str(info)+(" index %i:"%(len(var)-1))+" "+str(v))\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)""", fr_FR = "Imprime sur la sortie standard et, en même temps enregistre dans un fichier, la valeur courante de la variable, en ajoutant son index", en_EN = "Print on standard output and, in the same time save in a file, the current value of the variable, adding its index", order = "next", ) ObserverTemplates.store( name = "ValueSeriePrinterAndSaver", - content = """import numpy, re\nv=numpy.array(var[:], ndmin=1)\nprint info,v\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)""", + content = """import numpy, re\nv=numpy.array(var[:], ndmin=1)\nprint(str(info)+" "+str(v))\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)""", fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier la série des valeurs de la variable", en_EN = "Print on standard output and, in the same time, save in a file the value series of the variable", order = "next", @@ -164,63 +164,63 @@ ObserverTemplates.store( ) ObserverTemplates.store( name = "ValuePrinterAndGnuPlotter", - content = """print info, var[-1]\nimport numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\nglobal ifig,gp\ntry:\n ifig += 1\n gp(' set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp(' set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + content = """print(str(info)+" "+str(var[-1]))\nimport numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\nglobal ifig,gp\ntry:\n ifig += 1\n gp(' set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp(' set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable", en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable", order = "next", ) ObserverTemplates.store( name = "ValueSeriePrinterAndGnuPlotter", - content = """print info, var[:] \nimport numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\nglobal ifig,gp\ntry:\n ifig += 1\n gp(' set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp(' set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + content = """print(str(info)+" "+str(var[:]))\nimport numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\nglobal ifig,gp\ntry:\n ifig += 1\n gp(' set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp(' set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la série des valeurs de la variable", en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the value series of the variable", order = "next", ) ObserverTemplates.store( name = "ValuePrinterSaverAndGnuPlotter", - content = """print info, var[-1]\nimport numpy, re\nv=numpy.array(var[-1], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal ifig,gp\ntry:\n ifig += 1\n gp(' set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp(' set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + content = """print(str(info)+" "+str(var[-1]))\nimport numpy, re\nv=numpy.array(var[-1], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal ifig,gp\ntry:\n ifig += 1\n gp(' set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp(' set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier et affiche graphiquement la valeur courante de la variable ", en_EN = "Print on standard output and, in the same, time save in a file and graphically plot the current value of the variable", order = "next", ) ObserverTemplates.store( name = "ValueSeriePrinterSaverAndGnuPlotter", - content = """print info, var[:] \nimport numpy, re\nv=numpy.array(var[:], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal ifig,gp\ntry:\n ifig += 1\n gp(' set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp(' set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + content = """print(str(info)+" "+str(var[:]))\nimport numpy, re\nv=numpy.array(var[:], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal ifig,gp\ntry:\n ifig += 1\n gp(' set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp(' set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier et affiche graphiquement la série des valeurs de la variable", en_EN = "Print on standard output and, in the same, time save in a file and graphically plot the value series of the variable", order = "next", ) ObserverTemplates.store( name = "ValueMean", - content = """import numpy\nprint info, numpy.nanmean(var[-1])""", + content = """import numpy\nprint(str(info)+" "+str(numpy.nanmean(var[-1])))""", fr_FR = "Imprime sur la sortie standard la moyenne de la valeur courante de la variable", en_EN = "Print on standard output the mean of the current value of the variable", order = "next", ) ObserverTemplates.store( name = "ValueStandardError", - content = """import numpy\nprint info, numpy.nanstd(var[-1])""", + content = """import numpy\nprint(str(info)+" "+str(numpy.nanstd(var[-1])))""", fr_FR = "Imprime sur la sortie standard l'écart-type de la valeur courante de la variable", en_EN = "Print on standard output the standard error of the current value of the variable", order = "next", ) ObserverTemplates.store( name = "ValueVariance", - content = """import numpy\nprint info, numpy.nanvar(var[-1])""", + content = """import numpy\nprint(str(info)+" "+str(numpy.nanvar(var[-1])))""", fr_FR = "Imprime sur la sortie standard la variance de la valeur courante de la variable", en_EN = "Print on standard output the variance of the current value of the variable", order = "next", ) ObserverTemplates.store( name = "ValueL2Norm", - content = """import numpy\nv = numpy.matrix( numpy.ravel( var[-1] ) )\nprint info, float( numpy.linalg.norm(v) )""", + content = """import numpy\nv = numpy.matrix( numpy.ravel( var[-1] ) )\nprint(str(info)+" "+str(float( numpy.linalg.norm(v) )))""", fr_FR = "Imprime sur la sortie standard la norme L2 de la valeur courante de la variable", en_EN = "Print on standard output the L2 norm of the current value of the variable", order = "next", ) ObserverTemplates.store( name = "ValueRMS", - content = """import numpy\nv = numpy.matrix( numpy.ravel( var[-1] ) )\nprint info, float( numpy.sqrt((1./v.size)*(v*v.T)) )""", + content = """import numpy\nv = numpy.matrix( numpy.ravel( var[-1] ) )\nprint(str(info)+" "+str(float( numpy.sqrt((1./v.size)*(v*v.T)) )))""", fr_FR = "Imprime sur la sortie standard la racine de la moyenne des carrés (RMS), ou moyenne quadratique, de la valeur courante de la variable", en_EN = "Print on standard output the root mean square (RMS), or quadratic mean, of the current value of the variable", order = "next", @@ -228,4 +228,4 @@ ObserverTemplates.store( # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daCore/version.py b/src/daComposant/daCore/version.py index 6f1be27..2c62b87 100644 --- a/src/daComposant/daCore/version.py +++ b/src/daComposant/daCore/version.py @@ -27,5 +27,5 @@ __author__ = "Jean-Philippe ARGAUD" __all__ = [] name = "Data Assimilation Package" -version = "17.02.28" -date = "samedi 28 février 2017, 12:12:12 (UTC+0100)" +version = "17.04.30" +date = "samedi 30 avril 2017, 12:12:12 (UTC+0100)"