# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
"""
- Définit des outils de persistence et d'enregistrement de séries de valeurs
+ Définit des outils de persistance et d'enregistrement de séries de valeurs
pour analyse ultérieure ou utilisation de calcul.
"""
__author__ = "Jean-Philippe ARGAUD"
__all__ = []
-import os, sys, numpy, copy
-import gzip, bz2
+import os, numpy, copy, math
+import gzip, bz2, pickle
from daCore.PlatformInfo import PathManagement ; PathManagement()
from daCore.PlatformInfo import has_gnuplot, PlatformInfo
if has_gnuplot:
import Gnuplot
-if sys.version_info.major < 3:
- range = xrange
- iLong = long
- import cPickle as pickle
-else:
- iLong = int
- import pickle
-
# ==============================================================================
class Persistence(object):
"""
- Classe générale de persistence définissant les accesseurs nécessaires
+ Classe générale de persistance définissant les accesseurs nécessaires
(Template)
"""
def __init__(self, name="", unit="", basetype=str):
def pop(self, item=None):
"""
- Retire une valeur enregistree par son index de stockage. Sans argument,
+ Retire une valeur enregistrée par son index de stockage. Sans argument,
retire le dernier objet enregistre.
"""
if item is not None:
return allKeys
# ---------------------------------------------------------
- # Pour compatibilite
+ # Pour compatibilité
def stepnumber(self):
"Nombre de pas"
return len(self.__values)
- # Pour compatibilite
+ # Pour compatibilité
def stepserie(self, **kwargs):
"Nombre de pas filtrés"
__indexOfFilteredItems = self.__filteredIndexes(**kwargs)
return __indexOfFilteredItems
- # Pour compatibilite
+ # Pour compatibilité
def steplist(self, **kwargs):
"Nombre de pas filtrés"
__indexOfFilteredItems = self.__filteredIndexes(**kwargs)
"""
try:
if numpy.version.version >= '1.1.0':
- return numpy.array(self.__values).std(ddof=ddof,axis=0).astype('float')
+ return numpy.asarray(self.__values).std(ddof=ddof,axis=0).astype('float')
else:
- return numpy.array(self.__values).std(axis=0).astype('float')
+ return numpy.asarray(self.__values).std(axis=0).astype('float')
except:
raise TypeError("Base type is incompatible with numpy")
les types élémentaires numpy.
"""
try:
- return numpy.array(self.__values).sum(axis=0)
+ return numpy.asarray(self.__values).sum(axis=0)
except:
raise TypeError("Base type is incompatible with numpy")
les types élémentaires numpy.
"""
try:
- return numpy.array(self.__values).min(axis=0)
+ return numpy.asarray(self.__values).min(axis=0)
except:
raise TypeError("Base type is incompatible with numpy")
les types élémentaires numpy.
"""
try:
- return numpy.array(self.__values).max(axis=0)
+ return numpy.asarray(self.__values).max(axis=0)
except:
raise TypeError("Base type is incompatible with numpy")
les types élémentaires numpy.
"""
try:
- return numpy.array(self.__values).cumsum(axis=0)
+ return numpy.asarray(self.__values).cumsum(axis=0)
except:
raise TypeError("Base type is incompatible with numpy")
elif isinstance(Scheduler,range): # Considéré comme un itérateur
Schedulers = Scheduler
elif isinstance(Scheduler,(list,tuple)): # Considéré comme des index explicites
- Schedulers = [iLong(i) for i in Scheduler] # map( long, Scheduler )
+ Schedulers = [int(i) for i in Scheduler] # map( long, Scheduler )
else: # Dans tous les autres cas, activé par défaut
Schedulers = range( 0, maxiter )
#
)
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)""",
+ 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)""",
+ 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 series 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(str(info)+" "+str(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)""",
+ content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nprint(str(info)+" "+str(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 du répertoire '/tmp', la valeur courante de la variable",
en_EN = "Print on standard output and, in the same time save in a file of the '/tmp' directory, the current value of the variable",
order = "next",
)
ObserverTemplates.store(
name = "ValueIndexPrinterAndSaver",
- content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nprint(str(info)+(" index %i:"%(len(var)-1))+" "+str(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)""",
+ content = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nprint(str(info)+(" index %i:"%(len(var)-1))+" "+str(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 du répertoire '/tmp', la valeur courante de la variable, en ajoutant son index",
en_EN = "Print on standard output and, in the same time save in a file of the '/tmp' directory, the current value of the variable, adding its index",
order = "next",
)
ObserverTemplates.store(
name = "ValueSeriePrinterAndSaver",
- content = """import numpy, re\nv=numpy.array(var[:], ndmin=1)\nprint(str(info)+" "+str(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)""",
+ content = """import numpy, re\nv=numpy.array(var[:], ndmin=1)\nprint(str(info)+" "+str(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 du répertoire '/tmp', la série des valeurs de la variable",
en_EN = "Print on standard output and, in the same time, save in a file of the '/tmp' directory, the value series 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' ) )""",
+ 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' ) )""",
+ 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 series of the variable",
order = "next",
)
ObserverTemplates.store(
name = "ValuePrinterAndGnuPlotter",
- content = """print(str(info)+" "+str(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' ) )""",
+ content = """print(str(info)+' '+str(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(str(info)+" "+str(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' ) )""",
+ content = """print(str(info)+' '+str(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 series of the variable",
order = "next",
)
ObserverTemplates.store(
name = "ValuePrinterSaverAndGnuPlotter",
- content = """print(str(info)+" "+str(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' ) )""",
+ content = """print(str(info)+' '+str(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 du répertoire '/tmp' et affiche graphiquement la valeur courante de la variable",
en_EN = "Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the current value of the variable",
order = "next",
)
ObserverTemplates.store(
name = "ValueSeriePrinterSaverAndGnuPlotter",
- content = """print(str(info)+" "+str(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' ) )""",
+ content = """print(str(info)+' '+str(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 du répertoire '/tmp' 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 of the '/tmp' directory and graphically plot the value series of the variable",
order = "next",
)
ObserverTemplates.store(
name = "ValueMean",
- content = """import numpy\nprint(str(info)+" "+str(numpy.nanmean(var[-1])))""",
+ content = """import numpy\nprint(str(info)+' '+str(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(str(info)+" "+str(numpy.nanstd(var[-1])))""",
+ content = """import numpy\nprint(str(info)+' '+str(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(str(info)+" "+str(numpy.nanvar(var[-1])))""",
+ content = """import numpy\nprint(str(info)+' '+str(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 = "ValueL2Norm",
- content = """import numpy\nv = numpy.ravel( var[-1] )\nprint(str(info)+" "+str(float( numpy.linalg.norm(v) )))""",
+ content = """import numpy\nv = numpy.ravel( var[-1] )\nprint(str(info)+' '+str(float( numpy.linalg.norm(v) )))""",
fr_FR = "Imprime sur la sortie standard la norme L2 de la valeur courante de la variable",
en_EN = "Print on standard output the L2 norm of the current value of the variable",
order = "next",
)
ObserverTemplates.store(
name = "ValueRMS",
- content = """import numpy\nv = numpy.ravel( var[-1] )\nprint(str(info)+" "+str(float( numpy.sqrt((1./v.size)*numpy.dot(v,v)) )))""",
+ content = """import numpy\nv = numpy.ravel( var[-1] )\nprint(str(info)+' '+str(float( numpy.sqrt((1./v.size)*numpy.dot(v,v)) )))""",
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",