1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2015 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 Modèles généraux pour les observers, le post-processing
26 __author__ = "Jean-Philippe ARGAUD"
27 __all__ = ["ObserverTemplates"]
31 # ==============================================================================
32 class TemplateStorage(object):
34 Classe générale de stockage de type dictionnaire étendu
37 def __init__( self, language = "fr_FR" ):
38 self.__preferedLanguage = language
42 def store( self, name = None, content = None, fr_FR = "", en_EN = "", order = "next" ):
43 if name is None or content is None:
44 raise ValueError("To be consistent, the storage of a template must provide a name and a content.")
48 self.__order = int(order)
49 self.__values[str(name)] = {
50 'content': str(content),
53 'order' : int(self.__order),
57 __keys = self.__values.keys()
61 def has_key(self, name):
62 return self.__values.has_key(name)
65 return len(self.__values)
67 def __getitem__(self, name=None ):
68 return self.__values[name]['content']
70 def getdoc(self, name = None, lang = "fr_FR"):
71 if lang not in self.__values[name]: lang = self.__preferedLanguage
72 return self.__values[name][lang]
74 def keys_in_presentation_order(self):
75 "Restitue l'ordre de présentation requis"
78 __orders.append( self.__values[k]['order'] )
79 __reorder = numpy.array(__orders).argsort()
80 return list(numpy.array(self.keys())[__reorder])
82 # ==============================================================================
83 ObserverTemplates = TemplateStorage()
85 ObserverTemplates.store(
86 name = "ValuePrinter",
87 content = """print info, var[-1]""",
88 fr_FR = "Imprime sur la sortie standard la valeur courante de la variable",
89 en_EN = "Print on standard output the current value of the variable",
92 ObserverTemplates.store(
93 name = "ValueSeriePrinter",
94 content = """print info, var[:]""",
95 fr_FR = "Imprime sur la sortie standard la série des valeurs de la variable",
96 en_EN = "Print on standard output the value serie of the variable",
99 ObserverTemplates.store(
101 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)""",
102 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",
103 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",
106 ObserverTemplates.store(
107 name = "ValueSerieSaver",
108 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)""",
109 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",
110 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",
113 ObserverTemplates.store(
114 name = "ValuePrinterAndSaver",
115 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)""",
116 fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier la valeur courante de la variable",
117 en_EN = "Print on standard output and, in the same time, save in a file the current value of the variable",
120 ObserverTemplates.store(
121 name = "ValueSeriePrinterAndSaver",
122 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)""",
123 fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier la série des valeurs de la variable",
124 en_EN = "Print on standard output and, in the same time, save in a file the value serie of the variable",
127 ObserverTemplates.store(
128 name = "ValueGnuPlotter",
129 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' ) )""",
130 fr_FR = "Affiche graphiquement avec Gnuplot la valeur courante de la variable",
131 en_EN = "Graphically plot with Gnuplot the current value of the variable",
134 ObserverTemplates.store(
135 name = "ValueSerieGnuPlotter",
136 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' ) )""",
137 fr_FR = "Affiche graphiquement avec Gnuplot la série des valeurs de la variable",
138 en_EN = "Graphically plot with Gnuplot the value serie of the variable",
141 ObserverTemplates.store(
142 name = "ValuePrinterAndGnuPlotter",
143 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' ) )""",
144 fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable",
145 en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable",
148 ObserverTemplates.store(
149 name = "ValueSeriePrinterAndGnuPlotter",
150 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' ) )""",
151 fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la série des valeurs de la variable",
152 en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the value serie of the variable",
155 ObserverTemplates.store(
156 name = "ValuePrinterSaverAndGnuPlotter",
157 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' ) )""",
158 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 ",
159 en_EN = "Print on standard output and, in the same, time save in a file and graphically plot the current value of the variable",
162 ObserverTemplates.store(
163 name = "ValueSeriePrinterSaverAndGnuPlotter",
164 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' ) )""",
165 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",
166 en_EN = "Print on standard output and, in the same, time save in a file and graphically plot the value serie of the variable",
169 ObserverTemplates.store(
171 content = """import numpy\nprint info, numpy.nanmean(var[-1])""",
172 fr_FR = "Imprime sur la sortie standard la moyenne de la valeur courante de la variable",
173 en_EN = "Print on standard output the mean of the current value of the variable",
176 ObserverTemplates.store(
177 name = "ValueStandardError",
178 content = """import numpy\nprint info, numpy.nanstd(var[-1])""",
179 fr_FR = "Imprime sur la sortie standard l'écart-type de la valeur courante de la variable",
180 en_EN = "Print on standard output the standard error of the current value of the variable",
183 ObserverTemplates.store(
184 name = "ValueVariance",
185 content = """import numpy\nprint info, numpy.nanvar(var[-1])""",
186 fr_FR = "Imprime sur la sortie standard la variance de la valeur courante de la variable",
187 en_EN = "Print on standard output the variance of the current value of the variable",
190 ObserverTemplates.store(
192 content = """import numpy\nv = numpy.matrix( numpy.ravel( var[-1] ) )\nprint info, float( numpy.sqrt((1./v.size)*(v*v.T)) )""",
193 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",
194 en_EN = "Print on standard output the root mean square (RMS), or quadratic mean, of the current value of the variable",
198 # ==============================================================================
199 if __name__ == "__main__":
200 print '\n AUTODIAGNOSTIC \n'