From: Jean-Philippe ARGAUD Date: Wed, 23 Sep 2015 19:30:28 +0000 (+0200) Subject: Observer common settings for catalog and documentation X-Git-Tag: V7_7_0rc1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c006db6ee4b6d09333bd7059fac33c42c147a2f1;p=modules%2Fadao.git Observer common settings for catalog and documentation --- diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index 09a11a8..d76ff7a 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -205,64 +205,28 @@ observers_choice = """ ), ),""" +from daCore.Templates import ObserverTemplates +observers_list = ObserverTemplates.keys_in_presentation_order() +observers_list = '"%s"'%str('", "'.join(observers_list)) +observers_cont = "" +for k in ObserverTemplates.keys_in_presentation_order(): + observers_cont += """ %s = BLOC (condition = " Template == '%s' ",\n"""%(k,k) + observers_cont += """ ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "%s", fr="%s", ang="%s" ),\n"""%( + ObserverTemplates[k].replace("\n","\\n").replace('"','\\"'), + ObserverTemplates.getdoc(k, "fr_FR"), + ObserverTemplates.getdoc(k, "en_EN"), + ) + observers_cont += """ ),\n""" 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", "ValueMean", "ValueStandardError", "ValueVariance", "ValueRMS")), - 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], 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)" ), - ), - ValueSerieSaver = BLOC (condition = " Template == 'ValueSerieSaver' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import 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)" ), - ), - ValuePrinterAndSaver = BLOC (condition = " Template == 'ValuePrinterAndSaver' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy, re\\nv=numpy.array(var[-1], ndmin=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[:], ndmin=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)" ), - ), - ValueGnuPlotter = BLOC (condition = " Template == 'ValueGnuPlotter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy, Gnuplot\\nv=numpy.array(var[-1], ndmin=1)\\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' ) )" ), - ), - ValueSerieGnuPlotter = BLOC (condition = " Template == 'ValueSerieGnuPlotter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy, Gnuplot\\nv=numpy.array(var[:], ndmin=1)\\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' ) )" ), - ), - ValuePrinterAndGnuPlotter = BLOC (condition = " Template == 'ValuePrinterAndGnuPlotter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info, var[-1]\\nimport numpy, Gnuplot\\nv=numpy.array(var[-1], ndmin=1)\\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' ) )" ), - ), - ValueSeriePrinterAndGnuPlotter = BLOC (condition = " Template == 'ValueSeriePrinterAndGnuPlotter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info, var[:] \\nimport numpy, Gnuplot\\nv=numpy.array(var[:], ndmin=1)\\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' ) )" ), - ), - ValuePrinterSaverAndGnuPlotter = BLOC (condition = " Template == 'ValuePrinterSaverAndGnuPlotter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "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' ) )" ), - ), - 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' ) )" ), - ), - ValueMean = BLOC (condition = " Template == 'ValueMean' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanmean(var[-1])" ), - ), - ValueStandardError = BLOC (condition = " Template == 'ValueStandardError' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanstd(var[-1])" ), - ), - ValueVariance = BLOC (condition = " Template == 'ValueVariance' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "import numpy\\nprint info, numpy.nanvar(var[-1])" ), - ), - ValueRMS = 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)) )" ), - ), - ) + Template = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "ValuePrinter", into=(%s)), +%s ) def F_Observers(statut) : return FACT( statut=statut, SELECTION = SIMP(statut="o", defaut=[], typ="TXM", min=0, max="**", validators=NoRepeat(), into=(${choices})),${decl_choices} ) -""" +"""%(observers_list,observers_cont) algo_choices = """ def AlgorithmParametersInNS(filename): diff --git a/doc/en/ref_observers_requirements.rst b/doc/en/ref_observers_requirements.rst index db8890a..bd4b223 100644 --- a/doc/en/ref_observers_requirements.rst +++ b/doc/en/ref_observers_requirements.rst @@ -81,73 +81,69 @@ Hereinafter we give the identifier and the contents of each model available. Inventory of available *observer* models ("*Template*") +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. index:: single: ValueGnuPlotter (Observer) +.. index:: single: ValuePrinter (Observer) -Template **ValueGnuPlotter** : -.............................. +Template **ValuePrinter** : +........................... -Graphically plot with Gnuplot the current value of the variable. +Print on standard output the current value of the variable. :: - import numpy, Gnuplot - v=numpy.array(var[-1], ndmin=1) - global ifig, gp - try: - ifig += 1 - gp('set style data lines') - except: - ifig = 0 - gp = Gnuplot.Gnuplot(persist=1) - gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) - gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) + print info, var[-1] -.. index:: single: ValueMean (Observer) +.. index:: single: ValueSeriePrinter (Observer) -Template **ValueMean** : -........................ +Template **ValueSeriePrinter** : +................................ -Print on standard output the mean of the current value of the variable. +Print on standard output the value serie of the variable. :: - import numpy - print info, numpy.nanmean(var[-1]) + print info, var[:] -.. index:: single: ValuePrinter (Observer) +.. index:: single: ValueSaver (Observer) -Template **ValuePrinter** : -........................... +Template **ValueSaver** : +......................... -Print on standard output the current value of the variable. +Save the current value of the variable in a file of the '/tmp' directory named 'value...txt' from the variable name and the saving step. :: - print info, var[-1] + import numpy, re + v=numpy.array(var[-1], ndmin=1) + global istep + try: + istep += 1 + except: + istep = 0 + f='/tmp/value_%s_%05i.txt'%(info,istep) + f=re.sub('\s','_',f) + print 'Value saved in "%s"'%f + numpy.savetxt(f,v) -.. index:: single: ValuePrinterAndGnuPlotter (Observer) +.. index:: single: ValueSerieSaver (Observer) -Template **ValuePrinterAndGnuPlotter** : -........................................ +Template **ValueSerieSaver** : +.............................. -Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable. +Save the value serie of the variable in a file of the '/tmp' directory named 'value...txt' from the variable name and the saving step. :: - print info, var[-1] - import numpy, Gnuplot - v=numpy.array(var[-1], ndmin=1) - global ifig,gp + import numpy, re + v=numpy.array(var[:], ndmin=1) + global istep try: - ifig += 1 - gp('set style data lines') + istep += 1 except: - ifig = 0 - gp = Gnuplot.Gnuplot(persist=1) - gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) - gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) + istep = 0 + f='/tmp/value_%s_%05i.txt'%(info,istep) + f=re.sub('\s','_',f) + print 'Value saved in "%s"'%f + numpy.savetxt(f,v) .. index:: single: ValuePrinterAndSaver (Observer) @@ -171,18 +167,18 @@ Print on standard output and, in the same time, save in a file the current value print 'Value saved in "%s"'%f numpy.savetxt(f,v) -.. index:: single: ValuePrinterSaverAndGnuPlotter (Observer) +.. index:: single: ValueSeriePrinterAndSaver (Observer) -Template **ValuePrinterSaverAndGnuPlotter** : -............................................. +Template **ValueSeriePrinterAndSaver** : +........................................ -Print on standard output and, in the same, time save in a file and graphically plot the current value of the variable. +Print on standard output and, in the same time, save in a file the value serie of the variable. :: - print info, var[-1] import numpy, re - v=numpy.array(var[-1], ndmin=1) + v=numpy.array(var[:], ndmin=1) + print info,v global istep try: istep += 1 @@ -192,51 +188,28 @@ Print on standard output and, in the same, time save in a file and graphically p f=re.sub('\s','_',f) print 'Value saved in "%s"'%f numpy.savetxt(f,v) - import Gnuplot - global ifig,gp - try: - ifig += 1 - gp('set style data lines') - except: - ifig = 0 - gp = Gnuplot.Gnuplot(persist=1) - gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) - gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) - -.. index:: single: ValueRMS (Observer) - -Template **ValueRMS** : -....................... - -Print on standard output the root mean square (RMS), or quadratic mean, of the current value of the variable. -:: - - import numpy - v = numpy.matrix( numpy.ravel( var[-1] ) ) - print info, float( numpy.sqrt((1./v.size)*(v*v.T)) ) - -.. index:: single: ValueSaver (Observer) +.. index:: single: ValueGnuPlotter (Observer) -Template **ValueSaver** : -......................... +Template **ValueGnuPlotter** : +.............................. -Save the current value of the variable in a file of the '/tmp' directory named 'value...txt' from the variable name and the saving step. +Graphically plot with Gnuplot the current value of the variable. :: - import numpy, re + import numpy, Gnuplot v=numpy.array(var[-1], ndmin=1) - global istep + global ifig, gp try: - istep += 1 + ifig += 1 + gp('set style data lines') except: - istep = 0 - f='/tmp/value_%s_%05i.txt'%(info,istep) - f=re.sub('\s','_',f) - print 'Value saved in "%s"'%f - numpy.savetxt(f,v) + ifig = 0 + gp = Gnuplot.Gnuplot(persist=1) + gp('set style data lines') + gp('set title "%s (Figure %i)"'%(info,ifig)) + gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSerieGnuPlotter (Observer) @@ -260,16 +233,28 @@ Graphically plot with Gnuplot the value serie of the variable. gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) -.. index:: single: ValueSeriePrinter (Observer) +.. index:: single: ValuePrinterAndGnuPlotter (Observer) -Template **ValueSeriePrinter** : -................................ +Template **ValuePrinterAndGnuPlotter** : +........................................ -Print on standard output the value serie of the variable. +Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable. :: - print info, var[:] + print info, var[-1] + import numpy, Gnuplot + v=numpy.array(var[-1], ndmin=1) + global ifig,gp + try: + ifig += 1 + gp('set style data lines') + except: + ifig = 0 + gp = Gnuplot.Gnuplot(persist=1) + gp('set style data lines') + gp('set title "%s (Figure %i)"'%(info,ifig)) + gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSeriePrinterAndGnuPlotter (Observer) @@ -294,18 +279,18 @@ Print on standard output and, in the same time, graphically plot with Gnuplot th gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) -.. index:: single: ValueSeriePrinterAndSaver (Observer) +.. index:: single: ValuePrinterSaverAndGnuPlotter (Observer) -Template **ValueSeriePrinterAndSaver** : -........................................ +Template **ValuePrinterSaverAndGnuPlotter** : +............................................. -Print on standard output and, in the same time, save in a file the value serie of the variable. +Print on standard output and, in the same, time save in a file and graphically plot the current value of the variable. :: + print info, var[-1] import numpy, re - v=numpy.array(var[:], ndmin=1) - print info,v + v=numpy.array(var[-1], ndmin=1) global istep try: istep += 1 @@ -315,6 +300,17 @@ Print on standard output and, in the same time, save in a file the value serie o f=re.sub('\s','_',f) print 'Value saved in "%s"'%f numpy.savetxt(f,v) + import Gnuplot + global ifig,gp + try: + ifig += 1 + gp('set style data lines') + except: + ifig = 0 + gp = Gnuplot.Gnuplot(persist=1) + gp('set style data lines') + gp('set title "%s (Figure %i)"'%(info,ifig)) + gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSeriePrinterSaverAndGnuPlotter (Observer) @@ -349,26 +345,17 @@ Print on standard output and, in the same, time save in a file and graphically p gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) -.. index:: single: ValueSerieSaver (Observer) +.. index:: single: ValueMean (Observer) -Template **ValueSerieSaver** : -.............................. +Template **ValueMean** : +........................ -Save the value serie of the variable in a file of the '/tmp' directory named 'value...txt' from the variable name and the saving step. +Print on standard output the mean of the current value of the variable. :: - import numpy, re - v=numpy.array(var[:], ndmin=1) - global istep - try: - istep += 1 - except: - istep = 0 - f='/tmp/value_%s_%05i.txt'%(info,istep) - f=re.sub('\s','_',f) - print 'Value saved in "%s"'%f - numpy.savetxt(f,v) + import numpy + print info, numpy.nanmean(var[-1]) .. index:: single: ValueStandardError (Observer) @@ -393,3 +380,16 @@ Print on standard output the variance of the current value of the variable. import numpy print info, numpy.nanvar(var[-1]) + +.. index:: single: ValueRMS (Observer) + +Template **ValueRMS** : +....................... + +Print on standard output the root mean square (RMS), or quadratic mean, of the current value of the variable. + +:: + + import numpy + v = numpy.matrix( numpy.ravel( var[-1] ) ) + print info, float( numpy.sqrt((1./v.size)*(v*v.T)) ) diff --git a/doc/fr/ref_observers_requirements.rst b/doc/fr/ref_observers_requirements.rst index d43678f..adfc3be 100644 --- a/doc/fr/ref_observers_requirements.rst +++ b/doc/fr/ref_observers_requirements.rst @@ -84,73 +84,69 @@ On donne ci-apr Inventaire des modèles d'*observer* disponibles ("*Template*") ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -.. index:: single: ValueGnuPlotter (Observer) +.. index:: single: ValuePrinter (Observer) -Modèle **ValueGnuPlotter** : -............................ +Modèle **ValuePrinter** : +......................... -Affiche graphiquement avec Gnuplot la valeur courante de la variable. +Imprime sur la sortie standard la valeur courante de la variable. :: - import numpy, Gnuplot - v=numpy.array(var[-1], ndmin=1) - global ifig, gp - try: - ifig += 1 - gp('set style data lines') - except: - ifig = 0 - gp = Gnuplot.Gnuplot(persist=1) - gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) - gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) + print info, var[-1] -.. index:: single: ValueMean (Observer) +.. index:: single: ValueSeriePrinter (Observer) -Modèle **ValueMean** : -...................... +Modèle **ValueSeriePrinter** : +.............................. -Imprime sur la sortie standard la moyenne de la valeur courante de la variable. +Imprime sur la sortie standard la série des valeurs de la variable. :: - import numpy - print info, numpy.nanmean(var[-1]) + print info, var[:] -.. index:: single: ValuePrinter (Observer) +.. index:: single: ValueSaver (Observer) -Modèle **ValuePrinter** : -......................... +Modèle **ValueSaver** : +....................... -Imprime sur la sortie standard la valeur courante de la variable. +Enregistre la valeur courante de la variable dans un fichier du répertoire '/tmp' nommé 'value...txt' selon le nom de la variable et l'étape d'enregistrement. :: - print info, var[-1] + import numpy, re + v=numpy.array(var[-1], ndmin=1) + global istep + try: + istep += 1 + except: + istep = 0 + f='/tmp/value_%s_%05i.txt'%(info,istep) + f=re.sub('\s','_',f) + print 'Value saved in "%s"'%f + numpy.savetxt(f,v) -.. index:: single: ValuePrinterAndGnuPlotter (Observer) +.. index:: single: ValueSerieSaver (Observer) -Modèle **ValuePrinterAndGnuPlotter** : -...................................... +Modèle **ValueSerieSaver** : +............................ -Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable. +Enregistre la série des valeurs de la variable dans un fichier du répertoire '/tmp' nommé 'value...txt' selon le nom de la variable et l'étape. :: - print info, var[-1] - import numpy, Gnuplot - v=numpy.array(var[-1], ndmin=1) - global ifig,gp + import numpy, re + v=numpy.array(var[:], ndmin=1) + global istep try: - ifig += 1 - gp('set style data lines') + istep += 1 except: - ifig = 0 - gp = Gnuplot.Gnuplot(persist=1) - gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) - gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) + istep = 0 + f='/tmp/value_%s_%05i.txt'%(info,istep) + f=re.sub('\s','_',f) + print 'Value saved in "%s"'%f + numpy.savetxt(f,v) .. index:: single: ValuePrinterAndSaver (Observer) @@ -174,18 +170,18 @@ Imprime sur la sortie standard et, en m print 'Value saved in "%s"'%f numpy.savetxt(f,v) -.. index:: single: ValuePrinterSaverAndGnuPlotter (Observer) +.. index:: single: ValueSeriePrinterAndSaver (Observer) -Modèle **ValuePrinterSaverAndGnuPlotter** : -........................................... +Modèle **ValueSeriePrinterAndSaver** : +...................................... -Imprime sur la sortie standard et, en même temps, enregistre dans un fichier et affiche graphiquement la valeur courante de la variable . +Imprime sur la sortie standard et, en même temps, enregistre dans un fichier la série des valeurs de la variable. :: - print info, var[-1] import numpy, re - v=numpy.array(var[-1], ndmin=1) + v=numpy.array(var[:], ndmin=1) + print info,v global istep try: istep += 1 @@ -195,51 +191,28 @@ Imprime sur la sortie standard et, en m f=re.sub('\s','_',f) print 'Value saved in "%s"'%f numpy.savetxt(f,v) - import Gnuplot - global ifig,gp - try: - ifig += 1 - gp('set style data lines') - except: - ifig = 0 - gp = Gnuplot.Gnuplot(persist=1) - gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) - gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) - -.. index:: single: ValueRMS (Observer) - -Modèle **ValueRMS** : -..................... - -Imprime sur la sortie standard la racine de la moyenne des carrés (RMS), ou moyenne quadratique, de la valeur courante de la variable. -:: - - import numpy - v = numpy.matrix( numpy.ravel( var[-1] ) ) - print info, float( numpy.sqrt((1./v.size)*(v*v.T)) ) - -.. index:: single: ValueSaver (Observer) +.. index:: single: ValueGnuPlotter (Observer) -Modèle **ValueSaver** : -....................... +Modèle **ValueGnuPlotter** : +............................ -Enregistre la valeur courante de la variable dans un fichier du répertoire '/tmp' nommé 'value...txt' selon le nom de la variable et l'étape d'enregistrement. +Affiche graphiquement avec Gnuplot la valeur courante de la variable. :: - import numpy, re + import numpy, Gnuplot v=numpy.array(var[-1], ndmin=1) - global istep + global ifig, gp try: - istep += 1 + ifig += 1 + gp('set style data lines') except: - istep = 0 - f='/tmp/value_%s_%05i.txt'%(info,istep) - f=re.sub('\s','_',f) - print 'Value saved in "%s"'%f - numpy.savetxt(f,v) + ifig = 0 + gp = Gnuplot.Gnuplot(persist=1) + gp('set style data lines') + gp('set title "%s (Figure %i)"'%(info,ifig)) + gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSerieGnuPlotter (Observer) @@ -263,16 +236,28 @@ Affiche graphiquement avec Gnuplot la s gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) -.. index:: single: ValueSeriePrinter (Observer) +.. index:: single: ValuePrinterAndGnuPlotter (Observer) -Modèle **ValueSeriePrinter** : -.............................. +Modèle **ValuePrinterAndGnuPlotter** : +...................................... -Imprime sur la sortie standard la série des valeurs de la variable. +Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable. :: - print info, var[:] + print info, var[-1] + import numpy, Gnuplot + v=numpy.array(var[-1], ndmin=1) + global ifig,gp + try: + ifig += 1 + gp('set style data lines') + except: + ifig = 0 + gp = Gnuplot.Gnuplot(persist=1) + gp('set style data lines') + gp('set title "%s (Figure %i)"'%(info,ifig)) + gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSeriePrinterAndGnuPlotter (Observer) @@ -297,18 +282,18 @@ Imprime sur la sortie standard et, en m gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) -.. index:: single: ValueSeriePrinterAndSaver (Observer) +.. index:: single: ValuePrinterSaverAndGnuPlotter (Observer) -Modèle **ValueSeriePrinterAndSaver** : -...................................... +Modèle **ValuePrinterSaverAndGnuPlotter** : +........................................... -Imprime sur la sortie standard et, en même temps, enregistre dans un fichier la série des valeurs de la variable. +Imprime sur la sortie standard et, en même temps, enregistre dans un fichier et affiche graphiquement la valeur courante de la variable . :: + print info, var[-1] import numpy, re - v=numpy.array(var[:], ndmin=1) - print info,v + v=numpy.array(var[-1], ndmin=1) global istep try: istep += 1 @@ -318,6 +303,17 @@ Imprime sur la sortie standard et, en m f=re.sub('\s','_',f) print 'Value saved in "%s"'%f numpy.savetxt(f,v) + import Gnuplot + global ifig,gp + try: + ifig += 1 + gp('set style data lines') + except: + ifig = 0 + gp = Gnuplot.Gnuplot(persist=1) + gp('set style data lines') + gp('set title "%s (Figure %i)"'%(info,ifig)) + gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSeriePrinterSaverAndGnuPlotter (Observer) @@ -352,26 +348,17 @@ Imprime sur la sortie standard et, en m gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) -.. index:: single: ValueSerieSaver (Observer) +.. index:: single: ValueMean (Observer) -Modèle **ValueSerieSaver** : -............................ +Modèle **ValueMean** : +...................... -Enregistre la série des valeurs de la variable dans un fichier du répertoire '/tmp' nommé 'value...txt' selon le nom de la variable et l'étape. +Imprime sur la sortie standard la moyenne de la valeur courante de la variable. :: - import numpy, re - v=numpy.array(var[:], ndmin=1) - global istep - try: - istep += 1 - except: - istep = 0 - f='/tmp/value_%s_%05i.txt'%(info,istep) - f=re.sub('\s','_',f) - print 'Value saved in "%s"'%f - numpy.savetxt(f,v) + import numpy + print info, numpy.nanmean(var[-1]) .. index:: single: ValueStandardError (Observer) @@ -396,3 +383,16 @@ Imprime sur la sortie standard la variance de la valeur courante de la variable. import numpy print info, numpy.nanvar(var[-1]) + +.. index:: single: ValueRMS (Observer) + +Modèle **ValueRMS** : +..................... + +Imprime sur la sortie standard la racine de la moyenne des carrés (RMS), ou moyenne quadratique, de la valeur courante de la variable. + +:: + + import numpy + v = numpy.matrix( numpy.ravel( var[-1] ) ) + print info, float( numpy.sqrt((1./v.size)*(v*v.T)) ) diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 25c49ec..57d4e41 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -772,40 +772,6 @@ class Covariance: def __len__(self): return self.shape[0] -# ============================================================================== -class TemplateStorage(object): - """ - Classe générale de stockage de type dictionnaire étendu - (Template) - """ - def __init__( self, language = "fr_FR" ): - self.__preferedLanguage = "fr" - self.__values = {} - - def store( self, name = None, content = None, fr_FR = "", en_EN = "" ): - if name is None or content is None: - raise ValueError("To be consistent, the storage of a template must provide a name and a content.") - self.__values[str(name)] = { - 'content': str(content), - 'fr_FR' : str(fr_FR), - 'en_EN' : str(en_EN), - } - - def keys(self): - __keys = self.__values.keys() - __keys.sort() - return __keys - - def __len__(self): - return len(self.__values) - - def __getitem__(self, name=None ): - return self.__values[name]['content'] - - def getdoc(self, name = None, lang = "fr_FR"): - if lang not in self.__values[name]: lang = "fr_FR" - return self.__values[name][lang] - # ============================================================================== def CostFunction3D( _x, diff --git a/src/daComposant/daCore/ExtendedLogging.py b/src/daComposant/daCore/ExtendedLogging.py index a7beee9..f83e659 100644 --- a/src/daComposant/daCore/ExtendedLogging.py +++ b/src/daComposant/daCore/ExtendedLogging.py @@ -76,7 +76,7 @@ __all__ = [] import os import sys import logging -from PlatformInfo import PlatformInfo +import PlatformInfo LOGFILE = os.path.join(os.path.abspath(os.curdir),"AssimilationStudy.log") @@ -95,7 +95,7 @@ class ExtendedLogging: # # Initialise l'affichage de logging # --------------------------------- - p = PlatformInfo() + p = PlatformInfo.PlatformInfo() # logging.info( "--------------------------------------------------" ) logging.info( "Lancement de "+p.getName()+" "+p.getVersion() ) diff --git a/src/daComposant/daCore/Templates.py b/src/daComposant/daCore/Templates.py new file mode 100644 index 0000000..aa84de7 --- /dev/null +++ b/src/daComposant/daCore/Templates.py @@ -0,0 +1,200 @@ +#-*-coding:iso-8859-1-*- +# +# Copyright (C) 2008-2015 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# 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. +# +# 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 +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D + +""" + Modèles généraux pour les observers, le post-processing +""" +__author__ = "Jean-Philippe ARGAUD" +__all__ = ["ObserverTemplates"] + +import numpy + +# ============================================================================== +class TemplateStorage(object): + """ + Classe générale de stockage de type dictionnaire étendu + (Template) + """ + def __init__( self, language = "fr_FR" ): + self.__preferedLanguage = language + self.__values = {} + self.__order = -1 + + def store( self, name = None, content = None, fr_FR = "", en_EN = "", order = "next" ): + if name is None or content is None: + raise ValueError("To be consistent, the storage of a template must provide a name and a content.") + if order == "next": + self.__order += 1 + else: + self.__order = int(order) + self.__values[str(name)] = { + 'content': str(content), + 'fr_FR' : str(fr_FR), + 'en_EN' : str(en_EN), + 'order' : int(self.__order), + } + + def keys(self): + __keys = self.__values.keys() + __keys.sort() + return __keys + + def has_key(self, name): + return self.__values.has_key(name) + + def __len__(self): + return len(self.__values) + + def __getitem__(self, name=None ): + return self.__values[name]['content'] + + def getdoc(self, name = None, lang = "fr_FR"): + if lang not in self.__values[name]: lang = self.__preferedLanguage + return self.__values[name][lang] + + def keys_in_presentation_order(self): + "Restitue l'ordre de présentation requis" + __orders = [] + for k in self.keys(): + __orders.append( self.__values[k]['order'] ) + __reorder = numpy.array(__orders).argsort() + return list(numpy.array(self.keys())[__reorder]) + +# ============================================================================== +ObserverTemplates = TemplateStorage() + +ObserverTemplates.store( + name = "ValuePrinter", + content = """print info, var[-1]""", + fr_FR = "Imprime sur la sortie standard la valeur courante de la variable", + en_EN = "Print on standard output the current value of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueSeriePrinter", + content = """print info, var[:]""", + fr_FR = "Imprime sur la sortie standard la série des valeurs de la variable", + en_EN = "Print on standard output the value serie of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueSaver", + content = """import 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)""", + fr_FR = "Enregistre la valeur courante de la variable dans un fichier du répertoire '/tmp' nommé 'value...txt' selon le nom de la variable et l'étape d'enregistrement", + en_EN = "Save the current value of the variable in a file of the '/tmp' directory named 'value...txt' from the variable name and the saving step", + order = "next", + ) +ObserverTemplates.store( + name = "ValueSerieSaver", + content = """import 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)""", + fr_FR = "Enregistre la série des valeurs de la variable dans un fichier du répertoire '/tmp' nommé 'value...txt' selon le nom de la variable et l'étape", + en_EN = "Save the value serie of the variable in a file of the '/tmp' directory named 'value...txt' from the variable name and the saving step", + order = "next", + ) +ObserverTemplates.store( + name = "ValuePrinterAndSaver", + content = """import numpy, re\nv=numpy.array(var[-1], ndmin=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)""", + fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier la valeur courante de la variable", + en_EN = "Print on standard output and, in the same time, save in a file the current value of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueSeriePrinterAndSaver", + content = """import numpy, re\nv=numpy.array(var[:], ndmin=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)""", + fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier la série des valeurs de la variable", + en_EN = "Print on standard output and, in the same time, save in a file the value serie of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueGnuPlotter", + content = """import numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\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' ) )""", + fr_FR = "Affiche graphiquement avec Gnuplot la valeur courante de la variable", + en_EN = "Graphically plot with Gnuplot the current value of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueSerieGnuPlotter", + content = """import numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\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' ) )""", + fr_FR = "Affiche graphiquement avec Gnuplot la série des valeurs de la variable", + en_EN = "Graphically plot with Gnuplot the value serie of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValuePrinterAndGnuPlotter", + content = """print info, var[-1]\nimport numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\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' ) )""", + fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable", + en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueSeriePrinterAndGnuPlotter", + content = """print info, var[:] \nimport numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\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' ) )""", + fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la série des valeurs de la variable", + en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the value serie of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValuePrinterSaverAndGnuPlotter", + content = """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' ) )""", + fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier et affiche graphiquement la valeur courante de la variable ", + en_EN = "Print on standard output and, in the same, time save in a file and graphically plot the current value of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueSeriePrinterSaverAndGnuPlotter", + content = """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' ) )""", + fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier et affiche graphiquement la série des valeurs de la variable", + en_EN = "Print on standard output and, in the same, time save in a file and graphically plot the value serie of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueMean", + content = """import numpy\nprint info, numpy.nanmean(var[-1])""", + fr_FR = "Imprime sur la sortie standard la moyenne de la valeur courante de la variable", + en_EN = "Print on standard output the mean of the current value of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueStandardError", + content = """import numpy\nprint info, numpy.nanstd(var[-1])""", + fr_FR = "Imprime sur la sortie standard l'écart-type de la valeur courante de la variable", + en_EN = "Print on standard output the standard error of the current value of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueVariance", + content = """import numpy\nprint info, numpy.nanvar(var[-1])""", + fr_FR = "Imprime sur la sortie standard la variance de la valeur courante de la variable", + en_EN = "Print on standard output the variance of the current value of the variable", + order = "next", + ) +ObserverTemplates.store( + name = "ValueRMS", + content = """import numpy\nv = numpy.matrix( numpy.ravel( var[-1] ) )\nprint info, float( numpy.sqrt((1./v.size)*(v*v.T)) )""", + fr_FR = "Imprime sur la sortie standard la racine de la moyenne des carrés (RMS), ou moyenne quadratique, de la valeur courante de la variable", + en_EN = "Print on standard output the root mean square (RMS), or quadratic mean, of the current value of the variable", + order = "next", + ) + +# ============================================================================== +if __name__ == "__main__": + print '\n AUTODIAGNOSTIC \n' diff --git a/src/daSalome/adaoBuilder.py b/src/daSalome/adaoBuilder.py index ffc48c7..8aa1bab 100644 --- a/src/daSalome/adaoBuilder.py +++ b/src/daSalome/adaoBuilder.py @@ -27,7 +27,7 @@ __author__ = "Jean-Philippe ARGAUD" __all__ = ["New"] import os -from daCore import AssimilationStudy +from daCore import AssimilationStudy, Templates # ============================================================================== class New(object): @@ -497,40 +497,8 @@ class New(object): # if String is not None: __FunctionText = String - elif Template is not None: - __FunctionText = "" - if Template == "ValuePrinter": - __FunctionText = """print info, var[-1]""" - if Template == "ValueSeriePrinter": - __FunctionText = """print info, var[:]""" - if Template == "ValueSaver": - __FunctionText = """import 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)""" - if Template == "ValueSerieSaver": - __FunctionText = """import 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)""" - if Template == "ValuePrinterAndSaver": - __FunctionText = """import numpy, re\nv=numpy.array(var[-1], ndmin=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)""" - if Template == "ValueSeriePrinterAndSaver": - __FunctionText = """import numpy, re\nv=numpy.array(var[:], ndmin=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)""" - if Template == "ValueGnuPlotter": - __FunctionText = """import numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\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 == "ValueSerieGnuPlotter": - __FunctionText = """import numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\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 == "ValuePrinterAndGnuPlotter": - __FunctionText = """print info, var[-1]\nimport numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\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 == "ValueSeriePrinterAndGnuPlotter": - __FunctionText = """print info, var[:] \nimport numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\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 == "ValuePrinterSaverAndGnuPlotter": - __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 (Template is not None) and Templates.ObserverTemplates.has_key(Template): + __FunctionText = Templates.ObserverTemplates[Template] elif Script is not None: __FunctionText = _ImportFromScript(Script).getstring() else: