Salome HOME
Improvement and extension of EnKF algorithm (loc)
[modules/adao.git] / bin / AdaoCatalogGenerator.py
index d162eeb9c21c490010cc386b3510bb7569f382b6..ec0a494092916ba411ade79286d31426cf2acf58 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2008-2018 EDF R&D
+# Copyright (C) 2008-2020 EDF R&D
 #
 # This file is part of SALOME ADAO module
 #
@@ -35,10 +35,24 @@ logging.basicConfig(level=logging.WARNING)
 if sys.version_info.major > 2:
     def unicode(text, encoding='utf-8'): return text
 
+print("-- Starting AdaoCalatogGenerator.py --")
+
+try:
+  import adao
+  import daEficas
+  import daYacsSchemaCreator
+  import daCore.AssimilationStudy
+  import daYacsSchemaCreator.infos_daComposant as infos
+except:
+  logging.fatal("Import of ADAO python modules failed !" +
+                "\n add ADAO python installation directory in your PYTHONPATH")
+  traceback.print_exc()
+  sys.exit(1)
+
 #----------- Templates Part ---------------#
 begin_catalog_file = """# -*- coding: utf-8 -*-
 #
-# Copyright (C) 2008-2018 EDF R&D
+# Copyright (C) 2008-2020 EDF R&D
 #
 # This file is part of SALOME ADAO module
 #
@@ -111,7 +125,13 @@ def AdjointOperatorInNS(filename):
             if cr.match(ln): return 1
     return 0
 AdjointOperatorInNS.info = u"The Python file has to contain explicitly an \\"AdjointOperator\\" function definition with only one pair of vectors as argument."
-"""%(module_version.name,module_version.version)
+def ColDataFileExtVal(filename):
+    __readable = (".csv", ".tsv", ".txt", ".npy", ".npz")
+    if os.path.exists(filename) and os.path.splitext(filename)[1] in __readable:
+        return 1
+    return 0
+ColDataFileExtVal.info = u"The data file has to contain explicitly one or more number columns with separator, or one variable, that can fit in a unique continuous vector."
+"""%(module_version.name,module_version.cata)
 
 # Important : validators=[...] pour que les conditions soient traitees simultanement, en "ET", et pas en "OU" (choisi dans le cas du tuple a la place de la liste)
 # validators=[OnlyStr(), FileExtVal('py'), FunctionVal(fv)]
@@ -120,7 +140,11 @@ def F_{data_name}(statut, fv=NoCheckInNS) : return FACT(
     statut = statut,
     FROM = SIMP(statut = "o", typ = "TXM", into=({data_into}), defaut={data_default}),
     SCRIPT_DATA = BLOC ( condition = " FROM in ( 'Script', ) ",
-        SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=[OnlyStr(), FileExtVal('py'), FunctionVal(fv)], fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant si nécessaire la définition d'une variable interne de même nom que le concept parent", ang="Waiting for a script file name, with or without the full path to find it, containing if necessary the definition of an internal variable of the same name as the parent concept"),
+        SCRIPT_FILE = SIMP(statut = "o", typ = ("FichierNoAbs",'Python Files (*.py)',), validators=[OnlyStr(), FileExtVal('py'), FunctionVal(fv)], fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant si nécessaire la définition d'une variable interne de même nom que le concept parent", ang="Waiting for a script file name, with or without the full path to find it, containing if necessary the definition of an internal variable of the same name as the parent concept"),
+        ),
+    DATA_DATA = BLOC ( condition = " FROM in ( 'DataFile', ) ",
+        DATA_FILE = SIMP(statut = "o", typ = ("FichierNoAbs",'CSV Text Files (*.csv);;TSV Text Files (*.tsv);;TXT Text Files (*.txt);;NPY Binary Numpy Files (*.npy);;NPZ Binary Numpy Files (*.npz);;All Files (*)", ',), validators=[OnlyStr(), FunctionVal(ColDataFileExtVal)], fr="En attente d'un nom de fichier de données, avec ou sans le chemin complet pour le trouver, contenant ou plusieurs colonnes pour définir un unique vecteur continu", ang="Waiting for a data file name, with or without the full path to find it, containing one or more columns to define a unique continuous vector"),
+        ColMajor = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0, fr="Variables en colonnes acquises ligne par ligne (0) ou colonne par colonne (1)", ang="Variables in columns acquired line by line (0) or column by column (1)"),
         ),
     STRING_DATA = BLOC ( condition = " FROM in ( 'String', ) ",
         STRING = SIMP(statut = "o", typ = "TXM",{ms_default} fr="En attente d'une chaine de caractères entre guillements. Pour construire un vecteur ou une matrice, ce doit être une suite de nombres, utilisant un espace ou une virgule pour séparer deux éléments et un point-virgule pour séparer deux lignes", ang="Waiting for a string in quotes. To build a vector or a matrix, it has to be a float serie, using a space or comma to separate two elements in a line, a semi-colon to separate rows"),
@@ -141,13 +165,13 @@ def F_{data_name}(statut, fv=NoCheckInNS) : return FACT(
     TEMPLATE_DATA =  BLOC (condition = " FROM in ( 'Template', ) ",
         Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "AnalysisPrinter", into=("AnalysisPrinter", "AnalysisSaver", "AnalysisPrinterAndSaver")),
         AnalysisPrinter = BLOC (condition = " Template == 'AnalysisPrinter' ",
-            ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa" ),
+            ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint('Analysis:',xa)" ),
             ),
         AnalysisSaver = BLOC (condition = " Template == 'AnalysisSaver' ",
-            ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nf='/tmp/analysis.txt'\\nprint 'Analysis saved in \\"%s\\"'%f\\nnumpy.savetxt(f,xa)" ),
+            ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nf='/tmp/analysis.txt'\\nprint('Analysis saved in \\"%s\\"'%f)\\nnumpy.savetxt(f,xa)" ),
             ),
         AnalysisPrinterAndSaver = BLOC (condition = " Template == 'AnalysisPrinterAndSaver' ",
-            ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa\\nf='/tmp/analysis.txt'\\nprint 'Analysis saved in \\"%s\\"'%f\\nnumpy.savetxt(f,xa)" ),
+            ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nxa=numpy.ravel(ADD.get('Analysis')[-1])\\nprint 'Analysis:',xa\\nf='/tmp/analysis.txt'\\nprint('Analysis saved in \\"%s\\"'%f)\\nnumpy.savetxt(f,xa)" ),
             ),
         ),
     )
@@ -273,6 +297,7 @@ ASSIMILATION_STUDY = PROC(nom="ASSIMILATION_STUDY",
     StudyName           = SIMP(statut="o", typ = "TXM", defaut="ADAO Calculation Case"),
     StudyRepertory      = SIMP(statut="f", typ = "Repertoire", validators=FunctionVal(ChDir), min=1, max=1),
     Debug               = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0),
+    ExecuteInContainer  = SIMP(statut="f", typ = "TXM", min=1, max=1, defaut = "No", into=("No", "Mono", "Multi")),
     AlgorithmParameters = F_AlgorithmParameters("o",({algos_names}), AlgorithmParametersInNS),
     Background          = F_Background("o", BackgroundInNS),
     BackgroundError     = F_BackgroundError("o", BackgroundErrorInNS),
@@ -295,8 +320,10 @@ CHECKING_STUDY = PROC(nom="CHECKING_STUDY",
     StudyName           = SIMP(statut="o", typ = "TXM", defaut="ADAO Checking Case"),
     StudyRepertory      = SIMP(statut="f", typ = "Repertoire", validators=FunctionVal(ChDir), min=1, max=1),
     Debug               = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0),
+    ExecuteInContainer  = SIMP(statut="f", typ = "TXM", min=1, max=1, defaut = "No", into=("No", "Mono", "Multi")),
     AlgorithmParameters = F_AlgorithmParameters("o", ({check_names}), AlgorithmParametersInNS),
     CheckingPoint       = F_CheckingPoint("o", CheckingPointInNS),
+    Background          = F_Background("f", BackgroundInNS),
     BackgroundError     = F_BackgroundError("f", BackgroundErrorInNS),
     Observation         = F_Observation("f", ObservationInNS),
     ObservationError    = F_ObservationError("f", ObservationErrorInNS),
@@ -311,18 +338,6 @@ CHECKING_STUDY = PROC(nom="CHECKING_STUDY",
 
 
 #----------- Begin generation script -----------#
-print("-- Starting AdaoCalatogGenerator.py --")
-
-try:
-  import daEficas
-  import daYacsSchemaCreator
-  import daCore.AssimilationStudy
-  import daYacsSchemaCreator.infos_daComposant as infos
-except:
-  logging.fatal("Import of ADAO python modules failed !" +
-                "\n add ADAO python installation directory in your PYTHONPATH")
-  traceback.print_exc()
-  sys.exit(1)
 
 # Parse arguments
 from argparse import ArgumentParser