From b6b846b626ab1dfd55f7812f2751034a0bc93090 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Thu, 7 May 2015 16:52:47 +0200 Subject: [PATCH] Correction of observer --- bin/AdaoCatalogGenerator.py | 30 +++++++++++++++++++++--------- doc/fr/tui.rst | 15 ++++++++------- src/daSalome/adaoBuilder.py | 24 ++++++++++++++++-------- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index dd7842f..71ff94f 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -198,30 +198,42 @@ 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")), + 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")), ValuePrinter = BLOC (condition = " Template == 'ValuePrinter' ", - ValueTemplate = SIMP(statut = "o", typ = "TXM", min=1, max=1, defaut = "print info,var[-1]" ), + 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[:]" ), + 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)" ), + 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[:])) \\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)" ), + 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]))\\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)" ), + 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[:])) \\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)" ), + 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 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' ) )" ), + 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 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' ) )" ), + 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' ) )" ), ), ) diff --git a/doc/fr/tui.rst b/doc/fr/tui.rst index 746dbf6..2c2ec07 100644 --- a/doc/fr/tui.rst +++ b/doc/fr/tui.rst @@ -116,9 +116,10 @@ d'erreurs :math:`\mathbf{R}` (nomm case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) -On remarque que l'on peut donner en entrée des quantités vectorielles des objets -de type ``list``, ``tuple``, ``array`` ou ``matrix`` de Numpy. Dans ces deux -derniers cas, il faut simplement importer Numpy avant. +On remarque que l'on peut donner, en entrée des quantités vectorielles ou +matricielles, des objets de type ``str``, ``list`` ou``tuple`` de Python, ou de +type ``array`` ou ``matrix`` de Numpy. Dans ces deux derniers cas, il faut +simplement importer le module Numpy avant. On doit ensuite définir les opérateurs :math:`H` d'observation et éventuellement :math:`M` d'évolution. Dans tous les cas, linéaire ou non-linéaire, on peut les @@ -154,8 +155,8 @@ ci-dessus) et l'enregistre dans le cas ADAO:: Pour connaître les résultats intermédiaire ou finaux du calcul du cas, on peut ajouter des "*observer*", qui permettent d'associer l'exécution d'un script à -une variable interne ou finale du calcul. On se reportera à la description de la -manière d':ref:`section_advanced_observer`, et à la :ref:`section_reference` +une variable intermédiaire ou finale du calcul. On se reportera à la description +de la manière d':ref:`section_advanced_observer`, et à la :ref:`section_reference` pour savoir quelles sont les quantités observables. Cette association d'"*observer*" avec une quantité existante se fait de manière similaire à la définition des données du calcul:: @@ -171,8 +172,8 @@ simple dans l'environnement de l'interpr Au final, on obtient le script très compact proposé précédemment dans :ref:`subsection_tui_example`. -Fournir des données de calcul plus complexes -++++++++++++++++++++++++++++++++++++++++++++ +Fournir des données ou informations de calcul plus complexes +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Une telle interface s'écrivant en Python, il est possible d'utiliser toute la puissance du langage pour entrer des données plus complexes qu'une déclaration diff --git a/src/daSalome/adaoBuilder.py b/src/daSalome/adaoBuilder.py index 454595e..e3c7184 100644 --- a/src/daSalome/adaoBuilder.py +++ b/src/daSalome/adaoBuilder.py @@ -498,21 +498,29 @@ class New(object): __FunctionText = String elif Template is not None: if Template == "ValuePrinter": - __FunctionText = "print info,var[-1]" + __FunctionText = """print info, var[-1]""" if Template == "ValueSeriePrinter": - __FunctionText = "print info,var[:]" + __FunctionText = """print info, var[:]""" if Template == "ValueSaver": - __FunctionText = r"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)" + __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 = r"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)" + __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 = r"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)" + __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 = r"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)" + __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 = r"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' ) )" + __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 = r"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' ) )" + __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' ) )""" elif Script is not None: __FunctionText = _ImportFromScript(Script).getstring() else: -- 2.39.2