Salome HOME
Adding examples for each optional command
[modules/adao.git] / bin / AdaoCatalogGenerator.py
index 941d1dd3c32f409f5865cef678adc97ec541429b..b7ff1cebfb361205e4bac250546c4b90992d2805 100644 (file)
@@ -1,23 +1,22 @@
-#-*- coding:utf-8 -*-
-#  Copyright (C) 2008-2011  EDF R&D
+#-*-coding:iso-8859-1-*-
 #
-#  This library is free software; you can redistribute it and/or
-#  modify it under the terms of the GNU General Public
-#  License as published by the Free Software Foundation; either
-#  version 2.1 of the License.
+# Copyright (C) 2008-2014 EDF R&D
 #
-#  This library is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  Lesser General Public License for more details.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
 #
-#  You should have received a copy of the GNU Lesser General Public
-#  License along with this library; if not, write to the Free Software
-#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
 #
-# --
-# Author : André RIBES (EDF R&D)
-# --
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
 
 import logging
 import traceback
@@ -25,11 +24,12 @@ import sys
 import string
 import StringIO
 
-logging.basicConfig(level=logging.DEBUG)
+import module_version
+
+logging.basicConfig(level=logging.WARNING)
 
 #----------- Templates Part ---------------#
-begin_catalog_file = """
-# -*- coding: utf-8 -*-
+begin_catalog_file = """# -*- coding: utf-8 -*-
 
 # --------------------------------------------------------
 # generated by AdaoCatalogGenerator at ${date}
@@ -38,27 +38,55 @@ begin_catalog_file = """
 import Accas
 from Accas import *
 
-JdC = JDC_CATA (code = 'ADAO',
+JdC = JDC_CATA (code = '%s',
                 execmodul = None,
-                regles = ( AU_MOINS_UN ('ASSIMILATION_STUDY'), AU_PLUS_UN ('ASSIMILATION_STUDY')),
+                regles = ( AU_MOINS_UN ('ASSIMILATION_STUDY','CHECKING_STUDY'), AU_PLUS_UN ('ASSIMILATION_STUDY','CHECKING_STUDY')),
                )
-"""
+VERSION_CATALOGUE='%s'
+"""%(module_version.name,module_version.version)
 
 data_method = """
 def F_${data_name}(statut) : 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())),
+                                                      SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), 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"),
                                                      ),
                                          STRING_DATA = BLOC ( condition = " FROM in ( 'String', ) ",
 
-                                                      STRING = SIMP(statut = "o", typ = "TXM"),
+                                                      STRING = SIMP(statut = "o", typ = "TXM", 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"),
+                                                     ),
+                                         SCRIPTWITHFUNCTIONS_DATA = BLOC ( condition = " FROM in ( 'ScriptWithFunctions', ) ",
+
+                                                      SCRIPTWITHFUNCTIONS_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant en variables internes trois fonctions de calcul nommées DirectOperator, TangentOperator et AdjointOperator", ang="Waiting for a script file name, with or without the full path to find it, containing as internal variables three computation functions named DirectOperator, TangentOperator and AdjointOperator"),
+                                                     ),
+                                         SCRIPTWITHONEFUNCTION_DATA = BLOC ( condition = " FROM in ( 'ScriptWithOneFunction', ) ",
+
+                                                      SCRIPTWITHONEFUNCTION_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant en variable interne une seule fonction de calcul nommée DirectOperator", ang="Waiting for a script file name, with or without the full path to find it, containing as internal variable only one function named DirectOperator"),
+                                                      DifferentialIncrement = SIMP(statut="o", typ = "R", val_min=0, val_max=1, defaut=0.01, fr="Incrément de la perturbation dX pour calculer la dérivée, construite en multipliant X par l'incrément en évitant les valeurs nulles", ang="Increment of dX perturbation to calculate the derivative, build multiplying X by the increment avoiding null values"),
+                                                      CenteredFiniteDifference = SIMP(statut="o", typ = "I", into=(0, 1), defaut=0, fr="Formulation centrée (1) ou décentrée (0) pour la méthode des différences finies", ang="Centered (1) or uncentered (0) formulation for the finite differences method"),
+                                                      EnableMultiProcessing = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0, fr="EXPERIMENTAL : Calculs élémentaires effectués en séquentiel (0) ou en parallèle (1) dans la méthode des différences finies", ang="EXPERIMENTAL: Elementary calculations done sequentially (0) or in parallel (1) in the finite differences method"),
+                                                     ),
+                                         SCRIPTWITHSWITCH_DATA = BLOC ( condition = " FROM in ( 'ScriptWithSwitch', ) ",
+
+                                                      SCRIPTWITHSWITCH_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant un switch pour les calculs direct, tangent et adjoint", ang="Waiting for a script file name, with or without the full path to find it, containing a switch for direct, tangent and adjoint computations"),
                                                      ),
                                          FUNCTIONDICT_DATA = BLOC ( condition = " FROM in ( 'FunctionDict', ) ",
 
-                                                      FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())),
+                                                      FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="OBSOLETE : conservé pour compatibilité avec la version 6.5, sera supprimé dans le futur", ang="OBSOLETE: keeped for compatibility with the 6.5 version, will be removed in the future"),
                                                      ),
+                                         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" ),
+                                             ),
+                                             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)" ),
+                                             ),
+                                             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)" ),
+                                             ),
+                                         ),
                                     )
 """
 
@@ -68,6 +96,8 @@ def F_InitChoice() : return  ("Background",
                               "Observation",
                               "ObservationError",
                               "ObservationOperator",
+                              "EvolutionModel",
+                              "EvolutionError",
                               "AlgorithmParameters",
                               "UserPostAnalysis",
                              )
@@ -80,6 +110,7 @@ def F_Init(statut) : return FACT(statut = statut,
 
 assim_data_method = """
 def F_${assim_name}(statut) : return FACT(statut=statut,
+${storage}
                                           INPUT_TYPE = SIMP(statut="o", typ = "TXM", into=(${choices}), defaut=${default_choice}),
 ${decl_choices}
                                                 )
@@ -93,18 +124,45 @@ assim_data_choice = """
 
 observers_choice = """
                                        ${var_name} = BLOC (condition=" '${var_name}' in set(SELECTION) ",
-                                                  ${var_name}_data = FACT(statut = "o",
-                                                             Scheduler = SIMP(statut = "f", typ = "TXM"),
-                                                             Info      = SIMP(statut = "f", typ = "TXM"),
-                                                             NodeType  = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "", into=("String", "Script")),
-                                                             PythonScript = BLOC (condition = " NodeType == 'String' ",
-                                                                                  Value = SIMP(statut = "o", typ = "TXM")
-                                                                                 ),
-                                                             UserFile = BLOC (condition = " NodeType == 'Script' ",
-                                                                              Value = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()))
-                                                                             )
-                                                                      ),
-                                                          ),
+                                           ${var_name}_data = FACT(statut = "o",
+                                               Scheduler    = SIMP(statut = "f", typ = "TXM"),
+                                               Info         = SIMP(statut = "o", typ = "TXM", defaut = "${var_name}"),
+                                               NodeType     = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "Template", into=("String", "Script", "Template")),
+                                               PythonScript = BLOC (condition = " NodeType == 'String' ",
+                                                   Value = SIMP(statut = "o", typ = "TXM")
+                                               ),
+                                               UserFile = BLOC (condition = " NodeType == 'Script' ",
+                                                   Value = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()))
+                                               ),
+                                               ObserverTemplate =  BLOC (condition = " NodeType == 'Template' ",
+                                                   Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "ValuePrinter", into=("ValuePrinter", "ValueSeriePrinter", "ValueSaver", "ValueSerieSaver", "ValuePrinterAndSaver", "ValueSeriePrinterAndSaver", "ValueGnuPlotter", "ValueSerieGnuPlotter")),
+                                                   ValuePrinter = BLOC (condition = " Template == 'ValuePrinter' ",
+                                                       ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info,var[-1]" ),
+                                                   ),
+                                                   ValueSeriePrinter = BLOC (condition = " Template == 'ValueSeriePrinter' ",
+                                                       ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info,var[:]" ),
+                                                   ),
+                                                   ValueSaver = BLOC (condition = " Template == 'ValueSaver' ",
+                                                       ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[-1]))\\nglobal istep\\ntry:\\n    istep += 1\\nexcept:\\n    istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ),
+                                                   ),
+                                                   ValueSerieSaver = BLOC (condition = " Template == 'ValueSerieSaver' ",
+                                                       ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[:])) \\nglobal istep\\ntry:\\n    istep += 1\\nexcept:\\n    istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ),
+                                                   ),
+                                                   ValuePrinterAndSaver = BLOC (condition = " Template == 'ValuePrinterAndSaver' ",
+                                                       ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[-1]))\\nprint info,v\\nglobal istep\\ntry:\\n    istep += 1\\nexcept:\\n    istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ),
+                                                   ),
+                                                   ValueSeriePrinterAndSaver = BLOC (condition = " Template == 'ValueSeriePrinterAndSaver' ",
+                                                       ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy,re\\nv=numpy.array((var[:])) \\nprint info,v\\nglobal istep\\ntry:\\n    istep += 1\\nexcept:\\n    istep = 0\\nf='/tmp/value_%s_%05i.txt'%(info,istep)\\nf=re.sub('\\s','_',f)\\nprint 'Value saved in \\"%s\\"'%f\\nnumpy.savetxt(f,v)" ),
+                                                   ),
+                                                   ValueGnuPlotter = BLOC (condition = " Template == 'ValueGnuPlotter' ",
+                                                       ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import Gnuplot\\nglobal ifig,gp\\ntry:\\n    ifig += 1\\n    gp('set style data lines')\\nexcept:\\n    ifig = 0\\n    gp = Gnuplot.Gnuplot(persist=1)\\n    gp('set style data lines')\\ngp('set title  \\"%s (Figure %i)\\"'%(info,ifig))\\ngp.plot( Gnuplot.Data( var[-1], with_='lines lw 2' ) )" ),
+                                                   ),
+                                                   ValueSerieGnuPlotter = BLOC (condition = " Template == 'ValueSerieGnuPlotter' ",
+                                                       ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import Gnuplot\\nglobal ifig,gp\\ntry:\\n    ifig += 1\\n    gp('set style data lines')\\nexcept:\\n    ifig = 0\\n    gp = Gnuplot.Gnuplot(persist=1)\\n    gp('set style data lines')\\ngp('set title  \\"%s (Figure %i)\\"'%(info,ifig))\\ngp.plot( Gnuplot.Data( var[:], with_='lines lw 2' ) )" ),
+                                                   ),
+                                               ),
+                                           ),
+                                       ),
 """
 
 observers_method = """
@@ -125,22 +183,42 @@ def F_variables(statut) : return FACT(statut=statut,
 ASSIMILATION_STUDY = PROC(nom="ASSIMILATION_STUDY",
                           op=None,
                           repetable           = "n",
-                          Study_name          = SIMP(statut="o", typ = "TXM"),
-                          Study_repertory     = SIMP(statut="f", typ = "TXM"),
-                          Debug               = SIMP(statut="o", typ = "I", into=(0, 1), defaut=0),
+                          Study_name          = SIMP(statut="o", typ = "TXM", defaut="ADAO Calculation Case"),
+                          Study_repertory     = SIMP(statut="f", typ = "Repertoire", min=1, max=1),
+                          Debug               = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0),
                           Algorithm           = SIMP(statut="o", typ = "TXM", into=(${algos_names})),
                           Background          = F_Background("o"),
                           BackgroundError     = F_BackgroundError("o"),
                           Observation         = F_Observation("o"),
                           ObservationError    = F_ObservationError("o"),
                           ObservationOperator = F_ObservationOperator("o"),
+                          EvolutionModel      = F_EvolutionModel("f"),
+                          EvolutionError      = F_EvolutionError("f"),
+                          ControlInput        = F_ControlInput("f"),
                           AlgorithmParameters = F_AlgorithmParameters("f"),
                           UserDataInit        = F_Init("f"),
-                          UserPostAnalysis    = F_UserPostAnalysis("f"),
+                          UserPostAnalysis    = F_UserPostAnalysis("o"),
                           InputVariables      = F_variables("f"),
                           OutputVariables     = F_variables("f"),
                           Observers           = F_Observers("f")
                          )
+
+CHECKING_STUDY = PROC(nom="CHECKING_STUDY",
+                          op=None,
+                          repetable           = "n",
+                          Study_name          = SIMP(statut="o", typ = "TXM", defaut="ADAO Checking Case"),
+                          Study_repertory     = SIMP(statut="f", typ = "Repertoire", min=1, max=1),
+                          Debug               = SIMP(statut="f", typ = "I", into=(0, 1), defaut=0),
+                          Algorithm           = SIMP(statut="o", typ = "TXM", into=(${check_names})),
+                          CheckingPoint       = F_CheckingPoint("o"),
+                          BackgroundError     = F_BackgroundError("f"),
+                          Observation         = F_Observation("f"),
+                          ObservationError    = F_ObservationError("f"),
+                          ObservationOperator = F_ObservationOperator("o"),
+                          AlgorithmParameters = F_AlgorithmParameters("f"),
+                          UserDataInit        = F_Init("f"),
+                          Observers           = F_Observers("f")
+                         )
 """
 
 begin_catalog_file = string.Template(begin_catalog_file)
@@ -193,44 +271,50 @@ mem_file = StringIO.StringIO()
 from time import strftime
 mem_file.write(begin_catalog_file.substitute(date=strftime("%Y-%m-%d %H:%M:%S")))
 
-# Step 1: A partir des infos, on crée les fonctions qui vont permettre
-# d'entrer les données utilisateur
+# Step 1: A partir des infos, on cree les fonctions qui vont permettre
+# d'entrer les donnees utilisateur
 for data_input_name in infos.DataTypeDict.keys():
   logging.debug('A data input Type is found: ' + data_input_name)
   data_name = data_input_name
   data_into = ""
   data_default = ""
 
-  # On récupère les différentes façon d'entrer les données
+  # On recupere les differentes facon d'entrer les donnees
   for basic_type in infos.DataTypeDict[data_input_name]:
     data_into += "\"" + basic_type + "\", "
 
-  # On choisit le défault
+  # On choisit le default
   data_default = "\"" + infos.DataTypeDefaultDict[data_input_name] + "\""
 
   mem_file.write(data_method.substitute(data_name    = data_name,
                                         data_into    = data_into,
                                         data_default = data_default))
 
-# Step 2: On crée les fonctions qui permettent de rentrer les données des algorithmes
+# Step 2: On cree les fonctions qui permettent de rentrer les donnees des algorithmes
 for assim_data_input_name in infos.AssimDataDict.keys():
   logging.debug("An assimilation algorithm data input is found: " + assim_data_input_name)
   assim_name = assim_data_input_name
+  storage = ""
   choices = ""
   default_choice = ""
   decl_choices = ""
   decl_opts = ""
+  if infos.AssimDataDefaultDict[assim_data_input_name] in infos.StoredAssimData:
+    storage = "                                          Stored = SIMP(statut=\"o\", typ = \"I\", into=(0, 1), defaut=0, fr=\"Choix de stockage interne ou non du concept parent\", ang=\"Choice of the storage or not of the parent concept\"),"
   for choice in infos.AssimDataDict[assim_data_input_name]:
     choices += "\"" + choice + "\", "
     decl_choices += assim_data_choice.substitute(choice_name = choice)
+    if choice in infos.StoredAssimData:
+      storage = "                                          Stored = SIMP(statut=\"o\", typ = \"I\", into=(0, 1), defaut=0, fr=\"Choix de stockage interne ou non du concept parent\", ang=\"Choice of the storage or not of the parent concept\"),"
   default_choice = "\"" + infos.AssimDataDefaultDict[assim_data_input_name] + "\""
 
   mem_file.write(assim_data_method.substitute(assim_name = assim_name,
+                                              storage = storage,
                                               choices = choices,
                                               decl_choices = decl_choices,
                                               default_choice=default_choice))
 
-# Step 3: On ajoute les fonctions représentant les options possibles
+# Step 3: On ajoute les fonctions representant les options possibles
 for opt_name in infos.OptDict.keys():
   logging.debug("An optional node is found: " + opt_name)
   data_name = opt_name
@@ -245,7 +329,7 @@ for opt_name in infos.OptDict.keys():
                                         data_into = data_into,
                                         data_default = data_default))
 
-# Step 4: On ajoute la méthode optionnelle init
+# Step 4: On ajoute la methode optionnelle init
 # TODO uniformiser avec le step 3
 mem_file.write(init_method)
 
@@ -258,15 +342,23 @@ mem_file.write(observers_method.substitute(choices = infos.ObserversList,
 
 # Final step: Add algorithm and assim_study
 algos_names = ""
-decl_algos = ""
+check_names = ""
+decl_algos  = ""
 
 assim_study_object = daCore.AssimilationStudy.AssimilationStudy()
 algos_list = assim_study_object.get_available_algorithms()
 for algo_name in algos_list:
-  logging.debug("An assimilation algorithm is found: " + algo_name)
-  algos_names += "\"" + algo_name + "\", "
+  if algo_name in infos.AssimAlgos:
+    logging.debug("An assimilation algorithm is found: " + algo_name)
+    algos_names += "\"" + algo_name + "\", "
+  elif algo_name in infos.CheckAlgos:
+    logging.debug("A checking algorithm is found: " + algo_name)
+    check_names += "\"" + algo_name + "\", "
+  else:
+    logging.debug("This algorithm is not considered: " + algo_name)
 
 mem_file.write(assim_study.substitute(algos_names=algos_names,
+                                      check_names=check_names,
                                       decl_algos=decl_algos))
 # Write file
 final_file = open(catalog_path + "/" + catalog_name, "wr")