1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2019 EDF R&D
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.
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.
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
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22 "Verification d'un exemple de la documentation"
26 # ==============================================================================
29 from numpy import array, matrix
30 from adao import adaoBuilder
31 case = adaoBuilder.New()
32 case.set( 'AlgorithmParameters', Algorithm='3DVAR' )
33 case.set( 'Background', Vector=[0, 1, 2] )
34 case.set( 'BackgroundError', ScalarSparseMatrix=1.0 )
35 case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) )
36 case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' )
37 case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' )
38 case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" )
40 case.setObserver("Analysis", String="print('==> Nombre d analyses : %i'%len(var))")
44 base_file = "output_test6711"
46 print("#===============================================================================")
48 print("#=== Restitution en dictionnaire basique =======================================")
50 print("#===============================================================================")
52 print("#=== Restitution en fichier TUI ================================================")
53 # print(case.dump(FileName=base_file+"_TUI.py", Formater="TUI"))
54 case.dump(FileName=base_file+"_TUI.py", Formater="TUI")
55 print("#===============================================================================")
57 print("#=== Restitution en fichier SCD ================================================")
58 # print(case.dump(FileName=base_file+"_SCD.py", Formater="SCD"))
59 case.dump(FileName=base_file+"_SCD.py", Formater="SCD")
60 print("#===============================================================================")
62 # print("#=== Restitution en fichier YACS ===============================================")
63 # # print(case.dump(FileName=base_file+"_YACS.xml", Formater="YACS"))
64 # case.dump(FileName=base_file+"_YACS.xml", Formater="YACS")
65 # print("#===============================================================================")
72 # base_file+"_YACS.xml",
74 if os.path.exists(os.path.abspath(cwd+"/"+f)):
75 print("#=== Fichier \"%s\" correctement généré"%f)
76 os.remove(os.path.abspath(cwd+"/"+f))
78 raise ValueError("Fichier \"%s\" inexistant"%f)
81 return case.get("Analysis")[-1]
83 # ==============================================================================
84 def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None):
85 "Compare two vectors, like unittest.assertAlmostEqual"
90 if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any():
91 raise AssertionError("%s != %s within %s places"%(first,second,delta))
93 if ( (numpy.asarray(first) - numpy.asarray(second)) > 10**(-int(places)) ).any():
94 raise AssertionError("%s != %s within %i places"%(first,second,places))
95 return max(abs(numpy.asarray(first) - numpy.asarray(second)))
97 # ==============================================================================
98 if __name__ == "__main__":
99 print('\n AUTODIAGNOSTIC\n')
100 print("""Exemple de la doc :
102 Cas-test vérifiant les conversions
103 ++++++++++++++++++++++++++++++++++
106 ecart = assertAlmostEqualArrays(xa, [0.25, 0.80, 0.95], places = 5)
108 print(" L'écart absolu maximal obtenu lors du test est de %.2e."%ecart)
109 print(" Les résultats obtenus sont corrects.")