1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2010-2012 EDF R&D
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.
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.
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
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
23 from daCore.AssimilationStudy import AssimilationStudy
24 from daCore import Logging
27 class daError(Exception):
28 def __init__(self, value):
31 return repr(self.value)
35 def __init__(self, name, algorithm, debug):
37 self.ADD = AssimilationStudy(name)
38 self.ADD.setControls()
39 self.algorithm = algorithm
40 self.algorithm_dict = None
41 self.Background = None
42 self.CheckingPoint = None
43 self.InputVariables = {}
44 self.OutputVariables = {}
45 self.InputVariablesOrder = []
46 self.OutputVariablesOrder = []
47 self.observers_dict = {}
51 logging.getLogger().setLevel(logging.DEBUG)
53 logging.getLogger().setLevel(logging.WARNING)
55 # Observation Management
56 self.ObservationOperatorType = {}
57 self.FunctionObservationOperator = {}
59 # Evolution Management
60 self.EvolutionModelType = {}
61 self.FunctionEvolutionModel = {}
63 #--------------------------------------
65 def setInputVariable(self, name, size):
66 self.InputVariables[name] = size
67 self.InputVariablesOrder.append(name)
69 def setOutputVariable(self, name, size):
70 self.OutputVariables[name] = size
71 self.OutputVariablesOrder.append(name)
73 #--------------------------------------
75 def setAlgorithmParameters(self, parameters):
76 self.algorithm_dict = parameters
78 #--------------------------------------
80 def initAlgorithm(self):
81 self.ADD.setAlgorithm(choice=self.algorithm)
82 if self.algorithm_dict != None:
83 logging.debug("DASTUDY AlgorithmParameters: "+str(self.algorithm_dict))
84 self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
86 #--------------------------------------
88 def getAssimilationStudy(self):
91 #--------------------------------------
92 # Methods to initialize AssimilationStudy
94 def setBackgroundType(self, Type):
96 self.BackgroundType = Type
98 raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + ". Types are : Vector")
100 def setBackgroundStored(self, Stored):
102 self.BackgroundStored = True
104 self.BackgroundStored = False
106 def setBackground(self, Background):
109 self.BackgroundStored
110 except AttributeError:
111 raise daError("[daStudy::setBackground] Type or Storage is not defined !")
112 self.Background = Background
113 if self.BackgroundType == "Vector":
114 self.ADD.setBackground(asVector = Background, toBeStored = self.BackgroundStored)
116 def getBackground(self):
117 return self.Background
119 #--------------------------------------
121 def setCheckingPointType(self, Type):
123 self.CheckingPointType = Type
125 raise daError("[daStudy::setCheckingPointType] Type is unkown : " + Type + ". Types are : Vector")
127 def setCheckingPointStored(self, Stored):
129 self.CheckingPointStored = True
131 self.CheckingPointStored = False
133 def setCheckingPoint(self, CheckingPoint):
135 self.CheckingPointType
136 self.CheckingPointStored
137 except AttributeError:
138 raise daError("[daStudy::setCheckingPoint] Type or Storage is not defined !")
139 self.CheckingPoint = CheckingPoint
140 if self.CheckingPointType == "Vector":
141 self.ADD.setBackground(asVector = CheckingPoint, toBeStored = self.CheckingPointStored)
143 #--------------------------------------
145 def setBackgroundErrorStored(self, Stored):
147 self.BackgroundErrorStored = True
149 self.BackgroundErrorStored = False
151 def setBackgroundError(self, BackgroundError):
153 self.BackgroundErrorStored
154 except AttributeError:
155 raise daError("[daStudy::setBackgroundError] Storage is not defined !")
156 self.ADD.setBackgroundError(asCovariance = BackgroundError, toBeStored = self.BackgroundErrorStored)
158 #--------------------------------------
160 def setControlInputType(self, Type):
161 if Type == "Vector" or Type == "VectorSerie":
162 self.ControlInputType = Type
164 raise daError("[daStudy::setControlInputType] Type is unkown : " + Type + ". Types are : Vector, VectorSerie")
166 def setControlInputStored(self, Stored):
168 self.ControlInputStored = True
170 self.ControlInputStored = False
172 def setControlInput(self, ControlInput):
174 self.ControlInputType
175 self.ControlInputStored
176 except AttributeError:
177 raise daError("[daStudy::setControlInput] Type or Storage is not defined !")
178 if self.ControlInputType == "Vector":
179 self.ADD.setControlInput(asVector = ControlInput, toBeStored = self.ControlInputStored)
180 if self.ControlInputType == "VectorSerie":
181 self.ADD.setControlInput(asPersistentVector = ControlInput, toBeStored = self.ControlInputStored)
183 #--------------------------------------
185 def setObservationType(self, Type):
186 if Type == "Vector" or Type == "VectorSerie":
187 self.ObservationType = Type
189 raise daError("[daStudy::setObservationType] Type is unkown : " + Type + ". Types are : Vector, VectorSerie")
191 def setObservationStored(self, Stored):
193 self.ObservationStored = True
195 self.ObservationStored = False
197 def setObservation(self, Observation):
200 self.ObservationStored
201 except AttributeError:
202 raise daError("[daStudy::setObservation] Type or Storage is not defined !")
203 if self.ObservationType == "Vector":
204 self.ADD.setObservation(asVector = Observation, toBeStored = self.ObservationStored)
205 if self.ObservationType == "VectorSerie":
206 self.ADD.setObservation(asPersistentVector = Observation, toBeStored = self.ObservationStored)
208 #--------------------------------------
210 def setObservationErrorStored(self, Stored):
212 self.ObservationErrorStored = True
214 self.ObservationErrorStored = False
216 def setObservationError(self, ObservationError):
218 self.ObservationErrorStored
219 except AttributeError:
220 raise daError("[daStudy::setObservationError] Storage is not defined !")
221 self.ADD.setObservationError(asCovariance = ObservationError, toBeStored = self.ObservationErrorStored)
223 #--------------------------------------
225 def getObservationOperatorType(self, Name):
228 rtn = self.ObservationOperatorType[Name]
233 def setObservationOperatorType(self, Name, Type):
235 self.ObservationOperatorType[Name] = Type
236 elif Type == "Function":
237 self.ObservationOperatorType[Name] = Type
239 raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + ". Types are : Matrix, Function")
241 def setObservationOperator(self, Name, ObservationOperator):
243 self.ObservationOperatorType[Name]
244 except AttributeError:
245 raise daError("[daStudy::setObservationOperator] Type is not defined !")
246 if self.ObservationOperatorType[Name] == "Matrix":
247 self.ADD.setObservationOperator(asMatrix = ObservationOperator)
248 elif self.ObservationOperatorType[Name] == "Function":
249 self.FunctionObservationOperator[Name] = ObservationOperator
251 #--------------------------------------
253 def setEvolutionErrorStored(self, Stored):
255 self.EvolutionErrorStored = True
257 self.EvolutionErrorStored = False
259 def setEvolutionError(self, EvolutionError):
261 self.EvolutionErrorStored
262 except AttributeError:
263 raise daError("[daStudy::setEvolutionError] Storage is not defined !")
264 self.ADD.setEvolutionError(asCovariance = EvolutionError, toBeStored = self.EvolutionErrorStored)
266 #--------------------------------------
268 def getEvolutionModelType(self, Name):
271 rtn = self.EvolutionModelType[Name]
276 def setEvolutionModelType(self, Name, Type):
278 self.EvolutionModelType[Name] = Type
279 elif Type == "Function":
280 self.EvolutionModelType[Name] = Type
282 raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + ". Types are : Matrix, Function")
284 def setEvolutionModel(self, Name, EvolutionModel):
286 self.EvolutionModelType[Name]
287 except AttributeError:
288 raise daError("[daStudy::setEvolutionModel] Type is not defined !")
289 if self.EvolutionModelType[Name] == "Matrix":
290 self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
291 elif self.EvolutionModelType[Name] == "Function":
292 self.FunctionEvolutionModel[Name] = EvolutionModel
294 #--------------------------------------
296 def addObserver(self, name, scheduler, info, number):
297 self.observers_dict[name] = {}
298 self.observers_dict[name]["scheduler"] = scheduler
299 self.observers_dict[name]["info"] = info
300 self.observers_dict[name]["number"] = number
302 def getObservers(self):
303 return self.observers_dict