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.CheckingPoint = None
42 self.InputVariables = {}
43 self.OutputVariables = {}
44 self.InputVariablesOrder = []
45 self.OutputVariablesOrder = []
46 self.observers_dict = {}
50 logging.getLogger().setLevel(logging.DEBUG)
52 logging.getLogger().setLevel(logging.WARNING)
54 # Observation Management
55 self.ObservationOperatorType = {}
56 self.EvolutionModelType = {}
57 self.FunctionObservationOperator = {}
59 #--------------------------------------
61 def setInputVariable(self, name, size):
62 self.InputVariables[name] = size
63 self.InputVariablesOrder.append(name)
65 def setOutputVariable(self, name, size):
66 self.OutputVariables[name] = size
67 self.OutputVariablesOrder.append(name)
69 #--------------------------------------
71 def setAlgorithmParameters(self, parameters):
72 self.algorithm_dict = parameters
74 #--------------------------------------
76 def initAlgorithm(self):
77 self.ADD.setAlgorithm(choice=self.algorithm)
78 if self.algorithm_dict != None:
79 logging.debug("ADD.setAlgorithm : "+str(self.algorithm_dict))
80 self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
82 #--------------------------------------
84 def getAssimilationStudy(self):
87 #--------------------------------------
88 # Methods to initialize AssimilationStudy
90 def setBackgroundType(self, Type):
92 self.BackgroundType = Type
94 raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
96 def setBackgroundStored(self, Stored):
98 self.BackgroundStored = True
100 self.BackgroundStored = False
102 def setBackground(self, Background):
105 self.BackgroundStored
106 except AttributeError:
107 raise daError("[daStudy::setBackground] Type or Storage is not defined !")
108 self.Background = Background
109 if self.BackgroundType == "Vector":
110 self.ADD.setBackground(asVector = Background, toBeStored = self.BackgroundStored)
112 def getBackground(self):
113 return self.Background
115 #--------------------------------------
117 def setCheckingPointType(self, Type):
119 self.CheckingPointType = Type
121 raise daError("[daStudy::setCheckingPointType] Type is unkown : " + Type + " Types are : Vector")
123 def setCheckingPointStored(self, Stored):
125 self.CheckingPointStored = True
127 self.CheckingPointStored = False
129 def setCheckingPoint(self, CheckingPoint):
131 self.CheckingPointType
132 self.CheckingPointStored
133 except AttributeError:
134 raise daError("[daStudy::setCheckingPoint] Type or Storage is not defined !")
135 self.CheckingPoint = CheckingPoint
136 if self.CheckingPointType == "Vector":
137 self.ADD.setBackground(asVector = CheckingPoint, toBeStored = self.CheckingPointStored)
139 #--------------------------------------
141 def setBackgroundErrorStored(self, Stored):
143 self.BackgroundErrorStored = True
145 self.BackgroundErrorStored = False
147 def setBackgroundError(self, BackgroundError):
149 self.BackgroundErrorStored
150 except AttributeError:
151 raise daError("[daStudy::setBackgroundError] Storage is not defined !")
152 self.ADD.setBackgroundError(asCovariance = BackgroundError, toBeStored = self.BackgroundErrorStored)
154 #--------------------------------------
156 def setObservationType(self, Type):
158 self.ObservationType = Type
160 raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
162 def setObservationStored(self, Stored):
164 self.ObservationStored = True
166 self.ObservationStored = False
168 def setObservation(self, Observation):
171 self.ObservationStored
172 except AttributeError:
173 raise daError("[daStudy::setObservation] Type or Storage is not defined !")
174 if self.ObservationType == "Vector":
175 self.ADD.setObservation(asVector = Observation, toBeStored = self.ObservationStored)
177 #--------------------------------------
179 def setObservationErrorStored(self, Stored):
181 self.ObservationErrorStored = True
183 self.ObservationErrorStored = False
185 def setObservationError(self, ObservationError):
187 self.ObservationErrorStored
188 except AttributeError:
189 raise daError("[daStudy::setObservationError] Storage is not defined !")
190 self.ADD.setObservationError(asCovariance = ObservationError, toBeStored = self.ObservationErrorStored)
192 #--------------------------------------
194 def getObservationOperatorType(self, Name):
197 rtn = self.ObservationOperatorType[Name]
202 def setObservationOperatorType(self, Name, Type):
204 self.ObservationOperatorType[Name] = Type
205 elif Type == "Function":
206 self.ObservationOperatorType[Name] = Type
208 raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix, Function")
210 def setObservationOperator(self, Name, ObservationOperator):
212 self.ObservationOperatorType[Name]
213 except AttributeError:
214 raise daError("[daStudy::setObservationOperator] Type is not defined !")
215 if self.ObservationOperatorType[Name] == "Matrix":
216 self.ADD.setObservationOperator(asMatrix = ObservationOperator)
217 elif self.ObservationOperatorType[Name] == "Function":
218 self.FunctionObservationOperator[Name] = ObservationOperator
220 #--------------------------------------
222 def getEvolutionModelType(self, Name):
225 rtn = self.EvolutionModelType[Name]
230 def setEvolutionModelType(self, Name, Type):
232 self.EvolutionModelType[Name] = Type
233 elif Type == "Function":
234 self.EvolutionModelType[Name] = Type
236 raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + " Types are : Matrix, Function")
238 def setEvolutionModel(self, Name, EvolutionModel):
240 self.EvolutionModelType[Name]
241 except AttributeError:
242 raise daError("[daStudy::setEvolutionModel] Type is not defined !")
243 if self.EvolutionModelType[Name] == "Matrix":
244 self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
245 elif self.EvolutionModelType[Name] == "Function":
246 self.FunctionEvolutionModel[Name] = EvolutionModel
248 #--------------------------------------
250 def addObserver(self, name, scheduler, info, number):
251 self.observers_dict[name] = {}
252 self.observers_dict[name]["scheduler"] = scheduler
253 self.observers_dict[name]["info"] = info
254 self.observers_dict[name]["number"] = number
256 def getObservers(self):
257 return self.observers_dict