Salome HOME
Temporary YACS dump analysis for V9
[modules/adao.git] / test / test6711 / Doc_TUI_Exemple_01_Savings.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2018 EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22 "Verification d'un exemple de la documentation"
23
24 import os, pprint
25 from utExtend import assertAlmostEqualArrays
26
27 # ==============================================================================
28 def test1():
29     """Test"""
30     from numpy import array, matrix
31     import adaoBuilder
32     case = adaoBuilder.New()
33     case.set( 'AlgorithmParameters', Algorithm='3DVAR' )
34     case.set( 'Background',          Vector=[0, 1, 2] )
35     case.set( 'BackgroundError',     ScalarSparseMatrix=1.0 )
36     case.set( 'Observation',         Vector=array([0.5, 1.5, 2.5]) )
37     case.set( 'ObservationError',    DiagonalSparseMatrix='1 1 1' )
38     case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' )
39     case.set( 'Observer',            Variable="Analysis", Template="ValuePrinter" )
40     #
41     case.setObserver("Analysis", String="print('==> Nombre d analyses   : %i'%len(var))")
42     #
43     case.execute()
44     #
45     base_file = "output_test6711"
46     print("")
47     print("#===============================================================================")
48     #
49     print("#=== Restitution en dictionnaire basique =======================================")
50     case.get()
51     print("#===============================================================================")
52     #
53     print("#=== Restitution en fichier TUI ================================================")
54     # print(case.dump(FileName=base_file+"_TUI.py", Formater="TUI"))
55     case.dump(FileName=base_file+"_TUI.py", Formater="TUI")
56     print("#===============================================================================")
57     #
58     print("#=== Restitution en fichier SCD ================================================")
59     # print(case.dump(FileName=base_file+"_SCD.py", Formater="SCD"))
60     case.dump(FileName=base_file+"_SCD.py", Formater="SCD")
61     print("#===============================================================================")
62     #
63     #   print("#=== Restitution en fichier YACS ===============================================")
64     #   # print(case.dump(FileName=base_file+"_YACS.xml", Formater="YACS"))
65     #   case.dump(FileName=base_file+"_YACS.xml", Formater="YACS")
66     #   print("#===============================================================================")
67     #
68     print("")
69     cwd = os.getcwd()
70     for f in [
71         base_file+"_TUI.py",
72         base_file+"_SCD.py",
73         # base_file+"_YACS.xml",
74         ]:
75         if os.path.exists(os.path.abspath(cwd+"/"+f)):
76             print("#=== Fichier \"%s\" correctement généré"%f)
77             os.remove(os.path.abspath(cwd+"/"+f))
78         else:
79             raise ValueError("Fichier \"%s\" inexistant"%f)
80     print("")
81     #
82     return case.get("Analysis")[-1]
83
84 # ==============================================================================
85 if __name__ == "__main__":
86     print('\n AUTODIAGNOSTIC\n')
87     print("""Exemple de la doc :
88
89     Cas-test vérifiant les conversions
90     ++++++++++++++++++++++++++++++++++
91 """)
92     xa = test1()
93     assertAlmostEqualArrays(xa, [0.25, 0.80, 0.95], places = 5)