1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2010-2013 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] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
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] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
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 setBackgroundErrorType(self, Type):
146 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
147 self.BackgroundErrorType = Type
149 raise daError("[daStudy::setBackgroundErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
151 def setBackgroundErrorStored(self, Stored):
153 self.BackgroundErrorStored = True
155 self.BackgroundErrorStored = False
157 def setBackgroundError(self, BackgroundError):
159 self.BackgroundErrorType
160 self.BackgroundErrorStored
161 except AttributeError:
162 raise daError("[daStudy::setBackgroundError] Type or Storage is not defined !")
163 if self.BackgroundErrorType == "Matrix":
164 self.ADD.setBackgroundError(asCovariance = BackgroundError, toBeStored = self.BackgroundErrorStored)
165 if self.BackgroundErrorType == "ScalarSparseMatrix":
166 self.ADD.setBackgroundError(asEyeByScalar = BackgroundError, toBeStored = self.BackgroundErrorStored)
167 if self.BackgroundErrorType == "DiagonalSparseMatrix":
168 self.ADD.setBackgroundError(asEyeByVector = BackgroundError, toBeStored = self.BackgroundErrorStored)
170 #--------------------------------------
172 def setControlInputType(self, Type):
173 if Type in ("Vector", "VectorSerie"):
174 self.ControlInputType = Type
176 raise daError("[daStudy::setControlInputType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
178 def setControlInputStored(self, Stored):
180 self.ControlInputStored = True
182 self.ControlInputStored = False
184 def setControlInput(self, ControlInput):
186 self.ControlInputType
187 self.ControlInputStored
188 except AttributeError:
189 raise daError("[daStudy::setControlInput] Type or Storage is not defined !")
190 if self.ControlInputType == "Vector":
191 self.ADD.setControlInput(asVector = ControlInput, toBeStored = self.ControlInputStored)
192 if self.ControlInputType == "VectorSerie":
193 self.ADD.setControlInput(asPersistentVector = ControlInput, toBeStored = self.ControlInputStored)
195 #--------------------------------------
197 def setObservationType(self, Type):
198 if Type in ("Vector", "VectorSerie"):
199 self.ObservationType = Type
201 raise daError("[daStudy::setObservationType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
203 def setObservationStored(self, Stored):
205 self.ObservationStored = True
207 self.ObservationStored = False
209 def setObservation(self, Observation):
212 self.ObservationStored
213 except AttributeError:
214 raise daError("[daStudy::setObservation] Type or Storage is not defined !")
215 if self.ObservationType == "Vector":
216 self.ADD.setObservation(asVector = Observation, toBeStored = self.ObservationStored)
217 if self.ObservationType == "VectorSerie":
218 self.ADD.setObservation(asPersistentVector = Observation, toBeStored = self.ObservationStored)
220 #--------------------------------------
222 def setObservationErrorType(self, Type):
223 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
224 self.ObservationErrorType = Type
226 raise daError("[daStudy::setObservationErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
228 def setObservationErrorStored(self, Stored):
230 self.ObservationErrorStored = True
232 self.ObservationErrorStored = False
234 def setObservationError(self, ObservationError):
236 self.ObservationErrorType
237 self.ObservationErrorStored
238 except AttributeError:
239 raise daError("[daStudy::setObservationError] Type or Storage is not defined !")
240 if self.ObservationErrorType == "Matrix":
241 self.ADD.setObservationError(asCovariance = ObservationError, toBeStored = self.ObservationErrorStored)
242 if self.ObservationErrorType == "ScalarSparseMatrix":
243 self.ADD.setObservationError(asEyeByScalar = ObservationError, toBeStored = self.ObservationErrorStored)
244 if self.ObservationErrorType == "DiagonalSparseMatrix":
245 self.ADD.setObservationError(asEyeByVector = ObservationError, toBeStored = self.ObservationErrorStored)
247 #--------------------------------------
249 def getObservationOperatorType(self, Name):
252 rtn = self.ObservationOperatorType[Name]
257 def setObservationOperatorType(self, Name, Type):
258 if Type in ("Matrix", "Function"):
259 self.ObservationOperatorType[Name] = Type
261 raise daError("[daStudy::setObservationOperatorType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
263 def setObservationOperator(self, Name, ObservationOperator):
265 self.ObservationOperatorType[Name]
266 except AttributeError:
267 raise daError("[daStudy::setObservationOperator] Type is not defined !")
268 if self.ObservationOperatorType[Name] == "Matrix":
269 self.ADD.setObservationOperator(asMatrix = ObservationOperator)
270 elif self.ObservationOperatorType[Name] == "Function":
271 self.FunctionObservationOperator[Name] = ObservationOperator
273 #--------------------------------------
275 def setEvolutionErrorType(self, Type):
276 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
277 self.EvolutionErrorType = Type
279 raise daError("[daStudy::setEvolutionErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
281 def setEvolutionErrorStored(self, Stored):
283 self.EvolutionErrorStored = True
285 self.EvolutionErrorStored = False
287 def setEvolutionError(self, EvolutionError):
289 self.EvolutionErrorType
290 self.EvolutionErrorStored
291 except AttributeError:
292 raise daError("[daStudy::setEvolutionError] Type or Storage is not defined !")
293 if self.EvolutionErrorType == "Matrix":
294 self.ADD.setEvolutionError(asCovariance = EvolutionError, toBeStored = self.EvolutionErrorStored)
295 if self.EvolutionErrorType == "ScalarSparseMatrix":
296 self.ADD.setEvolutionError(asEyeByScalar = EvolutionError, toBeStored = self.EvolutionErrorStored)
297 if self.EvolutionErrorType == "DiagonalSparseMatrix":
298 self.ADD.setEvolutionError(asEyeByVector = EvolutionError, toBeStored = self.EvolutionErrorStored)
300 #--------------------------------------
302 def getEvolutionModelType(self, Name):
305 rtn = self.EvolutionModelType[Name]
310 def setEvolutionModelType(self, Name, Type):
311 if Type in ("Matrix", "Function"):
312 self.EvolutionModelType[Name] = Type
314 raise daError("[daStudy::setEvolutionModelType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
316 def setEvolutionModel(self, Name, EvolutionModel):
318 self.EvolutionModelType[Name]
319 except AttributeError:
320 raise daError("[daStudy::setEvolutionModel] Type is not defined !")
321 if self.EvolutionModelType[Name] == "Matrix":
322 self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
323 elif self.EvolutionModelType[Name] == "Function":
324 self.FunctionEvolutionModel[Name] = EvolutionModel
326 #--------------------------------------
328 def addObserver(self, name, scheduler, info, number):
329 self.observers_dict[name] = {}
330 self.observers_dict[name]["scheduler"] = scheduler
331 self.observers_dict[name]["info"] = info
332 self.observers_dict[name]["number"] = number
334 def getObservers(self):
335 return self.observers_dict