Salome HOME
Update and documentation of InputValuesTest
[modules/adao.git] / src / daComposant / daAlgorithms / InputValuesTest.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008-2020 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
23 import sys, logging
24 import numpy
25 from daCore import BasicObjects
26
27 # ==============================================================================
28 class ElementaryAlgorithm(BasicObjects.Algorithm):
29     def __init__(self):
30         BasicObjects.Algorithm.__init__(self, "INPUTVALUESTEST")
31         self.defineRequiredParameter(
32             name     = "NumberOfPrintedDigits",
33             default  = 5,
34             typecast = int,
35             message  = "Nombre de chiffres affichés pour les impressions de réels",
36             minval   = 0,
37             )
38         self.defineRequiredParameter(
39             name     = "PrintAllValuesFor",
40             default  = [],
41             typecast = tuple,
42             message  = "Liste de noms de vecteurs dont les valeurs détaillées sont à imprimer",
43             listval  = [
44                 "Background",
45                 "CheckingPoint",
46                 "Observation",
47                 ]
48             )
49         self.defineRequiredParameter(
50             name     = "ShowInformationOnlyFor",
51             default  = ["Background", "CheckingPoint", "Observation"],
52             typecast = tuple,
53             message  = "Liste de noms de vecteurs dont les informations synthétiques sont à imprimer",
54             listval  = [
55                 "Background",
56                 "CheckingPoint",
57                 "Observation",
58                 ]
59             )
60         self.defineRequiredParameter(
61             name     = "SetDebug",
62             default  = False,
63             typecast = bool,
64             message  = "Activation du mode debug lors de l'exécution",
65             )
66         self.requireInputArguments(
67             mandatory= (),
68             )
69
70     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
71         self._pre_run(Parameters, Xb, Y, R, B, Q)
72         #
73         _p = self._parameters["NumberOfPrintedDigits"]
74         numpy.set_printoptions(precision=_p)
75         #
76         def __buildPrintableVectorProperties( __name, __vector ):
77             if __vector is None:                                         return ""
78             if len(__vector) == 0:                                       return ""
79             if hasattr(__vector,"name") and __name != __vector.name():   return ""
80             if __name not in self._parameters["ShowInformationOnlyFor"]: return ""
81             #
82             if hasattr(__vector,"mins"):
83                 __title = "Information for %svector series:"%(str(__name)+" ",)
84             else:
85                 __title = "Information for %svector:"%(str(__name)+" ",)
86             msgs = "\n"
87             msgs += ("===> "+__title+"\n")
88             msgs += ("     "+("-"*len(__title))+"\n")
89             msgs += ("     Main characteristics of the vector:\n")
90             if hasattr(__vector,"basetype"):
91                 msgs += ("       Python base type..........: %s\n")%( __vector.basetype(), )
92                 msgs += ("       Shape of data.............: %s\n")%( __vector.shape(), )
93             else:
94                 msgs += ("       Python base type..........: %s\n")%type( __vector )
95                 msgs += ("       Shape of serie of vectors.: %s\n")%( __vector.shape, )
96             try:
97                 msgs += ("       Number of data............: %s\n")%( len(__vector), )
98             except: pass
99             if hasattr(__vector,"mins"):
100                 msgs += ("       Serie of minimum values...: %s\n")%numpy.array(__vector.mins())
101             else:
102                 msgs += ("       Minimum of vector.........: %12."+str(_p)+"e\n")%__vector.min()
103             if hasattr(__vector,"means"):
104                 msgs += ("       Serie of mean values......: %s\n")%numpy.array(__vector.means())
105             else:
106                 msgs += ("       Mean of vector............: %12."+str(_p)+"e\n")%__vector.mean()
107             if hasattr(__vector,"maxs"):
108                 msgs += ("       Serie of maximum values...: %s\n")%numpy.array(__vector.maxs())
109             else:
110                 msgs += ("       Maximum of vector.........: %12."+str(_p)+"e\n")%__vector.max()
111             if self._parameters["SetDebug"] or __name in self._parameters["PrintAllValuesFor"]:
112                 msgs += ("\n")
113                 msgs += ("     Printing all values :\n")
114                 msgs += ("%s"%(__vector,))
115             print(msgs)
116             return msgs
117         #----------
118         __buildPrintableVectorProperties( "Background",    Xb )
119         __buildPrintableVectorProperties( "CheckingPoint", Xb )
120         __buildPrintableVectorProperties( "Observation",    Y )
121         #
122         self._post_run(HO)
123         return 0
124
125 # ==============================================================================
126 if __name__ == "__main__":
127     print('\n AUTODIAGNOSTIC\n')