Salome HOME
Initial Commit
[modules/adao.git] / src / daComposant / daDiagnostics / ReduceBiais.py
1 #-*-coding:iso-8859-1-*-
2 #
3 #  Copyright (C) 2008-2009  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 __doc__ = """
22     Diagnostic sur la reduction du biais lors de l'analyse
23 """
24 __author__ = "Sophie RICCI - Aout 2008"
25
26 import sys ; sys.path.insert(0, "../daCore") 
27
28 import numpy
29 import Persistence
30 from BasicObjects import Diagnostic
31 from AssimilationStudy import AssimilationStudy
32
33 # ==============================================================================
34 class ElementaryDiagnostic(Diagnostic,Persistence.OneScalar):
35     def __init__(self, name = "", unit = "", basetype = None, parameters = {}):
36         Diagnostic.__init__(self, name, parameters)
37         Persistence.OneScalar.__init__( self, name, unit, basetype = bool)
38
39     def _formula(self, V1, V2):
40         """
41         Vérification de la reduction du biais entre OMB et OMA lors de l'analyse
42         """
43         biaisOMB = V1.mean() 
44         biaisOMA = V2.mean() 
45         #
46         if biaisOMA > biaisOMB: 
47             reducebiais = False
48         else :
49             reducebiais = True
50         #
51         return reducebiais
52
53     def calculate(self, vectorOMB = None, vectorOMA = None, step = None):
54         """
55         Teste les arguments, active la formule de calcul et stocke le résultat
56         Arguments :
57             - vectorOMB : vecteur d'écart entre les observations et l'ébauche 
58             - vectorOMA : vecteur d'écart entre les observations et l'analyse
59         """
60         if ( (vectorOMB is None) or (vectorOMA is None) ):
61             raise ValueError("Two vectors must be given to test the reduction of the biais after analysis")
62         V1 = numpy.array(vectorOMB)
63         V2 = numpy.array(vectorOMA)
64         if V1.size < 1 or V2.size < 1:
65             raise ValueError("The given vectors must not be empty")
66         if V1.size != V2.size:
67             raise ValueError("The two given vectors must have the same size")
68         #
69         value = self._formula( V1, V2 )
70         #
71         self.store( value = value,  step = step )
72
73 #===============================================================================
74 if __name__ == "__main__":
75     print '\n AUTODIAGNOSTIC \n'
76     #
77     # Instanciation de l'objet diagnostic
78     # -----------------------------------
79     D = ElementaryDiagnostic("Mon ReduceBiais")
80     #
81     # Tirage des 2 vecteurs choisis
82     # -------------------------------
83     x1 = numpy.matrix(([3. , 4., 5. ]))
84     x2 = numpy.matrix(([1.5, 2., 2.5]))
85     print " L'écart entre les observations et l'ébauche est OMB :", x1
86     print " La moyenne de OMB (i.e. le biais) est de............:", x1.mean()
87     print " L'écart entre les observations et l'analyse est OMA :", x2
88     print " La moyenne de OMA (i.e. le biais) est de............:", x2.mean()
89     #
90     D.calculate( vectorOMB = x1,  vectorOMA = x2)
91     if not D.valueserie(0) :
92             print " Résultat : l'analyse NE RÉDUIT PAS le biais"
93     else :
94             print " Résultat : l'analyse RÉDUIT le biais"
95     print
96     #
97     # Tirage des 2 vecteurs choisis
98     # -------------------------------
99     x1 = numpy.matrix(range(-5,6))
100     x2 = numpy.array(range(11))
101     print " L'écart entre les observations et l'ébauche est OMB :", x1
102     print " La moyenne de OMB (i.e. le biais) est de............:", x1.mean()
103     print " L'écart entre les observations et l'analyse est OMA :", x2
104     print " La moyenne de OMA (i.e. le biais) est de............:", x2.mean()
105     #
106     D.calculate( vectorOMB = x1,  vectorOMA = x2)
107     if not D.valueserie(1) :
108             print " Résultat : l'analyse NE RÉDUIT PAS le biais"
109     else :
110             print " Résultat : l'analyse RÉDUIT le biais"
111     print