3 from daCore.AssimilationStudy import AssimilationStudy
4 from daCore import Logging
7 class daError(Exception):
8 def __init__(self, value):
11 return repr(self.value)
15 def __init__(self, name, algorithm, debug):
17 self.ADD = AssimilationStudy(name)
18 self.ADD.setControls()
19 self.algorithm = algorithm
20 self.algorithm_dict = None
21 self.Background = None
22 self.InputVariables = {}
23 self.OutputVariables = {}
24 self.InputVariablesOrder = []
25 self.OutputVariablesOrder = []
29 logging.getLogger().setLevel(logging.DEBUG)
31 logging.getLogger().setLevel(logging.WARNING)
33 # Observation Management
34 self.ObservationOperatorType = {}
35 self.FunctionObservationOperator = {}
37 def setInputVariable(self, name, size):
38 self.InputVariables[name] = size
39 self.InputVariablesOrder.append(name)
41 def setOutputVariable(self, name, size):
42 self.OutputVariables[name] = size
43 self.OutputVariablesOrder.append(name)
45 def setAlgorithmParameters(self, parameters):
46 self.algorithm_dict = parameters
48 def initAlgorithm(self):
50 self.ADD.setAlgorithm(choice=self.algorithm)
51 if self.algorithm_dict != None:
52 self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
54 def getAssimilationStudy(self):
58 # Methods to initialize AssimilationStudy
60 def setBackgroundType(self, Type):
63 self.BackgroundType = Type
65 raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
67 def setBackground(self, Background):
71 except AttributeError:
72 raise daError("[daStudy::setBackground] Type is not defined !")
74 self.Background = Background
76 if self.BackgroundType == "Vector":
77 self.ADD.setBackground(asVector = Background)
79 def getBackground(self):
80 return self.Background
82 def setBackgroundError(self, BackgroundError):
84 self.ADD.setBackgroundError(asCovariance = BackgroundError)
86 def setObservationType(self, Type):
89 self.ObservationType = Type
91 raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
93 def setObservation(self, Observation):
97 except AttributeError:
98 raise daError("[daStudy::setObservation] Type is not defined !")
100 if self.ObservationType == "Vector":
101 self.ADD.setObservation(asVector = Observation)
103 def setObservationError(self, ObservationError):
104 self.ADD.setObservationError(asCovariance = ObservationError)
107 def getObservationOperatorType(self, Name):
110 rtn = self.ObservationOperatorType[Name]
115 def setObservationOperatorType(self, Name, Type):
117 self.ObservationOperatorType[Name] = Type
118 elif Type == "Function":
119 self.ObservationOperatorType[Name] = Type
121 raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix")
123 def setObservationOperator(self, Name, ObservationOperator):
125 self.ObservationOperatorType[Name]
126 except AttributeError:
127 raise daError("[daStudy::setObservationOperator] Type is not defined !")
129 if self.ObservationOperatorType[Name] == "Matrix":
130 self.ADD.setObservationOperator(asMatrix = ObservationOperator)
131 elif self.ObservationOperatorType[Name] == "Function":
132 self.FunctionObservationOperator[Name] = ObservationOperator