Salome HOME
7bda3dac702a2875741a380bc154e34c4bf828e8
[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         self.setAttributes(tags=(
70             "Checking",
71             ))
72
73     def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None):
74         self._pre_run(Parameters, Xb, Y, U, HO, EM, CM, R, B, Q)
75         #
76         _p = self._parameters["NumberOfPrintedDigits"]
77         numpy.set_printoptions(precision=_p)
78         #
79         def __buildPrintableVectorProperties( __name, __vector ):
80             if __vector is None:                                         return ""
81             if len(__vector) == 0:                                       return ""
82             if hasattr(__vector,"name") and __name != __vector.name():   return ""
83             if __name not in self._parameters["ShowInformationOnlyFor"]: return ""
84             #
85             if hasattr(__vector,"mins"):
86                 __title = "Information for %svector series:"%(str(__name)+" ",)
87             else:
88                 __title = "Information for %svector:"%(str(__name)+" ",)
89             msgs = "\n"
90             msgs += ("===> "+__title+"\n")
91             msgs += ("     "+("-"*len(__title))+"\n")
92             msgs += ("     Main characteristics of the vector:\n")
93             if hasattr(__vector,"basetype"):
94                 msgs += ("       Python base type..........: %s\n")%( __vector.basetype(), )
95                 msgs += ("       Shape of data.............: %s\n")%( __vector.shape(), )
96             else:
97                 msgs += ("       Python base type..........: %s\n")%type( __vector )
98                 msgs += ("       Shape of serie of vectors.: %s\n")%( __vector.shape, )
99             try:
100                 msgs += ("       Number of data............: %s\n")%( len(__vector), )
101             except: pass
102             if hasattr(__vector,"mins"):
103                 msgs += ("       Serie of minimum values...: %s\n")%numpy.array(__vector.mins())
104             else:
105                 msgs += ("       Minimum of vector.........: %12."+str(_p)+"e\n")%__vector.min()
106             if hasattr(__vector,"means"):
107                 msgs += ("       Serie of mean values......: %s\n")%numpy.array(__vector.means())
108             else:
109                 msgs += ("       Mean of vector............: %12."+str(_p)+"e\n")%__vector.mean()
110             if hasattr(__vector,"maxs"):
111                 msgs += ("       Serie of maximum values...: %s\n")%numpy.array(__vector.maxs())
112             else:
113                 msgs += ("       Maximum of vector.........: %12."+str(_p)+"e\n")%__vector.max()
114             if self._parameters["SetDebug"] or __name in self._parameters["PrintAllValuesFor"]:
115                 msgs += ("\n")
116                 msgs += ("     Printing all values :\n")
117                 msgs += ("%s"%(__vector,))
118             print(msgs)
119             return msgs
120         #----------
121         __buildPrintableVectorProperties( "Background",    Xb )
122         __buildPrintableVectorProperties( "CheckingPoint", Xb )
123         __buildPrintableVectorProperties( "Observation",    Y )
124         #
125         self._post_run(HO)
126         return 0
127
128 # ==============================================================================
129 if __name__ == "__main__":
130     print('\n AUTODIAGNOSTIC\n')