]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
Merge remote-tracking branch 'andre/V6_main' into V6_main
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*- coding: utf-8 -*-
2 # Copyright (C) 2010-2011 EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
21
22 from daCore.AssimilationStudy import AssimilationStudy
23 from daCore import Logging
24 import logging
25
26 class daError(Exception):
27   def __init__(self, value):
28     self.value = value
29   def __str__(self):
30     return repr(self.value)
31
32 class daStudy:
33
34   def __init__(self, name, algorithm, debug):
35
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 = {}
46
47     self.debug = debug
48     if self.debug:
49       logging.getLogger().setLevel(logging.DEBUG)
50     else:
51       logging.getLogger().setLevel(logging.WARNING)
52
53     # Observation Management
54     self.ObservationOperatorType = {}
55     self.FunctionObservationOperator = {}
56
57   def setInputVariable(self, name, size):
58     self.InputVariables[name] = size
59     self.InputVariablesOrder.append(name)
60
61   def setOutputVariable(self, name, size):
62     self.OutputVariables[name] = size
63     self.OutputVariablesOrder.append(name)
64
65   def setAlgorithmParameters(self, parameters):
66     self.algorithm_dict = parameters
67
68   def initAlgorithm(self):
69
70     self.ADD.setAlgorithm(choice=self.algorithm)
71     if self.algorithm_dict != None:
72       print self.algorithm_dict
73       self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
74
75   def getAssimilationStudy(self):
76
77     return self.ADD
78
79   # Methods to initialize AssimilationStudy
80
81   def setBackgroundType(self, Type):
82
83     if Type == "Vector":
84       self.BackgroundType = Type
85     else:
86       raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
87
88   def setBackground(self, Background):
89
90     try:
91       self.BackgroundType
92     except AttributeError:
93       raise daError("[daStudy::setBackground] Type is not defined !")
94
95     self.Background = Background
96
97     if self.BackgroundType == "Vector":
98       self.ADD.setBackground(asVector = Background)
99
100   def getBackground(self):
101     return self.Background
102
103   def setBackgroundError(self, BackgroundError):
104
105     self.ADD.setBackgroundError(asCovariance = BackgroundError)
106
107   def setObservationType(self, Type):
108
109     if Type == "Vector":
110       self.ObservationType = Type
111     else:
112       raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
113
114   def setObservation(self, Observation):
115
116     try:
117       self.ObservationType
118     except AttributeError:
119       raise daError("[daStudy::setObservation] Type is not defined !")
120
121     if self.ObservationType == "Vector":
122       self.ADD.setObservation(asVector = Observation)
123
124   def setObservationError(self, ObservationError):
125     self.ADD.setObservationError(asCovariance = ObservationError)
126
127
128   def getObservationOperatorType(self, Name):
129     rtn = None
130     try:
131       rtn = self.ObservationOperatorType[Name]
132     except:
133       pass
134     return rtn
135
136   def setObservationOperatorType(self, Name, Type):
137     if Type == "Matrix":
138       self.ObservationOperatorType[Name] = Type
139     elif Type == "Function":
140       self.ObservationOperatorType[Name] = Type
141     else:
142       raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix")
143
144   def setObservationOperator(self, Name, ObservationOperator):
145     try:
146       self.ObservationOperatorType[Name]
147     except AttributeError:
148       raise daError("[daStudy::setObservationOperator] Type is not defined !")
149
150     if self.ObservationOperatorType[Name] == "Matrix":
151       self.ADD.setObservationOperator(asMatrix = ObservationOperator)
152     elif self.ObservationOperatorType[Name] == "Function":
153       self.FunctionObservationOperator[Name] = ObservationOperator
154
155   def addObserver(self, name, scheduler, info, number):
156     self.observers_dict[name] = {}
157     self.observers_dict[name]["scheduler"] = scheduler
158     self.observers_dict[name]["info"] = info
159     self.observers_dict[name]["number"] = number
160
161   def getObservers(self):
162     return self.observers_dict