]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
Mise à jour des copyrights
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*- coding: utf-8 -*-
2 # Copyright (C) 2010-2011 EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
21
22 from daCore.AssimilationStudy import AssimilationStudy
23 from daCore import Logging
24 import logging
25
26 class daError(Exception):
27   def __init__(self, value):
28     self.value = value
29   def __str__(self):
30     return repr(self.value)
31
32 class daStudy:
33
34   def __init__(self, name, algorithm, debug):
35
36     self.ADD = AssimilationStudy(name)
37     self.ADD.setControls()
38     self.algorithm = algorithm
39     self.algorithm_dict = None
40     self.Background = None
41     self.InputVariables = {}
42     self.OutputVariables = {}
43     self.InputVariablesOrder = []
44     self.OutputVariablesOrder = []
45
46     self.debug = debug
47     if self.debug:
48       logging.getLogger().setLevel(logging.DEBUG)
49     else:
50       logging.getLogger().setLevel(logging.WARNING)
51
52     # Observation Management
53     self.ObservationOperatorType = {}
54     self.FunctionObservationOperator = {}
55
56   def setInputVariable(self, name, size):
57     self.InputVariables[name] = size
58     self.InputVariablesOrder.append(name)
59
60   def setOutputVariable(self, name, size):
61     self.OutputVariables[name] = size
62     self.OutputVariablesOrder.append(name)
63
64   def setAlgorithmParameters(self, parameters):
65     self.algorithm_dict = parameters
66
67   def initAlgorithm(self):
68
69     self.ADD.setAlgorithm(choice=self.algorithm)
70     if self.algorithm_dict != None:
71       self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
72
73   def getAssimilationStudy(self):
74
75     return self.ADD
76
77   # Methods to initialize AssimilationStudy
78
79   def setBackgroundType(self, Type):
80
81     if Type == "Vector":
82       self.BackgroundType = Type
83     else:
84       raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
85
86   def setBackground(self, Background):
87
88     try:
89       self.BackgroundType
90     except AttributeError:
91       raise daError("[daStudy::setBackground] Type is not defined !")
92
93     self.Background = Background
94
95     if self.BackgroundType == "Vector":
96       self.ADD.setBackground(asVector = Background)
97
98   def getBackground(self):
99     return self.Background
100
101   def setBackgroundError(self, BackgroundError):
102
103     self.ADD.setBackgroundError(asCovariance = BackgroundError)
104
105   def setObservationType(self, Type):
106
107     if Type == "Vector":
108       self.ObservationType = Type
109     else:
110       raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
111
112   def setObservation(self, Observation):
113
114     try:
115       self.ObservationType
116     except AttributeError:
117       raise daError("[daStudy::setObservation] Type is not defined !")
118
119     if self.ObservationType == "Vector":
120       self.ADD.setObservation(asVector = Observation)
121
122   def setObservationError(self, ObservationError):
123     self.ADD.setObservationError(asCovariance = ObservationError)
124
125
126   def getObservationOperatorType(self, Name):
127     rtn = None
128     try:
129       rtn = self.ObservationOperatorType[Name]
130     except:
131       pass
132     return rtn
133
134   def setObservationOperatorType(self, Name, Type):
135     if Type == "Matrix":
136       self.ObservationOperatorType[Name] = Type
137     elif Type == "Function":
138       self.ObservationOperatorType[Name] = Type
139     else:
140       raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix")
141
142   def setObservationOperator(self, Name, ObservationOperator):
143     try:
144       self.ObservationOperatorType[Name]
145     except AttributeError:
146       raise daError("[daStudy::setObservationOperator] Type is not defined !")
147
148     if self.ObservationOperatorType[Name] == "Matrix":
149       self.ADD.setObservationOperator(asMatrix = ObservationOperator)
150     elif self.ObservationOperatorType[Name] == "Function":
151       self.FunctionObservationOperator[Name] = ObservationOperator
152