2 # Copyright (C) 2010-2011 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
22 from daCore.AssimilationStudy import AssimilationStudy
23 from daCore import Logging
26 class daError(Exception):
27 def __init__(self, value):
30 return repr(self.value)
34 def __init__(self, name, algorithm, debug):
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 self.observers_dict = {}
49 logging.getLogger().setLevel(logging.DEBUG)
51 logging.getLogger().setLevel(logging.WARNING)
53 # Observation Management
54 self.ObservationOperatorType = {}
55 self.EvolutionModelType = {}
56 self.FunctionObservationOperator = {}
58 #--------------------------------------
60 def setInputVariable(self, name, size):
61 self.InputVariables[name] = size
62 self.InputVariablesOrder.append(name)
64 def setOutputVariable(self, name, size):
65 self.OutputVariables[name] = size
66 self.OutputVariablesOrder.append(name)
68 #--------------------------------------
70 def setAlgorithmParameters(self, parameters):
71 self.algorithm_dict = parameters
73 #--------------------------------------
75 def initAlgorithm(self):
76 self.ADD.setAlgorithm(choice=self.algorithm)
77 if self.algorithm_dict != None:
78 logging.debug("ADD.setAlgorithm : "+str(self.algorithm_dict))
79 self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
81 #--------------------------------------
83 def getAssimilationStudy(self):
86 #--------------------------------------
87 # Methods to initialize AssimilationStudy
89 def setBackgroundType(self, Type):
91 self.BackgroundType = Type
93 raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
95 def setBackground(self, Background):
98 except AttributeError:
99 raise daError("[daStudy::setBackground] Type is not defined !")
100 self.Background = Background
101 if self.BackgroundType == "Vector":
102 self.ADD.setBackground(asVector = Background)
104 def getBackground(self):
105 return self.Background
107 #--------------------------------------
109 def setBackgroundError(self, BackgroundError):
110 self.ADD.setBackgroundError(asCovariance = BackgroundError)
112 #--------------------------------------
114 def setObservationType(self, Type):
116 self.ObservationType = Type
118 raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
120 def setObservation(self, Observation):
123 except AttributeError:
124 raise daError("[daStudy::setObservation] Type is not defined !")
125 if self.ObservationType == "Vector":
126 self.ADD.setObservation(asVector = Observation)
128 #--------------------------------------
130 def setObservationError(self, ObservationError):
131 self.ADD.setObservationError(asCovariance = ObservationError)
133 #--------------------------------------
135 def getObservationOperatorType(self, Name):
138 rtn = self.ObservationOperatorType[Name]
143 def setObservationOperatorType(self, Name, Type):
145 self.ObservationOperatorType[Name] = Type
146 elif Type == "Function":
147 self.ObservationOperatorType[Name] = Type
149 raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix, Function")
151 def setObservationOperator(self, Name, ObservationOperator):
153 self.ObservationOperatorType[Name]
154 except AttributeError:
155 raise daError("[daStudy::setObservationOperator] Type is not defined !")
156 if self.ObservationOperatorType[Name] == "Matrix":
157 self.ADD.setObservationOperator(asMatrix = ObservationOperator)
158 elif self.ObservationOperatorType[Name] == "Function":
159 self.FunctionObservationOperator[Name] = ObservationOperator
161 #--------------------------------------
163 def getEvolutionModelType(self, Name):
166 rtn = self.EvolutionModelType[Name]
171 def setEvolutionModelType(self, Name, Type):
173 self.EvolutionModelType[Name] = Type
174 elif Type == "Function":
175 self.EvolutionModelType[Name] = Type
177 raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + " Types are : Matrix, Function")
179 def setEvolutionModel(self, Name, EvolutionModel):
181 self.EvolutionModelType[Name]
182 except AttributeError:
183 raise daError("[daStudy::setEvolutionModel] Type is not defined !")
184 if self.EvolutionModelType[Name] == "Matrix":
185 self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
186 elif self.EvolutionModelType[Name] == "Function":
187 self.FunctionEvolutionModel[Name] = EvolutionModel
189 #--------------------------------------
191 def addObserver(self, name, scheduler, info, number):
192 self.observers_dict[name] = {}
193 self.observers_dict[name]["scheduler"] = scheduler
194 self.observers_dict[name]["info"] = info
195 self.observers_dict[name]["number"] = number
197 def getObservers(self):
198 return self.observers_dict