From: Jean-Philippe ARGAUD Date: Thu, 1 Jun 2017 13:31:04 +0000 (+0200) Subject: Python 3 compatibility improvement (examples and tests) X-Git-Tag: V8_4_0~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fff4d55f563d928e1ef03b1aa7b54e88ce96e43e;p=modules%2Fadao.git Python 3 compatibility improvement (examples and tests) --- diff --git a/examples/daSalome/test001_ADAO_JDC_using_strings.py b/examples/daSalome/test001_ADAO_JDC_using_strings.py index b5d4055..1d5955a 100644 --- a/examples/daSalome/test001_ADAO_JDC_using_strings.py +++ b/examples/daSalome/test001_ADAO_JDC_using_strings.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- study_config = {} study_config['StudyType'] = 'ASSIMILATION_STUDY' study_config['Name'] = 'Test' diff --git a/examples/daSalome/test002_ADAO_JDC_using_strings.py b/examples/daSalome/test002_ADAO_JDC_using_strings.py index aaf0dd2..83b3e12 100644 --- a/examples/daSalome/test002_ADAO_JDC_using_strings.py +++ b/examples/daSalome/test002_ADAO_JDC_using_strings.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- study_config = {} study_config['StudyType'] = 'ASSIMILATION_STUDY' study_config['Name'] = 'Test' diff --git a/examples/daSalome/test003_ADAO_JDC_using_scripts.py.in b/examples/daSalome/test003_ADAO_JDC_using_scripts.py.in index 161056f..56dfe2b 100644 --- a/examples/daSalome/test003_ADAO_JDC_using_scripts.py.in +++ b/examples/daSalome/test003_ADAO_JDC_using_scripts.py.in @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- study_config = {} study_config['StudyType'] = 'ASSIMILATION_STUDY' study_config['Name'] = 'Test' diff --git a/examples/daSalome/test003_ADAO_scripts_for_JDC.py b/examples/daSalome/test003_ADAO_scripts_for_JDC.py index be2e496..27a56b3 100644 --- a/examples/daSalome/test003_ADAO_scripts_for_JDC.py +++ b/examples/daSalome/test003_ADAO_scripts_for_JDC.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSalome/test003_bis_ADAO_JDC_using_user_data_init.py.in b/examples/daSalome/test003_bis_ADAO_JDC_using_user_data_init.py.in index 39baa1f..f44ed36 100644 --- a/examples/daSalome/test003_bis_ADAO_JDC_using_user_data_init.py.in +++ b/examples/daSalome/test003_bis_ADAO_JDC_using_user_data_init.py.in @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- study_config = {} study_config['StudyType'] = 'ASSIMILATION_STUDY' study_config['Name'] = 'Test' diff --git a/examples/daSalome/test003_bis_ADAO_scripts_for_JDC.py b/examples/daSalome/test003_bis_ADAO_scripts_for_JDC.py index 9294180..905f250 100644 --- a/examples/daSalome/test003_bis_ADAO_scripts_for_JDC.py +++ b/examples/daSalome/test003_bis_ADAO_scripts_for_JDC.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSalome/test003_bis_ADAO_user_data_init.py b/examples/daSalome/test003_bis_ADAO_user_data_init.py index 46f7902..8b666b4 100644 --- a/examples/daSalome/test003_bis_ADAO_user_data_init.py +++ b/examples/daSalome/test003_bis_ADAO_user_data_init.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSalome/test004_ADAO_JDC_using_scripts.py.in b/examples/daSalome/test004_ADAO_JDC_using_scripts.py.in index 49ad855..a2a7f3c 100644 --- a/examples/daSalome/test004_ADAO_JDC_using_scripts.py.in +++ b/examples/daSalome/test004_ADAO_JDC_using_scripts.py.in @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- study_config = {} study_config['StudyType'] = 'ASSIMILATION_STUDY' study_config['Name'] = 'Test' diff --git a/examples/daSalome/test004_ADAO_scripts_for_JDC.py b/examples/daSalome/test004_ADAO_scripts_for_JDC.py index 6a9521e..2f13dcb 100644 --- a/examples/daSalome/test004_ADAO_scripts_for_JDC.py +++ b/examples/daSalome/test004_ADAO_scripts_for_JDC.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSalome/test005_ADAO_Operators.comm.in b/examples/daSalome/test005_ADAO_Operators.comm.in index fc3dda6..8e8117a 100644 --- a/examples/daSalome/test005_ADAO_Operators.comm.in +++ b/examples/daSalome/test005_ADAO_Operators.comm.in @@ -2,7 +2,7 @@ ASSIMILATION_STUDY(StudyName='Test', StudyRepertory='@prefix@/share/salome/adao_examples/daSalome', AlgorithmParameters=_F(Algorithm='3DVAR',), - Background=_F(Stored=0, + Background=_F(Stored=1, INPUT_TYPE='Vector', data=_F(FROM='String', STRING='0 0 0',),), @@ -25,7 +25,7 @@ ASSIMILATION_STUDY(StudyName='Test', UserPostAnalysis=_F(FROM='String', STRING= """import numpy -Xb = Study.getBackground() +Xb = ADD.get("Background") Xa = ADD.get("Analysis")[-1] print print "Size of Background...........= %i"%len(Xb.A1) diff --git a/examples/daSalome/test005_ADAO_Operators.py.in b/examples/daSalome/test005_ADAO_Operators.py.in index f32d18a..e1d69dd 100644 --- a/examples/daSalome/test005_ADAO_Operators.py.in +++ b/examples/daSalome/test005_ADAO_Operators.py.in @@ -1,5 +1,5 @@ -#-*-coding:iso-8859-1-*- -study_config = {} +# -*- coding: utf-8 -*- +study_config = {} study_config['StudyType'] = 'ASSIMILATION_STUDY' study_config['Name'] = 'Test' study_config['Debug'] = '0' @@ -8,7 +8,7 @@ Background_config = {} Background_config['Type'] = 'Vector' Background_config['From'] = 'String' Background_config['Data'] = '0 0 0' -Background_config['Stored'] = '0' +Background_config['Stored'] = '1' study_config['Background'] = Background_config BackgroundError_config = {} BackgroundError_config['Type'] = 'Matrix' @@ -51,7 +51,7 @@ study_config['Repertory'] = '@prefix@/share/salome/adao_examples/daSalome' Analysis_config = {} Analysis_config['From'] = 'String' Analysis_config['Data'] = """import numpy -Xb = Study.getBackground() +Xb = ADD.get("Background") Xa = ADD.get("Analysis")[-1] print print "Size of Background...........= %i"%len(Xb.A1) diff --git a/examples/daSalome/test005_ADAO_scripts_for_JDC.py b/examples/daSalome/test005_ADAO_scripts_for_JDC.py index 2e1152e..20f5c37 100644 --- a/examples/daSalome/test005_ADAO_scripts_for_JDC.py +++ b/examples/daSalome/test005_ADAO_scripts_for_JDC.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -52,7 +52,8 @@ H = numpy.matrix(numpy.core.identity(dimension)) def FunctionH( X ): return H * X # -def AdjointH( (X, Y) ): +def AdjointH( paire ): + X, Y = paire return H.T * Y # # The possible computations diff --git a/examples/daSalome/test006_Observers.py.in b/examples/daSalome/test006_Observers.py.in index 056b712..4d2364f 100644 --- a/examples/daSalome/test006_Observers.py.in +++ b/examples/daSalome/test006_Observers.py.in @@ -1,10 +1,10 @@ -#-*-coding:iso-8859-1-*- -study_config = {} +# -*- coding: utf-8 -*- +study_config = {} study_config['StudyType'] = 'ASSIMILATION_STUDY' study_config['Name'] = 'test_observers' study_config['Debug'] = '0' study_config['Algorithm'] = '3DVAR' -AlgorithmParameters_config = {} +AlgorithmParameters_config = {} AlgorithmParameters_config['Type'] = 'Dict' AlgorithmParameters_config['From'] = 'Script' AlgorithmParameters_config['Data'] = 'test006_Observers_var.py' diff --git a/examples/daSalome/test006_Observers_Observation_Operator.py b/examples/daSalome/test006_Observers_Observation_Operator.py index 5768de4..d64337c 100644 --- a/examples/daSalome/test006_Observers_Observation_Operator.py +++ b/examples/daSalome/test006_Observers_Observation_Operator.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -54,7 +54,8 @@ def FunctionH( X ): time.sleep(1) return H * X # -def AdjointH( (X, Y) ): +def AdjointH( paire ): + X, Y = paire return H.T * Y # # The possible computations diff --git a/examples/daSalome/test006_Observers_init.py b/examples/daSalome/test006_Observers_init.py index f9645f5..f6463de 100644 --- a/examples/daSalome/test006_Observers_init.py +++ b/examples/daSalome/test006_Observers_init.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -55,10 +55,10 @@ BackgroundError = B # ---------------------------------------------------------- ObservationError = R -print xb -print B -print yo -print R +print(xb) +print(B) +print(yo) +print(R) # # Definition of the init_data dictionnary diff --git a/examples/daSalome/test006_Observers_observer_with_file.py b/examples/daSalome/test006_Observers_observer_with_file.py index 1ca883d..26fe0f8 100644 --- a/examples/daSalome/test006_Observers_observer_with_file.py +++ b/examples/daSalome/test006_Observers_observer_with_file.py @@ -1,6 +1,7 @@ -print " ---> observerState" -print " var =",var[-1] -print " info =",info +# -*- coding: utf-8 -*- +print(" ---> observerState") +print(" var =",var[-1]) +print(" info =",info) # import Gnuplot import os @@ -16,7 +17,7 @@ gp('set title "'+str(info)+'"') gp.plot( Gnuplot.Data( var[-1] ) ) filename = os.path.join("/tmp", "imageState_%02i.ps"%numero) -print " imageState \"%s\""%filename +print(" imageState \"%s\""%filename) gp.hardcopy(filename=filename, color=1) numero += 1 diff --git a/examples/daSalome/test006_Observers_var.py b/examples/daSalome/test006_Observers_var.py index 448847a..dba6172 100644 --- a/examples/daSalome/test006_Observers_var.py +++ b/examples/daSalome/test006_Observers_var.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSalome/test008_ADAO_Elementary_GradientTest.py b/examples/daSalome/test008_ADAO_Elementary_GradientTest.py index 578408c..d4347ab 100644 --- a/examples/daSalome/test008_ADAO_Elementary_GradientTest.py +++ b/examples/daSalome/test008_ADAO_Elementary_GradientTest.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- study_config = {} study_config['StudyType'] = 'CHECKING_STUDY' study_config['Name'] = 'Elementary gradient test' diff --git a/examples/daSalome/test009_ADAO_Simple_GradientTest.py b/examples/daSalome/test009_ADAO_Simple_GradientTest.py index efaf389..77b21bd 100644 --- a/examples/daSalome/test009_ADAO_Simple_GradientTest.py +++ b/examples/daSalome/test009_ADAO_Simple_GradientTest.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- study_config = {} study_config['StudyType'] = 'CHECKING_STUDY' study_config['Name'] = 'Test' diff --git a/examples/daSalome/test010_ADAO_Simple_AdjointTest.py b/examples/daSalome/test010_ADAO_Simple_AdjointTest.py index d8adb65..98a8df1 100644 --- a/examples/daSalome/test010_ADAO_Simple_AdjointTest.py +++ b/examples/daSalome/test010_ADAO_Simple_AdjointTest.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- study_config = {} study_config['StudyType'] = 'CHECKING_STUDY' study_config['Name'] = 'Test' diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Physical_data_and_covariance_matrices.py b/examples/daSkeletons/External_data_definition_by_scripts/Physical_data_and_covariance_matrices.py index baea4c8..c321dc5 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Physical_data_and_covariance_matrices.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Physical_data_and_covariance_matrices.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -51,14 +51,14 @@ def Simple_Matrix( size, diagonal=None ): # ============================================================================== if __name__ == "__main__": - print - print "AUTODIAGNOSTIC" - print "==============" + print("") + print("AUTODIAGNOSTIC") + print("==============") - print - print "True_state = ", True_state() - print - print "B or R =\n",Simple_Matrix(3) - print - print "B or R =\n",Simple_Matrix(4, diagonal=numpy.arange(4,dtype=float)) - print + print("") + print("True_state = ", True_state()) + print("") + print("B or R =\n",Simple_Matrix(3)) + print("") + print("B or R =\n",Simple_Matrix(4, diagonal=numpy.arange(4,dtype=float))) + print("") diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py b/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py index c92e03a..e1e7408 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -38,9 +38,9 @@ def DirectOperator( XX ): """ Direct non-linear simulation operator """ # # --------------------------------------> EXAMPLE TO BE REMOVED - if type(XX) is type(numpy.matrix([])): # EXAMPLE TO BE REMOVED + if isinstance(XX, type(numpy.matrix([]))): # EXAMPLE TO BE REMOVED HX = XX.A1.tolist() # EXAMPLE TO BE REMOVED - elif type(XX) is type(numpy.array([])): # EXAMPLE TO BE REMOVED + elif isinstance(XX, type(numpy.array([]))): # EXAMPLE TO BE REMOVED HX = numpy.matrix(XX).A1.tolist() # EXAMPLE TO BE REMOVED else: # EXAMPLE TO BE REMOVED HX = XX # EXAMPLE TO BE REMOVED @@ -57,13 +57,13 @@ AdjointOperator = FDA.AdjointOperator # ============================================================================== if __name__ == "__main__": - print - print "AUTODIAGNOSTIC" - print "==============" + print("") + print("AUTODIAGNOSTIC") + print("==============") from Physical_data_and_covariance_matrices import True_state X0, noms = True_state() FX = DirectOperator( X0 ) - print "FX =", FX - print + print("FX =", FX) + print("") diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_AlgorithmParameters.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_AlgorithmParameters.py index 2c6abfa..a66d710 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_AlgorithmParameters.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_AlgorithmParameters.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_BackgroundError_B.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_BackgroundError_B.py index a72bcba..6799b9d 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_BackgroundError_B.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_BackgroundError_B.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_Background_xb.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_Background_xb.py index 12c56fb..85fbe31 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_Background_xb.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_Background_xb.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationError_R.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationError_R.py index d863121..411a3d5 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationError_R.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationError_R.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py index 8af5820..e720439 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_ObservationOperator_H.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_Observation_yo.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_Observation_yo.py index 948a361..fe3c9ed 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_Observation_yo.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_Observation_yo.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py b/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py index 9a9f4fe..09ba05b 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Script_UserPostAnalysis.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -41,15 +41,15 @@ J = ADD.get("CostFunctionJ")[:] # # Verifying the results by printing # --------------------------------- -print -print "obs = [%s]"%(", ".join(["%.4f"%v for v in ADD.get("Observation").A1])) -print -print "xb = [%s]"%(", ".join(["%.4f"%v for v in ADD.get("Background").A1])) -print "xt = [%s]"%(", ".join(["%.4f"%v for v in numpy.array(xt)])) -print "xa = [%s]"%(", ".join(["%.4f"%v for v in numpy.array(xa)])) -print +print("") +print("obs = [%s]"%(", ".join(["%.4f"%v for v in ADD.get("Observation").A1]))) +print("") +print("xb = [%s]"%(", ".join(["%.4f"%v for v in ADD.get("Background").A1]))) +print("xt = [%s]"%(", ".join(["%.4f"%v for v in numpy.array(xt)]))) +print("xa = [%s]"%(", ".join(["%.4f"%v for v in numpy.array(xa)]))) +print("") for i in range( len(x_series) ): - print "Step %2i : J = %.4e X = [%s]"%(i, J[i], ", ".join(["%.4f"%v for v in x_series[i]])) -print + print("Step %2i : J = %.4e X = [%s]"%(i, J[i], ", ".join(["%.4f"%v for v in x_series[i]]))) +print("") # # ============================================================================== diff --git a/test/test1001/Versions.py b/test/test1001/Versions.py index f09f010..3189002 100644 --- a/test/test1001/Versions.py +++ b/test/test1001/Versions.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -35,39 +35,39 @@ def compare_versions(v1,v2): for s in ['+', 'rc1', 'rc2', 'rc3']: v1 = v1.replace(s,'',1) v2 = v2.replace(s,'',1) - v11,v12,v13 = map(float,v1.split('.')) - v21,v22,v23 = map(float,v2.split('.')) + v11,v12,v13 = list(map(float,v1.split('.'))) + v21,v22,v23 = list(map(float,v2.split('.'))) lv1 = 1e6*v11 + 1e3*v12 + v13 lv2 = 1e6*v21 + 1e3*v22 + v23 return lv1 >= lv2 def minimalVersion(): "Description" - print " Les versions minimales attendues sont :" - print " - Python systeme....: %s"%minimal_python_version - print " - Numpy.............: %s"%minimal_numpy_version - print " - Scipy.............: %s"%minimal_scipy_version - print " - Matplotlib........: %s"%minimal_matplotlib_version - print + print(" Les versions minimales attendues sont :") + print(" - Python systeme....: %s"%minimal_python_version) + print(" - Numpy.............: %s"%minimal_numpy_version) + print(" - Scipy.............: %s"%minimal_scipy_version) + print(" - Matplotlib........: %s"%minimal_matplotlib_version) + print("") import sys def testSysteme(): "Test des versions de modules" - print " Les versions disponibles sont :" + print(" Les versions disponibles sont :") v=sys.version.split() - print " - Python systeme....: %s"%v[0] + print(" - Python systeme....: %s"%v[0]) assert compare_versions(sys.version.split()[0], minimal_python_version) # try: import numpy - print " - Numpy.............: %s"%numpy.version.version + print(" - Numpy.............: %s"%numpy.version.version) assert compare_versions(numpy.version.version, minimal_numpy_version) except ImportError: return 1 # try: import scipy - print " - Scipy.............: %s"%scipy.version.version + print(" - Scipy.............: %s"%scipy.version.version) assert compare_versions(scipy.version.version, minimal_scipy_version) except ImportError: return 1 @@ -75,10 +75,10 @@ def testSysteme(): try: import matplotlib mplversion = matplotlib.__version__ - print " - Matplotlib........: %s"%mplversion + print(" - Matplotlib........: %s"%mplversion) assert compare_versions(mplversion, minimal_matplotlib_version) # - print + print("") backends_OK = [] backends_KO = [] backend_now = matplotlib.get_backend() @@ -93,24 +93,24 @@ def testSysteme(): except ValueError: backends_KO.append(backend) # - print " Backends disponibles pour Matplotlib %s :"%mplversion - print " Defaut initial......: '%s'"%backend_now - print " Fonctionnant........:" + print(" Backends disponibles pour Matplotlib %s :"%mplversion) + print(" Defaut initial......: '%s'"%backend_now) + print(" Fonctionnant........:") for b in backends_OK: - print " '%s'"%b - print " Non fonctionnant....:" + print(" '%s'"%b) + print(" Non fonctionnant....:") for b in backends_KO: - print " '%s'"%b - print " (Le backend 'bidon' n'est ici que pour verifier le test, il n'existe pas)" + print(" '%s'"%b) + print(" (Le backend 'bidon' n'est ici que pour verifier le test, il n'existe pas)") except ImportError: pass - print + print("") # return 0 # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\nAUTODIAGNOSTIC\n') minimalVersion() sys.exit(testSysteme()) diff --git a/test/test1002/Performances.py b/test/test1002/Performances.py index 948cc07..fdf9deb 100644 --- a/test/test1002/Performances.py +++ b/test/test1002/Performances.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -26,62 +26,62 @@ import numpy, time numpy.set_printoptions(precision=5) def testSysteme(): - print " Les caracteristiques des applications et outils systeme :" - import sys ; v=sys.version.split() ; print " - Python systeme....: %s"%v[0] - import numpy ; print " - Numpy.............: %s"%numpy.version.version + print(" Les caracteristiques des applications et outils systeme :") + import sys ; v=sys.version.split() ; print(" - Python systeme....: %s"%v[0]) + import numpy ; print(" - Numpy.............: %s"%numpy.version.version) try: - import scipy ; print " - Scipy.............: %s"%scipy.version.version + import scipy ; print(" - Scipy.............: %s"%scipy.version.version) except: - print " - Scipy.............: %s"%("absent",) + print(" - Scipy.............: %s"%("absent",)) try: - import numpy.distutils.system_info as sysinfo ; la = sysinfo.get_info('lapack') ; print " - Lapack............: %s/lib%s.so"%(la['library_dirs'][0],la['libraries'][0]) + import numpy.distutils.system_info as sysinfo ; la = sysinfo.get_info('lapack') ; print(" - Lapack............: %s/lib%s.so"%(la['library_dirs'][0],la['libraries'][0])) except: - print " - Lapack............: %s"%("absent",) - print + print(" - Lapack............: %s"%("absent",)) + print("") return True def testNumpy01(dimension = 3, precision = 1.e-17, repetitions = 10): "Test Numpy" __d = int(dimension) - print " Taille du test..................................: %.0e"%__d + print(" Taille du test..................................: %.0e"%__d) t_init = time.time() A = numpy.array([numpy.arange(dimension)+1.,]*__d) x = numpy.arange(__d)+1. - print " La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init) + print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init)) # t_init = time.time() for i in range(repetitions): b = numpy.dot(A,x) - print " La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init) + print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init)) r = [__d*(__d+1.)*(2.*__d+1.)/6.,]*__d if max(abs(b-r)) > precision: raise ValueError("Resultat du test errone (1)") else: - print " Test correct, erreur maximale inferieure a %s"%precision - print + print(" Test correct, erreur maximale inferieure a %s"%precision) + print("") del A, x, b def testNumpy02(dimension = 3, precision = 1.e-17, repetitions = 100): "Test Numpy" __d = int(dimension) - print " Taille du test..................................: %.0e"%__d + print(" Taille du test..................................: %.0e"%__d) t_init = time.time() A = numpy.random.normal(0.,1.,size=(__d,__d)) x = numpy.random.normal(0.,1.,size=(__d,)) - print " La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init) + print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init)) # t_init = time.time() for i in range(repetitions): b = numpy.dot(A,x) - print " La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init) - print + print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init)) + print("") del A, x, b # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\nAUTODIAGNOSTIC\n') testSysteme() numpy.random.seed(1000) testNumpy01(dimension = 1.e4) testNumpy02(dimension = 3.e3) - print + print("") diff --git a/test/test6701/Doc_TUI_Exemple_01.py b/test/test6701/Doc_TUI_Exemple_01.py index f2a7f91..2739eac 100644 --- a/test/test6701/Doc_TUI_Exemple_01.py +++ b/test/test6701/Doc_TUI_Exemple_01.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -42,11 +42,11 @@ def test1(): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' - print """Exemple de la doc : + print('\nAUTODIAGNOSTIC\n') + print("""Exemple de la doc : Un exemple simple de creation d'un cas de calcul TUI ADAO +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - """ + """) xa = test1() assertAlmostEqualArrays(xa, [0.25, 0.80, 0.95], places = 5) diff --git a/test/test6701/utExtend.py b/test/test6701/utExtend.py index ec9aba5..cb7b8e8 100644 --- a/test/test6701/utExtend.py +++ b/test/test6701/utExtend.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -32,7 +32,7 @@ import numpy def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None): "Compare two vectors, like unittest.assertAlmostEqual" if msg is not None: - print msg + print(msg) if delta is not None: if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any(): raise AssertionError("%s != %s within %s places"%(first,second,delta)) diff --git a/test/test6702/Doc_TUI_Exemple_02.py b/test/test6702/Doc_TUI_Exemple_02.py index 19c2a2a..9f857df 100644 --- a/test/test6702/Doc_TUI_Exemple_02.py +++ b/test/test6702/Doc_TUI_Exemple_02.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -67,14 +67,14 @@ def test2(): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' - print """Exemple de la doc : + print('\nAUTODIAGNOSTIC\n') + print("""Exemple de la doc : Creation detaillee d'un cas de calcul TUI ADAO ++++++++++++++++++++++++++++++++++++++++++++++ Les deux resultats sont testes pour etre identiques. - """ + """) xa1 = test1() xa2 = test2() ecart = assertAlmostEqualArrays(xa1, xa2, places = 15) - print " Difference maximale entre les deux : %.2e"%ecart + print(" Difference maximale entre les deux : %.2e"%ecart) diff --git a/test/test6702/utExtend.py b/test/test6702/utExtend.py index ec9aba5..cb7b8e8 100644 --- a/test/test6702/utExtend.py +++ b/test/test6702/utExtend.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -32,7 +32,7 @@ import numpy def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None): "Compare two vectors, like unittest.assertAlmostEqual" if msg is not None: - print msg + print(msg) if delta is not None: if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any(): raise AssertionError("%s != %s within %s places"%(first,second,delta)) diff --git a/test/test6703/Doc_TUI_Exemple_03.py b/test/test6703/Doc_TUI_Exemple_03.py index 44d4af6..5100c06 100644 --- a/test/test6703/Doc_TUI_Exemple_03.py +++ b/test/test6703/Doc_TUI_Exemple_03.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -94,22 +94,22 @@ def test1(): Xoptimum = case.get("Analysis")[-1] FX_at_optimum = case.get("SimulatedObservationAtOptimum")[-1] J_values = case.get("CostFunctionJ")[:] - print - print "Number of internal iterations...: %i"%len(J_values) - print "Initial state...................:",numpy.ravel(Xbackground) - print "Optimal state...................:",numpy.ravel(Xoptimum) - print "Simulation at optimal state.....:",numpy.ravel(FX_at_optimum) - print + print("") + print("Number of internal iterations...: %i"%len(J_values)) + print("Initial state...................: %s"%(numpy.ravel(Xbackground),)) + print("Optimal state...................: %s"%(numpy.ravel(Xoptimum),)) + print("Simulation at optimal state.....: %s"%(numpy.ravel(FX_at_optimum),)) + print("") # return case.get("Analysis")[-1] # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' - print """Exemple de la doc : + print('\nAUTODIAGNOSTIC\n') + print("""Exemple de la doc : Exploitation independante des resultats d'un cas de calcul ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - """ + """) xa = test1() assertAlmostEqualArrays(xa, [ 2., 3., 4.]) diff --git a/test/test6703/utExtend.py b/test/test6703/utExtend.py index ec9aba5..cb7b8e8 100644 --- a/test/test6703/utExtend.py +++ b/test/test6703/utExtend.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -32,7 +32,7 @@ import numpy def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None): "Compare two vectors, like unittest.assertAlmostEqual" if msg is not None: - print msg + print(msg) if delta is not None: if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any(): raise AssertionError("%s != %s within %s places"%(first,second,delta)) diff --git a/test/test6901/Verification_des_Assimilation_Algorithms.py b/test/test6901/Verification_des_Assimilation_Algorithms.py index e933b95..47b0b07 100644 --- a/test/test6901/Verification_des_Assimilation_Algorithms.py +++ b/test/test6901/Verification_des_Assimilation_Algorithms.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -27,9 +27,9 @@ def test1(): """Verification de la disponibilite de l'ensemble des algorithmes\n(Utilisation d'un operateur matriciel)""" Xa = {} for algo in ("3DVAR", "Blue", "ExtendedBlue", "LinearLeastSquares", "NonLinearLeastSquares", "DerivativeFreeOptimization"): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10, "Bounds":[[-1,10.],[-1,10.],[-1,10.]]}) @@ -44,9 +44,9 @@ def test1(): del adaopy # for algo in ("ExtendedKalmanFilter", "KalmanFilter", "UnscentedKalmanFilter", "4DVAR"): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10, }) @@ -63,9 +63,9 @@ def test1(): del adaopy # for algo in ("ParticleSwarmOptimization", "QuantileRegression", ): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"BoxBounds":3*[[-1,3]], "SetSeed":1000, }) @@ -80,9 +80,9 @@ def test1(): del adaopy # for algo in ("EnsembleBlue", ): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"SetSeed":1000, }) @@ -96,14 +96,14 @@ def test1(): Xa[algo] = adaopy.get("Analysis")[-1] del adaopy # - print + print("") msg = "Tests des ecarts attendus :" - print msg+"\n"+"="*len(msg) + print(msg+"\n"+"="*len(msg)) verify_similarity_of_algo_results(("3DVAR", "Blue", "ExtendedBlue", "4DVAR", "DerivativeFreeOptimization"), Xa) verify_similarity_of_algo_results(("LinearLeastSquares", "NonLinearLeastSquares"), Xa) verify_similarity_of_algo_results(("ExtendedKalmanFilter", "KalmanFilter", "UnscentedKalmanFilter"), Xa) - print " Les resultats obtenus sont corrects." - print + print(" Les resultats obtenus sont corrects.") + print("") # return 0 @@ -113,9 +113,9 @@ def test2(): M = numpy.matrix("1 0 0;0 2 0;0 0 3") def H(x): return M * numpy.asmatrix(numpy.ravel( x )).T for algo in ("3DVAR", "Blue", "ExtendedBlue", "NonLinearLeastSquares", "DerivativeFreeOptimization"): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10, "Bounds":[[-1,10.],[-1,10.],[-1,10.]]}) @@ -132,9 +132,9 @@ def test2(): M = numpy.matrix("1 0 0;0 2 0;0 0 3") def H(x): return M * numpy.asmatrix(numpy.ravel( x )).T for algo in ("ExtendedKalmanFilter", "KalmanFilter", "UnscentedKalmanFilter", "4DVAR"): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10, }) @@ -153,9 +153,9 @@ def test2(): M = numpy.matrix("1 0 0;0 1 0;0 0 1") def H(x): return M * numpy.asmatrix(numpy.ravel( x )).T for algo in ("ParticleSwarmOptimization", "QuantileRegression", ): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"BoxBounds":3*[[-1,3]], "SetSeed":1000, }) @@ -169,31 +169,31 @@ def test2(): Xa[algo] = adaopy.get("Analysis")[-1] del adaopy # - print + print("") msg = "Tests des ecarts attendus :" - print msg+"\n"+"="*len(msg) + print(msg+"\n"+"="*len(msg)) verify_similarity_of_algo_results(("3DVAR", "Blue", "ExtendedBlue", "4DVAR", "DerivativeFreeOptimization"), Xa) verify_similarity_of_algo_results(("ExtendedKalmanFilter", "KalmanFilter", "UnscentedKalmanFilter"), Xa) - print " Les resultats obtenus sont corrects." - print + print(" Les resultats obtenus sont corrects.") + print("") # return 0 def almost_equal_vectors(v1, v2, precision = 1.e-15, msg = ""): """Comparaison de deux vecteurs""" - print " Difference maximale %s: %.2e"%(msg, max(abs(v2 - v1))) + print(" Difference maximale %s: %.2e"%(msg, max(abs(v2 - v1)))) return max(abs(v2 - v1)) < precision def verify_similarity_of_algo_results(serie = [], Xa = {}): - print " Comparaisons :" + print(" Comparaisons :") for algo1 in serie: for algo2 in serie: if algo1 is algo2: break assert almost_equal_vectors( Xa[algo1], Xa[algo2], 5.e-5, "entre %s et %s "%(algo1, algo2) ) - print " Algorithmes dont les resultats sont similaires : %s\n"%(serie,) + print(" Algorithmes dont les resultats sont similaires : %s\n"%(serie,)) #=============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\nAUTODIAGNOSTIC\n') test1() test2() diff --git a/test/test6902/Verification_des_Checking_Algorithms.py b/test/test6902/Verification_des_Checking_Algorithms.py index 63a331a..936a724 100644 --- a/test/test6902/Verification_des_Checking_Algorithms.py +++ b/test/test6902/Verification_des_Checking_Algorithms.py @@ -1,4 +1,4 @@ -#-*-coding:iso-8859-1-*- +# -*- coding: utf-8 -*- # # Copyright (C) 2008-2017 EDF R&D # @@ -25,9 +25,9 @@ import adaoBuilder # ============================================================================== def test1(): for algo in ("AdjointTest", "FunctionTest", "GradientTest", "LinearityTest", "TangentTest"): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={"EpsilonMinimumExponent":-10,"NumberOfRepetition":2, "SetSeed":1000}) @@ -40,9 +40,9 @@ def test1(): del adaopy # for algo in ("ObserverTest", ): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo) @@ -56,9 +56,9 @@ def test1(): del adaopy # for algo in ("SamplingTest", ): - print + print("") msg = "Algorithme en test : %s"%algo - print msg+"\n"+"-"*len(msg) + print(msg+"\n"+"-"*len(msg)) # adaopy = adaoBuilder.New() adaopy.setAlgorithmParameters(Algorithm=algo, Parameters={ @@ -76,5 +76,5 @@ def test1(): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\nAUTODIAGNOSTIC\n') test1()