2 # Copyright (C) 2010-2012 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.FunctionObservationOperator = {}
58 # Evolution Management
59 self.EvolutionModelType = {}
60 self.FunctionEvolutionModel = {}
62 #--------------------------------------
64 def setInputVariable(self, name, size):
65 self.InputVariables[name] = size
66 self.InputVariablesOrder.append(name)
68 def setOutputVariable(self, name, size):
69 self.OutputVariables[name] = size
70 self.OutputVariablesOrder.append(name)
72 #--------------------------------------
74 def setAlgorithmParameters(self, parameters):
75 self.algorithm_dict = parameters
77 #--------------------------------------
79 def initAlgorithm(self):
80 self.ADD.setAlgorithm(choice=self.algorithm)
81 if self.algorithm_dict != None:
82 logging.debug("DASTUDY AlgorithmParameters: "+str(self.algorithm_dict))
83 self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
85 #--------------------------------------
87 def getAssimilationStudy(self):
90 #--------------------------------------
91 # Methods to initialize AssimilationStudy
93 def setBackgroundType(self, Type):
95 self.BackgroundType = Type
97 raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + ". Types are : Vector")
99 def setBackgroundStored(self, Stored):
101 self.BackgroundStored = True
103 self.BackgroundStored = False
105 def setBackground(self, Background):
108 self.BackgroundStored
109 except AttributeError:
110 raise daError("[daStudy::setBackground] Type or Storage is not defined !")
111 self.Background = Background
112 if self.BackgroundType == "Vector":
113 self.ADD.setBackground(asVector = Background, toBeStored = self.BackgroundStored)
115 def getBackground(self):
116 return self.Background
118 #--------------------------------------
120 def setCheckingPointType(self, Type):
122 self.CheckingPointType = Type
124 raise daError("[daStudy::setCheckingPointType] Type is unkown : " + Type + ". Types are : Vector")
126 def setCheckingPointStored(self, Stored):
128 self.CheckingPointStored = True
130 self.CheckingPointStored = False
132 def setCheckingPoint(self, CheckingPoint):
134 self.CheckingPointType
135 self.CheckingPointStored
136 except AttributeError:
137 raise daError("[daStudy::setCheckingPoint] Type or Storage is not defined !")
138 self.CheckingPoint = CheckingPoint
139 if self.CheckingPointType == "Vector":
140 self.ADD.setBackground(asVector = CheckingPoint, toBeStored = self.CheckingPointStored)
142 #--------------------------------------
144 def setBackgroundErrorStored(self, Stored):
146 self.BackgroundErrorStored = True
148 self.BackgroundErrorStored = False
150 def setBackgroundError(self, BackgroundError):
152 self.BackgroundErrorStored
153 except AttributeError:
154 raise daError("[daStudy::setBackgroundError] Storage is not defined !")
155 self.ADD.setBackgroundError(asCovariance = BackgroundError, toBeStored = self.BackgroundErrorStored)
157 #--------------------------------------
159 def setObservationType(self, Type):
160 if Type == "Vector" or Type == "VectorSerie":
161 self.ObservationType = Type
163 raise daError("[daStudy::setObservationType] Type is unkown : " + Type + ". Types are : Vector, VectorSerie")
165 def setObservationStored(self, Stored):
167 self.ObservationStored = True
169 self.ObservationStored = False
171 def setObservation(self, Observation):
174 self.ObservationStored
175 except AttributeError:
176 raise daError("[daStudy::setObservation] Type or Storage is not defined !")
177 if self.ObservationType == "Vector":
178 self.ADD.setObservation(asVector = Observation, toBeStored = self.ObservationStored)
179 if self.ObservationType == "VectorSerie":
180 self.ADD.setObservation(asPersistentVector = Observation, toBeStored = self.ObservationStored)
182 #--------------------------------------
184 def setObservationErrorStored(self, Stored):
186 self.ObservationErrorStored = True
188 self.ObservationErrorStored = False
190 def setObservationError(self, ObservationError):
192 self.ObservationErrorStored
193 except AttributeError:
194 raise daError("[daStudy::setObservationError] Storage is not defined !")
195 self.ADD.setObservationError(asCovariance = ObservationError, toBeStored = self.ObservationErrorStored)
197 #--------------------------------------
199 def getObservationOperatorType(self, Name):
202 rtn = self.ObservationOperatorType[Name]
207 def setObservationOperatorType(self, Name, Type):
209 self.ObservationOperatorType[Name] = Type
210 elif Type == "Function":
211 self.ObservationOperatorType[Name] = Type
213 raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + ". Types are : Matrix, Function")
215 def setObservationOperator(self, Name, ObservationOperator):
217 self.ObservationOperatorType[Name]
218 except AttributeError:
219 raise daError("[daStudy::setObservationOperator] Type is not defined !")
220 if self.ObservationOperatorType[Name] == "Matrix":
221 self.ADD.setObservationOperator(asMatrix = ObservationOperator)
222 elif self.ObservationOperatorType[Name] == "Function":
223 self.FunctionObservationOperator[Name] = ObservationOperator
225 #--------------------------------------
227 def setEvolutionErrorStored(self, Stored):
229 self.EvolutionErrorStored = True
231 self.EvolutionErrorStored = False
233 def setEvolutionError(self, EvolutionError):
235 self.EvolutionErrorStored
236 except AttributeError:
237 raise daError("[daStudy::setEvolutionError] Storage is not defined !")
238 self.ADD.setEvolutionError(asCovariance = EvolutionError, toBeStored = self.EvolutionErrorStored)
240 #--------------------------------------
242 def getEvolutionModelType(self, Name):
245 rtn = self.EvolutionModelType[Name]
250 def setEvolutionModelType(self, Name, Type):
252 self.EvolutionModelType[Name] = Type
253 elif Type == "Function":
254 self.EvolutionModelType[Name] = Type
256 raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + ". Types are : Matrix, Function")
258 def setEvolutionModel(self, Name, EvolutionModel):
260 self.EvolutionModelType[Name]
261 except AttributeError:
262 raise daError("[daStudy::setEvolutionModel] Type is not defined !")
263 if self.EvolutionModelType[Name] == "Matrix":
264 self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
265 elif self.EvolutionModelType[Name] == "Function":
266 self.FunctionEvolutionModel[Name] = EvolutionModel
268 #--------------------------------------
270 def addObserver(self, name, scheduler, info, number):
271 self.observers_dict[name] = {}
272 self.observers_dict[name]["scheduler"] = scheduler
273 self.observers_dict[name]["info"] = info
274 self.observers_dict[name]["number"] = number
276 def getObservers(self):
277 return self.observers_dict