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.FunctionObservationOperator = {}
57 def setInputVariable(self, name, size):
58 self.InputVariables[name] = size
59 self.InputVariablesOrder.append(name)
61 def setOutputVariable(self, name, size):
62 self.OutputVariables[name] = size
63 self.OutputVariablesOrder.append(name)
65 def setAlgorithmParameters(self, parameters):
66 self.algorithm_dict = parameters
68 def initAlgorithm(self):
70 self.ADD.setAlgorithm(choice=self.algorithm)
71 if self.algorithm_dict != None:
72 self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
74 def getAssimilationStudy(self):
78 # Methods to initialize AssimilationStudy
80 def setBackgroundType(self, Type):
83 self.BackgroundType = Type
85 raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
87 def setBackground(self, Background):
91 except AttributeError:
92 raise daError("[daStudy::setBackground] Type is not defined !")
94 self.Background = Background
96 if self.BackgroundType == "Vector":
97 self.ADD.setBackground(asVector = Background)
99 def getBackground(self):
100 return self.Background
102 def setBackgroundError(self, BackgroundError):
104 self.ADD.setBackgroundError(asCovariance = BackgroundError)
106 def setObservationType(self, Type):
109 self.ObservationType = Type
111 raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
113 def setObservation(self, Observation):
117 except AttributeError:
118 raise daError("[daStudy::setObservation] Type is not defined !")
120 if self.ObservationType == "Vector":
121 self.ADD.setObservation(asVector = Observation)
123 def setObservationError(self, ObservationError):
124 self.ADD.setObservationError(asCovariance = ObservationError)
127 def getObservationOperatorType(self, Name):
130 rtn = self.ObservationOperatorType[Name]
135 def setObservationOperatorType(self, Name, Type):
137 self.ObservationOperatorType[Name] = Type
138 elif Type == "Function":
139 self.ObservationOperatorType[Name] = Type
141 raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix")
143 def setObservationOperator(self, Name, ObservationOperator):
145 self.ObservationOperatorType[Name]
146 except AttributeError:
147 raise daError("[daStudy::setObservationOperator] Type is not defined !")
149 if self.ObservationOperatorType[Name] == "Matrix":
150 self.ADD.setObservationOperator(asMatrix = ObservationOperator)
151 elif self.ObservationOperatorType[Name] == "Function":
152 self.FunctionObservationOperator[Name] = ObservationOperator
154 def addObserver(self, name, scheduler, info):
155 self.observers_dict[name] = {}
156 self.observers_dict[name]["scheduler"] = scheduler
157 self.observers_dict[name]["info"] = info
159 def getObservers(self):
160 return self.observers_dict