From 67b1178b4d9367c9e0606134146e419612672330 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Thu, 24 Feb 2022 06:57:33 +0100 Subject: [PATCH] Minor documentation and code review corrections (24) --- doc/en/tui.rst | 19 ++++++++++--------- doc/fr/tui.rst | 19 ++++++++++--------- .../Physical_data_and_covariance_matrices.py | 4 ++-- test/test6701/Doc_TUI_Exemple_01.py | 2 +- test/test6702/Doc_TUI_Exemple_02.py | 10 +++++----- test/test6703/Doc_TUI_Exemple_03.py | 6 +++--- .../Doc_TUI_Exemple_03_en_multifonction.py | 6 +++--- ...erification_des_Assimilation_Algorithms.py | 12 ++++++------ 8 files changed, 40 insertions(+), 38 deletions(-) diff --git a/doc/en/tui.rst b/doc/en/tui.rst index a9dd5f6..40e1a66 100644 --- a/doc/en/tui.rst +++ b/doc/en/tui.rst @@ -63,7 +63,7 @@ ADAO calculation case. All the data are explicitly defined inside the script in order to make the reading easier. The whole set of commands is the following one:: - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) @@ -92,7 +92,7 @@ The creation and initialization of a study are done using the following commands, the ``case`` object name of the ADAO TUI calculation case being let free to the user choice:: - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() @@ -146,9 +146,10 @@ case:: import numpy def simulation(x): "Simulation function H to perform Y=H(X)" - __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T - __H = numpy.matrix("1 0 0;0 2 0;0 0 3") - return __H * __x + import numpy + __x = numpy.ravel(x) + __H = numpy.diag([1.,2.,3.]) + return __H @ __x # case.set( 'ObservationOperator', OneFunction = simulation, @@ -646,7 +647,7 @@ In addition, simple information about the case study as defined by the user can be obtained by using the Python "*print*" command directly on the case, at any stage during its design. For example:: - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) @@ -707,9 +708,9 @@ information, see the approach :ref:`section_methodology_twin`):: def simulation(x): "Simulation function H to perform Y=H(X)" import numpy - __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T - __H = numpy.matrix("1 0 0;0 2 0;0 0 3; 1 2 3") - return __H * __x + __x = numpy.ravel(x) + __H = numpy.diag([1.,2.,3.]) + return __H @ __x # # Observations obtained by simulation # ----------------------------------- diff --git a/doc/fr/tui.rst b/doc/fr/tui.rst index f3b894b..dac6e4d 100644 --- a/doc/fr/tui.rst +++ b/doc/fr/tui.rst @@ -64,7 +64,7 @@ de cas de calcul ADAO. Toutes les données sont explicitement définies dans le corps du script pour faciliter la lecture. L'ensemble des commandes est le suivant:: - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) @@ -93,7 +93,7 @@ La création et l'initialisation d'une étude se font par les commandes suivantes, le nom ``case`` de l'objet du cas de calcul TUI ADAO étant quelconque, au choix de l'utilisateur:: - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() @@ -149,9 +149,10 @@ ci-dessus) et l'enregistre dans le cas ADAO:: import numpy def simulation(x): "Fonction de simulation H pour effectuer Y=H(X)" - __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T - __H = numpy.matrix("1 0 0;0 2 0;0 0 3") - return __H * __x + import numpy + __x = numpy.ravel(x) + __H = numpy.diag([1.,2.,3.]) + return __H @ __x # case.set( 'ObservationOperator', OneFunction = simulation, @@ -674,7 +675,7 @@ De plus, on peut obtenir une information simple sur le cas d'étude tel que défini par l'utilisateur en utilisant directement la commande "*print*" de Python sur le cas, à toute étape lors de sa construction. Par exemple:: - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) @@ -736,9 +737,9 @@ jumelles (pour mémoire, voir la démarche :ref:`section_methodology_twin`):: def simulation(x): "Fonction de simulation H pour effectuer Y=H(X)" import numpy - __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T - __H = numpy.matrix("1 0 0;0 2 0;0 0 3; 1 2 3") - return __H * __x + __x = numpy.ravel(x) + __H = numpy.diag([1.,2.,3.]) + return __H @ __x # # Observations obtenues par simulation # ------------------------------------ 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 53618a9..b646e4c 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 @@ -43,9 +43,9 @@ def Simple_Matrix( size, diagonal=None ): Diagonal matrix, with either 1 or a given vector on the diagonal """ if diagonal is not None: - S = numpy.diag( diagonal ) + S = numpy.diagflat( diagonal ) else: - S = numpy.matrix(numpy.identity(int(size))) + S = numpy.identity(int(size)) return S # # ============================================================================== diff --git a/test/test6701/Doc_TUI_Exemple_01.py b/test/test6701/Doc_TUI_Exemple_01.py index ce8d209..4d4ae8a 100644 --- a/test/test6701/Doc_TUI_Exemple_01.py +++ b/test/test6701/Doc_TUI_Exemple_01.py @@ -34,7 +34,7 @@ class Test_Adao(unittest.TestCase): +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ """) #--------------------------------------------------------------------------- - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) diff --git a/test/test6702/Doc_TUI_Exemple_02.py b/test/test6702/Doc_TUI_Exemple_02.py index a43a49c..877c01e 100644 --- a/test/test6702/Doc_TUI_Exemple_02.py +++ b/test/test6702/Doc_TUI_Exemple_02.py @@ -35,7 +35,7 @@ class Test_Adao(unittest.TestCase): ++++++++++++++++++++++++++++++++++++++++++++++ Les deux resultats sont testes pour etre identiques. """) - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) @@ -53,7 +53,7 @@ class Test_Adao(unittest.TestCase): def test2(self): """Test""" - from numpy import array, matrix + from numpy import array from adao import adaoBuilder case = adaoBuilder.New() case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) @@ -63,9 +63,9 @@ class Test_Adao(unittest.TestCase): case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) def simulation(x): import numpy - __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T - __H = numpy.matrix("1 0 0;0 2 0;0 0 3") - return __H * __x + __x = numpy.ravel(x) + __H = numpy.diag([1.,2.,3.]) + return __H @ __x # case.set( 'ObservationOperator', OneFunction = simulation, diff --git a/test/test6703/Doc_TUI_Exemple_03.py b/test/test6703/Doc_TUI_Exemple_03.py index 91f5901..976145a 100644 --- a/test/test6703/Doc_TUI_Exemple_03.py +++ b/test/test6703/Doc_TUI_Exemple_03.py @@ -39,9 +39,9 @@ gammamin, gammamax = 1.5, 15.5 def simulation(x): "Fonction de simulation H pour effectuer Y=H(X)" import numpy - __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T - __H = numpy.matrix("1 0 0;0 2 0;0 0 3; 1 2 3") - return __H * __x + __x = numpy.ravel(x) + __H = numpy.diag([1.,2.,3.]) + return __H @ __x # # Observations obtenues par simulation # ------------------------------------ diff --git a/test/test6704/Doc_TUI_Exemple_03_en_multifonction.py b/test/test6704/Doc_TUI_Exemple_03_en_multifonction.py index de87ec6..184a7b7 100644 --- a/test/test6704/Doc_TUI_Exemple_03_en_multifonction.py +++ b/test/test6704/Doc_TUI_Exemple_03_en_multifonction.py @@ -39,9 +39,9 @@ gammamin, gammamax = 1.5, 15.5 def simulation(x): "Fonction de simulation H pour effectuer Y=H(X)" import numpy - __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T - __H = numpy.matrix("1 0 0;0 2 0;0 0 3; 1 2 3") - return __H * __x + __x = numpy.ravel(x) + __H = numpy.diag([1.,2.,3.]) + return __H @ __x # def multisimulation( xserie ): yserie = [] diff --git a/test/test6901/Verification_des_Assimilation_Algorithms.py b/test/test6901/Verification_des_Assimilation_Algorithms.py index ec6ed2e..223590b 100644 --- a/test/test6901/Verification_des_Assimilation_Algorithms.py +++ b/test/test6901/Verification_des_Assimilation_Algorithms.py @@ -118,8 +118,8 @@ class Test_Adao(unittest.TestCase): """Verification de la disponibilite de l'ensemble des algorithmes\n(Utilisation d'un operateur fonctionnel)""" print(self.test2.__doc__) Xa = {} - M = numpy.matrix("1 0 0;0 2 0;0 0 3") - def H(x): return M * numpy.asmatrix(numpy.ravel( x )).T + M = numpy.diag([1.,2.,3.]) + def H(x): return M @ numpy.ravel( x ) for algo in ("3DVAR", "Blue", "ExtendedBlue", "NonLinearLeastSquares", "DerivativeFreeOptimization"): print("") msg = "Algorithme en test : %s"%algo @@ -137,8 +137,8 @@ class Test_Adao(unittest.TestCase): Xa[algo] = adaopy.get("Analysis")[-1] del adaopy # - M = numpy.matrix("1 0 0;0 2 0;0 0 3") - def H(x): return M * numpy.asmatrix(numpy.ravel( x )).T + M = numpy.diag([1.,2.,3.]) + def H(x): return M @ numpy.ravel( x ) for algo in ("ExtendedKalmanFilter", "KalmanFilter", "EnsembleKalmanFilter", "UnscentedKalmanFilter", "4DVAR"): print("") msg = "Algorithme en test : %s"%algo @@ -158,8 +158,8 @@ class Test_Adao(unittest.TestCase): Xa[algo] = adaopy.get("Analysis")[-1] del adaopy # - M = numpy.matrix("1 0 0;0 1 0;0 0 1") - def H(x): return M * numpy.asmatrix(numpy.ravel( x )).T + M = numpy.identity(3) + def H(x): return M @ numpy.ravel( x ) for algo in ("ParticleSwarmOptimization", "QuantileRegression", ): print("") msg = "Algorithme en test : %s"%algo -- 2.39.2