]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
ASTER Ok
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*- coding: utf-8 -*-
2
3 from daCore.AssimilationStudy import AssimilationStudy
4 from daCore import Logging
5 import logging
6
7 class daError(Exception):
8   def __init__(self, value):
9     self.value = value
10   def __str__(self):
11     return repr(self.value)
12
13 class daStudy:
14
15   def __init__(self, name, algorithm, debug):
16
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 = []
26
27     self.debug = debug
28     if self.debug:
29       logging.getLogger().setLevel(logging.DEBUG)
30     else:
31       logging.getLogger().setLevel(logging.INFO)
32
33     # Observation Management
34     self.ObservationOperatorType = {}
35     self.FunctionObservationOperator = {}
36
37   def setInputVariable(self, name, size):
38     self.InputVariables[name] = size
39     self.InputVariablesOrder.append(name)
40
41   def setOutputVariable(self, name, size):
42     self.OutputVariables[name] = size
43     self.OutputVariablesOrder.append(name)
44
45   def setAlgorithmParameters(self, parameters):
46     self.algorithm_dict = parameters
47
48   def initAlgorithm(self):
49
50     self.ADD.setAlgorithm(choice=self.algorithm)
51     if self.algorithm_dict != None:
52       self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
53
54   def getAssimilationStudy(self):
55
56     return self.ADD
57
58   # Methods to initialize AssimilationStudy
59
60   def setBackgroundType(self, Type):
61
62     if Type == "Vector":
63       self.BackgroundType = Type
64     else:
65       raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
66
67   def setBackground(self, Background):
68
69     try:
70       self.BackgroundType
71     except AttributeError:
72       raise daError("[daStudy::setBackground] Type is not defined !")
73
74     self.Background = Background
75
76     if self.BackgroundType == "Vector":
77       self.ADD.setBackground(asVector = Background)
78
79   def getBackground(self):
80     return self.Background
81
82   def setBackgroundError(self, BackgroundError):
83
84     self.ADD.setBackgroundError(asCovariance = BackgroundError)
85
86   def setObservationType(self, Type):
87
88     if Type == "Vector":
89       self.ObservationType = Type
90     else:
91       raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
92
93   def setObservation(self, Observation):
94
95     try:
96       self.ObservationType
97     except AttributeError:
98       raise daError("[daStudy::setObservation] Type is not defined !")
99
100     if self.ObservationType == "Vector":
101       self.ADD.setObservation(asVector = Observation)
102
103   def setObservationError(self, ObservationError):
104     self.ADD.setObservationError(asCovariance = ObservationError)
105
106
107   def getObservationOperatorType(self, Name):
108     rtn = None
109     try:
110       rtn = self.ObservationOperatorType[Name]
111     except:
112       pass
113     return rtn
114
115   def setObservationOperatorType(self, Name, Type):
116     if Type == "Matrix":
117       self.ObservationOperatorType[Name] = Type
118     elif Type == "Function":
119       self.ObservationOperatorType[Name] = Type
120     else:
121       raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix")
122
123   def setObservationOperator(self, Name, ObservationOperator):
124     try:
125       self.ObservationOperatorType[Name]
126     except AttributeError:
127       raise daError("[daStudy::setObservationOperator] Type is not defined !")
128
129     if self.ObservationOperatorType[Name] == "Matrix":
130       self.ADD.setObservationOperator(asMatrix = ObservationOperator)
131     elif self.ObservationOperatorType[Name] == "Function":
132       self.FunctionObservationOperator[Name] = ObservationOperator
133