From 6feafbbdbda16348d5957978d6ed41be4cdd895f Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Sat, 12 Sep 2015 10:01:36 +0200 Subject: [PATCH] Adding observer templates and associated documentation --- bin/AdaoCatalogGenerator.py | 14 ++++++++++- doc/en/glossary.rst | 16 +++++++++++++ doc/en/ref_algorithm_3DVAR.rst | 5 ++++ doc/en/ref_output_variables.rst | 17 ++++++++----- doc/en/tui.rst | 33 +++++++++++++------------- doc/fr/glossary.rst | 16 +++++++++++++ doc/fr/ref_algorithm_3DVAR.rst | 6 +++++ doc/fr/ref_output_variables.rst | 6 +++++ doc/fr/tui.rst | 7 +++--- src/daComposant/daCore/PlatformInfo.py | 18 ++++++++++---- src/daSalome/adaoBuilder.py | 8 +++++++ 11 files changed, 115 insertions(+), 31 deletions(-) diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index 15d383a..95c2ace 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -207,7 +207,7 @@ observers_choice = """ observers_method = """ def F_ObserverTemplate() : return 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", "ValuePrinterAndGnuPlotter", "ValueSeriePrinterAndGnuPlotter", "ValuePrinterSaverAndGnuPlotter", "ValueSeriePrinterSaverAndGnuPlotter")), + Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "ValuePrinter", into=("ValuePrinter", "ValueSeriePrinter", "ValueSaver", "ValueSerieSaver", "ValuePrinterAndSaver", "ValueSeriePrinterAndSaver", "ValueGnuPlotter", "ValueSerieGnuPlotter", "ValuePrinterAndGnuPlotter", "ValueSeriePrinterAndGnuPlotter", "ValuePrinterSaverAndGnuPlotter", "ValueSeriePrinterSaverAndGnuPlotter", "ValueMean", "ValueStandardError", "ValueVariance", "ValueRMS")), ValuePrinter = BLOC (condition = " Template == 'ValuePrinter' ", ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info, var[-1]" ), ), @@ -244,6 +244,18 @@ def F_ObserverTemplate() : return BLOC(condition = " NodeType == 'Template' ", ValueSeriePrinterSaverAndGnuPlotter = BLOC (condition = " Template == 'ValueSeriePrinterSaverAndGnuPlotter' ", ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info, var[:] \\nimport numpy, re\\nv=numpy.array(var[:], ndmin=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)\\nimport 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( v, with_='lines lw 2' ) )" ), ), + ValuePrinter = BLOC (condition = " Template == 'ValueMean' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanmean(var[-1])" ), + ), + ValuePrinter = BLOC (condition = " Template == 'ValueStandardError' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanstd(var[-1])" ), + ), + ValuePrinter = BLOC (condition = " Template == 'ValueVariance' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanvar(var[-1])" ), + ), + ValuePrinter = BLOC (condition = " Template == 'ValueRMS' ", + ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nv = numpy.matrix( numpy.ravel( var[-1] ) )\\nprint info, float( numpy.sqrt((1./v.size)*(v*v.T)) )" ), + ), ) def F_Observers(statut) : return FACT( diff --git a/doc/en/glossary.rst b/doc/en/glossary.rst index e91d0a4..f9d8873 100644 --- a/doc/en/glossary.rst +++ b/doc/en/glossary.rst @@ -48,6 +48,18 @@ Glossary Keyword to indicate the covariance matrix of *a posteriori* analysis errors. + APosterioriCorrelations + Keyword to indicate the correlation matrix of *a posteriori* analysis + errors. + + APosterioriVariances + Keyword to indicate the variances diagonal matrix of *a posteriori* + analysis errors. + + APosterioriStandardDeviations + Keyword to indicate the standard errors diagonal matrix of *a posteriori* + analysis errors. + BMA (Background minus Analysis) Difference between the background state and the optimal state estimation, noted as :math:`\mathbf{x}^b - \mathbf{x}^a`. @@ -103,3 +115,7 @@ Glossary CostFunctionJb Keyword to indicate the background part of the minimization function, noted as :math:`J^b`. + + CurrentState + Keyword to indicate the current state used during an optimization + algorithm procedure. diff --git a/doc/en/ref_algorithm_3DVAR.rst b/doc/en/ref_algorithm_3DVAR.rst index 660ba8a..ef532d4 100644 --- a/doc/en/ref_algorithm_3DVAR.rst +++ b/doc/en/ref_algorithm_3DVAR.rst @@ -309,6 +309,11 @@ The conditional outputs of the algorithm are the following: Example : ``d = ADD.get("Innovation")[-1]`` + InnovationAtCurrentState + *List of vectors*. Each element is an innovation vector at current state. + + Example : ``ds = ADD.get("InnovationAtCurrentState")[-1]`` + MahalanobisConsistency *List of values*. Each element is a value of the Mahalanobis quality indicator. diff --git a/doc/en/ref_output_variables.rst b/doc/en/ref_output_variables.rst index 996096e..3d2cd8d 100644 --- a/doc/en/ref_output_variables.rst +++ b/doc/en/ref_output_variables.rst @@ -216,7 +216,7 @@ of availability. They are the following, in alphabetical order: matrix of the optimal state, coming from the :math:`\mathbf{A}*` covariance matrix. - Exemple : ``C = ADD.get("APosterioriCorrelations")[-1]`` + Example : ``C = ADD.get("APosterioriCorrelations")[-1]`` APosterioriCovariance *List of matrices*. Each element is an *a posteriori* error covariance @@ -229,14 +229,14 @@ of availability. They are the following, in alphabetical order: diagonal matrix of the optimal state, coming from the :math:`\mathbf{A}*` covariance matrix. - Exemple : ``S = ADD.get("APosterioriStandardDeviations")[-1]`` + Example : ``S = ADD.get("APosterioriStandardDeviations")[-1]`` APosterioriVariances *List of matrices*. Each element is an *a posteriori* error variances diagonal matrix of the optimal state, coming from the :math:`\mathbf{A}*` covariance matrix. - Exemple : ``V = ADD.get("APosterioriVariances")[-1]`` + Example : ``V = ADD.get("APosterioriVariances")[-1]`` BMA *List of vectors*. Each element is a vector of difference between the @@ -265,7 +265,7 @@ of availability. They are the following, in alphabetical order: *List of vectors*. Each element is the optimal state obtained at the current step of the optimization algorithm. It is not necessarely the last state. - Exemple : ``Xo = ADD.get("CurrentOptimum")[:]`` + Example : ``Xo = ADD.get("CurrentOptimum")[:]`` CurrentState *List of vectors*. Each element is a usual state vector used during the @@ -278,7 +278,7 @@ of availability. They are the following, in alphabetical order: obtained at the current step the optimization algorithm. It is not necessarely the number of the last iteration. - Exemple : ``i = ADD.get("MahalanobisConsistency")[-1]`` + Example : ``i = ADD.get("MahalanobisConsistency")[-1]`` Innovation *List of vectors*. Each element is an innovation vector, which is in static @@ -287,6 +287,11 @@ of availability. They are the following, in alphabetical order: Example : ``d = ADD.get("Innovation")[-1]`` + InnovationAtCurrentState + *List of vectors*. Each element is an innovation vector at current state. + + Example : ``ds = ADD.get("InnovationAtCurrentState")[-1]`` + MahalanobisConsistency *List of values*. Each element is a value of the Mahalanobis quality indicator. @@ -328,7 +333,7 @@ of availability. They are the following, in alphabetical order: the optimal state obtained at the current step the optimization algorithm, that is, in the observation space. - Exemple : ``hxo = ADD.get("SimulatedObservationAtCurrentOptimum")[-1]`` + Example : ``hxo = ADD.get("SimulatedObservationAtCurrentOptimum")[-1]`` SimulatedObservationAtCurrentState *List of vectors*. Each element is an observed vector at the current state, diff --git a/doc/en/tui.rst b/doc/en/tui.rst index ddeadd0..78487cf 100644 --- a/doc/en/tui.rst +++ b/doc/en/tui.rst @@ -445,30 +445,31 @@ Setting the calculation, outputs, etc. .. index:: single: setDebug **setDebug** () - This command enables the detailed information mode when running. + This command enables the detailed information mode when running. .. index:: single: setNoDebug **setNoDebug** () - This command disables the detailed information mode when running. + This command disables the detailed information mode when running. .. index:: single: setObserver **setObserver** (*Variable, Template, String, Script, Info*) - This command allows to set an *observer* on the current or final - calculation variable. Reference should be made to the description of the - way of ':ref:`section_advanced_observer`, and to the - :ref:`section_reference` to know what are the observable quantities. One - defines as "*String*" the *observer* body, using a string including if - necessary line breaks. It is recommended to use the patterns available by - the argument "*Template*". There exist the following simple patterns: - "ValuePrinter", "ValueSeriePrinter", "ValueSaver", "ValueSerieSaver", - "ValuePrinterAndSaver", "ValueSeriePrinterAndSaver", "ValueGnuPlotter", - "ValueSerieGnuPlotter", "ValuePrinterAndGnuPlotter", - "ValueSeriePrinterAndGnuPlotter", "ValuePrinterSaverAndGnuPlotter", - "ValueSeriePrinterSaverAndGnuPlotter". In the case of a definition as - "*Script*", the file must contain only the body of the function, as - described in the way of :ref:`section_advanced_observer`. + This command allows to set an *observer* on the current or final calculation + variable. Reference should be made to the description of the way of + ':ref:`section_advanced_observer`, and to the :ref:`section_reference` to + know what are the observable quantities. One defines as "*String*" the + *observer* body, using a string including if necessary line breaks. It is + recommended to use the patterns available by the argument "*Template*". + There exist the following simple patterns: "ValuePrinter", + "ValueSeriePrinter", "ValueSaver", "ValueSerieSaver", + "ValuePrinterAndSaver", "ValueSeriePrinterAndSaver", "ValueGnuPlotter", + "ValueSerieGnuPlotter", "ValuePrinterAndGnuPlotter", + "ValueSeriePrinterAndGnuPlotter", "ValuePrinterSaverAndGnuPlotter", + "ValueSeriePrinterSaverAndGnuPlotter", "ValueMean", "ValueStandardError", + "ValueVariance", "ValueRMS". In the case of a definition as "*Script*", the + file must contain only the body of the function, as described in the way of + :ref:`section_advanced_observer`. Perform the calculation +++++++++++++++++++++++ diff --git a/doc/fr/glossary.rst b/doc/fr/glossary.rst index d10ee19..6abd30c 100644 --- a/doc/fr/glossary.rst +++ b/doc/fr/glossary.rst @@ -51,6 +51,18 @@ Glossaire Mot-clé indiquant la matrice de covariance des erreurs *a posteriori* d'analyse. + APosterioriCorrelations + Mot-clé indiquant la matrice de corrélation des erreurs *a posteriori* + d'analyse. + + APosterioriVariances + Mot-clé indiquant la matrice diagonale des variances des erreurs *a + posteriori* d'analyse. + + APosterioriStandardDeviations + Mot-clé indiquant la matrice diagonale des écarts-types des erreurs *a + posteriori* d'analyse. + BMA (Background minus Analysis) Différence entre l'état d'ébauche et l'état optimal estimé, notée :math:`\mathbf{x}^b - \mathbf{x}^a`. @@ -110,3 +122,7 @@ Glossaire CostFunctionJb Mot-clé indiquant la partie due à l'ébauche dans la fonction de minimisation, notée :math:`J^b`. + + CurrentState + Mot-clé indiquant l'état courant utilisé au cours du déroulement d'un + algorithme d'optimisation. diff --git a/doc/fr/ref_algorithm_3DVAR.rst b/doc/fr/ref_algorithm_3DVAR.rst index d1b550c..4bac5e4 100644 --- a/doc/fr/ref_algorithm_3DVAR.rst +++ b/doc/fr/ref_algorithm_3DVAR.rst @@ -317,6 +317,12 @@ Les sorties conditionnelles de l'algorithme sont les suivantes: Exemple : ``d = ADD.get("Innovation")[-1]`` + InnovationAtCurrentState + *Liste de vecteurs*. Chaque élément est un vecteur d'innovation à l'état + courant. + + Exemple : ``ds = ADD.get("InnovationAtCurrentState")[-1]`` + MahalanobisConsistency *Liste de valeurs*. Chaque élément est une valeur de l'indicateur de qualité de Mahalanobis. diff --git a/doc/fr/ref_output_variables.rst b/doc/fr/ref_output_variables.rst index 656c29d..fcafacb 100644 --- a/doc/fr/ref_output_variables.rst +++ b/doc/fr/ref_output_variables.rst @@ -298,6 +298,12 @@ alphab Exemple : ``d = ADD.get("Innovation")[-1]`` + InnovationAtCurrentState + *Liste de vecteurs*. Chaque élément est un vecteur d'innovation à l'état + courant. + + Exemple : ``ds = ADD.get("InnovationAtCurrentState")[-1]`` + MahalanobisConsistency *Liste de valeurs*. Chaque élément est une valeur de l'indicateur de qualité de Mahalanobis. diff --git a/doc/fr/tui.rst b/doc/fr/tui.rst index fc37268..6abe87d 100644 --- a/doc/fr/tui.rst +++ b/doc/fr/tui.rst @@ -486,9 +486,10 @@ Param "ValueSerieSaver", "ValuePrinterAndSaver", "ValueSeriePrinterAndSaver", "ValueGnuPlotter", "ValueSerieGnuPlotter", "ValuePrinterAndGnuPlotter", "ValueSeriePrinterAndGnuPlotter", "ValuePrinterSaverAndGnuPlotter", - "ValueSeriePrinterSaverAndGnuPlotter". Dans le cas d'une définition par - "*Script*", le fichier indiqué doit contenir uniquement le corps de la - fonction, comme décrit dans la manière d':ref:`section_advanced_observer`. + "ValueSeriePrinterSaverAndGnuPlotter", "ValueMean", "ValueStandardError", + "ValueVariance", "ValueRMS". Dans le cas d'une définition par "*Script*", le + fichier indiqué doit contenir uniquement le corps de la fonction, comme + décrit dans la manière d':ref:`section_advanced_observer`. Effectuer le calcul +++++++++++++++++++ diff --git a/src/daComposant/daCore/PlatformInfo.py b/src/daComposant/daCore/PlatformInfo.py index 4d2124c..d6cc771 100644 --- a/src/daComposant/daCore/PlatformInfo.py +++ b/src/daComposant/daCore/PlatformInfo.py @@ -62,22 +62,22 @@ class PlatformInfo: return version.date def getPythonVersion(self): - "Retourne la version de python utilisée" + "Retourne la version de python disponible" import sys return ".".join(map(str,sys.version_info[0:3])) def getNumpyVersion(self): - "Retourne la version de numpy utilisée" + "Retourne la version de numpy disponible" import numpy.version return numpy.version.version def getScipyVersion(self): - "Retourne la version de scipy utilisée" + "Retourne la version de scipy disponible" import scipy.version return scipy.version.version def getMatplotlibVersion(self): - "Retourne la version de matplotlib utilisée" + "Retourne la version de matplotlib disponible" try: import matplotlib return matplotlib.__version__ @@ -85,13 +85,21 @@ class PlatformInfo: return "0.0.0" def getGnuplotVersion(self): - "Retourne la version de gnuplotpy utilisée" + "Retourne la version de gnuplotpy disponible" try: import Gnuplot return Gnuplot.__version__ except: return "0.0" + def getSphinxVersion(self): + "Retourne la version de sphinx disponible" + try: + import sphinx + return sphinx.__version__ + except: + return "0.0.0" + def getCurrentMemorySize(self): "Retourne la taille mémoire courante utilisée" return 1 diff --git a/src/daSalome/adaoBuilder.py b/src/daSalome/adaoBuilder.py index 9a24547..dd4699e 100644 --- a/src/daSalome/adaoBuilder.py +++ b/src/daSalome/adaoBuilder.py @@ -522,6 +522,14 @@ class New(object): __FunctionText = """print info, var[-1]\nimport numpy, re\nv=numpy.array(var[-1], ndmin=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)\nimport 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( v, with_='lines lw 2' ) )""" if Template == "ValueSeriePrinterSaverAndGnuPlotter": __FunctionText = """print info, var[:] \nimport numpy, re\nv=numpy.array(var[:], ndmin=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)\nimport 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( v, with_='lines lw 2' ) )""" + if Template == "ValueMean": + __FunctionText = """import numpy\nprint info, numpy.nanmean(var[-1])""" + if Template == "ValueStandardError": + __FunctionText = """import numpy\nprint info, numpy.nanstd(var[-1])""" + if Template == "ValueVariance": + __FunctionText = """import numpy\nprint info, numpy.nanvar(var[-1])""" + if Template == "ValueRMS": + __FunctionText = """import numpy\nv = numpy.matrix( numpy.ravel( var[-1] ) )\nprint info, float( numpy.sqrt((1./v.size)*(v*v.T)) )""" elif Script is not None: __FunctionText = _ImportFromScript(Script).getstring() else: -- 2.39.2