]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
Permet d'ajouter un code d'analyse à partir d'un fichier
authorAndré <andre.ribes@edf.fr>
Thu, 22 Apr 2010 14:27:01 +0000 (16:27 +0200)
committerAndré <andre.ribes@edf.fr>
Thu, 22 Apr 2010 14:27:01 +0000 (16:27 +0200)
src/daSalome/daYacsSchemaCreator/help_methods.py
src/daSalome/daYacsSchemaCreator/infos_daComposant.py
src/daSalome/daYacsSchemaCreator/methods.py
src/tests/daSalome/test000_Blue_AnalysisCode.py [new file with mode: 0644]
src/tests/daSalome/test000_Blue_AnalysisFile.py [new file with mode: 0644]

index 9621af3bffffd2b6bb97b453df82b746c1020b0a..eecd291bef093768fed589242f6fb3dd1b48c0f1 100644 (file)
@@ -76,9 +76,9 @@ def check_study(study_config):
       logging.fatal("Analysis found but From is not defined in the analysis configuration !")
       sys.exit(1)
     else:
-      if analysis_config["From"] != "string":
+      if analysis_config["From"] not in AnalysisFromList:
         logging.fatal("Analysis From defined in the study configuration does not have a correct type : " + str(analysis_config["From"])
-                      + "\n You can have : string")
+                      + "\n You can have : " + str(AnalysisFromList))
         sys.exit(1)
     if "Data" not in analysis_config:
       logging.fatal("Analysis found but Data is not defined in the analysis configuration !")
index 019cea3df4634e94fef9ab5d250fb816f07a07ce..d957c078ae9fe5b355a456ab64d59b781fac5f67 100644 (file)
 # --
 
 
+# -- Infos pour le parser --
+
+AnalysisData = {}
+AnalysisFromList = ["string", "file"]
+
 # -- Infos from daCore --
 AssimData = ["Background", "BackgroundError",
              "Observation", "ObservationError", "ObservationOperator", "ObservationOperatorAppliedToX",
index 5071ae08e06d09111b89a277aa4c99cc848de699..fdcd0455c0f54cec5047ad6762faf956067134f3 100644 (file)
@@ -116,6 +116,28 @@ def create_yacs_proc(study_config):
       proc.edAddCFLink(compute_bloc, analysis_node)
       proc.edAddDFLink(execute_node.getOutputPort("Study"), analysis_node.getInputPort("Study"))
 
+    elif analysis_config["From"] == "file":
+      factory_analysis_node = catalogAd._nodeMap["SimpleUserAnalysis"]
+      analysis_node = factory_analysis_node.cloneNode("User Analysis")
+      default_script = analysis_node.getScript()
+      if not os.path.exists(analysis_config["Data"]):
+        logging.fatal("Analysis source file does not exists ! :" + str(analysis_config["Data"]))
+        sys.exit(1)
+      try:
+        analysis_file = open(analysis_config["Data"], 'r')
+      except:
+        logging.fatal("Exception in openng analysis file : " + str(analysis_config["Data"]))
+        traceback.print_exc()
+        sys.exit(1)
+      file_text = analysis_file.read()
+      final_script = default_script + file_text
+      analysis_node.setScript(final_script)
+      proc.edAddChild(analysis_node)
+      proc.edAddCFLink(compute_bloc, analysis_node)
+      proc.edAddDFLink(execute_node.getOutputPort("Study"), analysis_node.getInputPort("Study"))
+
+      pass
+
   return proc
 
 def write_yacs_proc(proc, yacs_schema_filename):
diff --git a/src/tests/daSalome/test000_Blue_AnalysisCode.py b/src/tests/daSalome/test000_Blue_AnalysisCode.py
new file mode 100644 (file)
index 0000000..8a27a3d
--- /dev/null
@@ -0,0 +1,17 @@
+#-*-coding:iso-8859-1-*-
+import numpy
+precision = 1.e-13
+
+Xa = ADD.get("Analysis")
+print
+print "    Nombre d'analyses  :",Xa.stepnumber()
+print "    Analyse résultante :",Xa.valueserie(0)
+#
+# Vérification du résultat
+# ------------------------
+if max(numpy.array(Xa.valueserie(0))-numpy.array([0.25, 1.25, 2.25])) > precision:
+  raise ValueError("Résultat du test erroné")
+else:
+  print "    Test correct, erreur maximale inférieure à %s"%precision
+  print
+
diff --git a/src/tests/daSalome/test000_Blue_AnalysisFile.py b/src/tests/daSalome/test000_Blue_AnalysisFile.py
new file mode 100644 (file)
index 0000000..5d75d0f
--- /dev/null
@@ -0,0 +1,40 @@
+#-*-coding:iso-8859-1-*-
+study_config = {}
+study_config["Name"] = "test000_Blue"
+study_config["Algorithm"] = "Blue"
+
+Background_config = {}
+Background_config["Data"] = "0,1,2"
+Background_config["Type"] = "Vector"
+Background_config["From"] = "string"
+study_config["Background"] = Background_config
+
+BackgroundError_config = {}
+BackgroundError_config["Data"] = "1 0 0;0 1 0;0 0 1"
+BackgroundError_config["Type"] = "Matrix"
+BackgroundError_config["From"] = "string"
+study_config["BackgroundError"] = BackgroundError_config
+
+Observation_config = {}
+Observation_config["Data"] = "0.5,1.5,2.5"
+Observation_config["Type"] = "Vector"
+Observation_config["From"] = "string"
+study_config["Observation"] = Observation_config
+
+ObservationError_config = {}
+ObservationError_config["Data"] = "1 0 0;0 1 0;0 0 1"
+ObservationError_config["Type"] = "Matrix"
+ObservationError_config["From"] = "string"
+study_config["ObservationError"] = ObservationError_config
+
+ObservationOperator_config = {}
+ObservationOperator_config["Data"] = "1 0 0;0 1 0;0 0 1"
+ObservationOperator_config["Type"] = "Matrix"
+ObservationOperator_config["From"] = "string"
+study_config["ObservationOperator"] = ObservationOperator_config
+
+Analysis_config = {}
+Analysis_config["Data"] = "/home/aribes/Projets/DATASSIM_SRC/src/tests/daSalome/test000_Blue_AnalysisCode.py"
+Analysis_config["From"] = "file"
+study_config["Analysis"] = Analysis_config
+