ValueTemplate=
"""import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa""",),);
-#VERSION_CATALOGUE:V8_3_0:FIN VERSION_CATALOGUE
\ No newline at end of file
+print('Analysis:',xa)""",),);
+#VERSION_CATALOGUE:V8_3_0:FIN VERSION_CATALOGUE
# -*- coding: utf-8 -*-
-study_config = {}
+study_config = {}
study_config['StudyType'] = 'ASSIMILATION_STUDY'
study_config['Name'] = 'Test'
study_config['Debug'] = '0'
Analysis_config['From'] = 'String'
Analysis_config['Data'] = """import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa"""
+print('Analysis:',xa)"""
study_config['UserPostAnalysis'] = Analysis_config
ValueTemplate=
"""import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa""",),);
+print('Analysis:',xa)""",),);
#VERSION_CATALOGUE:V8_3_0:FIN VERSION_CATALOGUE
# -*- coding: utf-8 -*-
-study_config = {}
+study_config = {}
study_config['StudyType'] = 'ASSIMILATION_STUDY'
study_config['Name'] = 'Test'
study_config['Debug'] = '0'
Analysis_config['From'] = 'String'
Analysis_config['Data'] = """import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa"""
+print('Analysis:',xa)"""
study_config['UserPostAnalysis'] = Analysis_config
ValueTemplate=
"""import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa""",),);
+print('Analysis:',xa)""",),);
#VERSION_CATALOGUE:V8_3_0:FIN VERSION_CATALOGUE
# -*- coding: utf-8 -*-
-study_config = {}
+study_config = {}
study_config['StudyType'] = 'ASSIMILATION_STUDY'
study_config['Name'] = 'Test'
study_config['Debug'] = '0'
Analysis_config['From'] = 'String'
Analysis_config['Data'] = """import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa"""
+print('Analysis:',xa)"""
study_config['UserPostAnalysis'] = Analysis_config
ValueTemplate=
"""import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa""",),);
+print('Analysis:',xa)""",),);
#VERSION_CATALOGUE:V8_3_0:FIN VERSION_CATALOGUE
# -*- coding: utf-8 -*-
-study_config = {}
+study_config = {}
study_config['StudyType'] = 'ASSIMILATION_STUDY'
study_config['Name'] = 'Test'
study_config['Debug'] = '0'
Analysis_config['From'] = 'String'
Analysis_config['Data'] = """import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa"""
+print('Analysis:',xa)"""
study_config['UserPostAnalysis'] = Analysis_config
Init_config = {}
Init_config['Type'] = 'Dict'
STRING=
"""import numpy
Xa = ADD.get("Analysis")[-1]
-print
-print "Size of Analysis = %i"%len(Xa)
-print "Min, mean, max = %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa))
-print
+print()
+print("Size of Analysis = %i"%len(Xa))
+print("Min, mean, max = %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa)))
+print()
""",),);
#VERSION_CATALOGUE:V8_3_0:FIN VERSION_CATALOGUE
# -*- coding: utf-8 -*-
-study_config = {}
+study_config = {}
study_config['StudyType'] = 'ASSIMILATION_STUDY'
study_config['Name'] = 'Test'
study_config['Debug'] = '0'
Analysis_config['From'] = 'String'
Analysis_config['Data'] = """import numpy
Xa = ADD.get("Analysis")[-1]
-print
-print "Size of Analysis = %i"%len(Xa)
-print "Min, mean, max = %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa))
-print
+print()
+print("Size of Analysis = %i"%len(Xa))
+print("Min, mean, max = %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa)))
+print()
"""
study_config['UserPostAnalysis'] = Analysis_config
"""import numpy
Xb = ADD.get("Background")
Xa = ADD.get("Analysis")[-1]
-print
-print "Size of Background...........= %i"%len(Xb.A1)
-print "Size of Analysis.............= %i"%len(Xa)
-print "Min, mean, max of Analysis...= %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa))
-print
+print()
+print("Size of Background...........= %i"%len(Xb.A1))
+print("Size of Analysis.............= %i"%len(Xa))
+print("Min, mean, max of Analysis...= %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa)))
+print()
""",),);
#VERSION_CATALOGUE:V8_3_0:FIN VERSION_CATALOGUE
Analysis_config['Data'] = """import numpy
Xb = ADD.get("Background")
Xa = ADD.get("Analysis")[-1]
-print
-print "Size of Background...........= %i"%len(Xb.A1)
-print "Size of Analysis.............= %i"%len(Xa)
-print "Min, mean, max of Analysis...= %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa))
-print
+print()
+print("Size of Background...........= %i"%len(Xb.A1))
+print("Size of Analysis.............= %i"%len(Xa))
+print("Min, mean, max of Analysis...= %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa)))
+print()
"""
study_config['UserPostAnalysis'] = Analysis_config
ValueTemplate=
"""import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa""",),
+print('Analysis:',xa)""",),
Observers=_F(SELECTION=('CurrentState','CostFunctionJ',),
CurrentState_data=_F(Info='CurrentState',
NodeType='Script',
CostFunctionJ_data=_F(Info='CostFunctionJ',
NodeType='String',
Value=
-"""print " ---> observerCost"
-print " var =",var[:]
-print " info =",info
+"""print(" ---> observerCost")
+print(" var =",var[:])
+print(" info =",info)
#
import Gnuplot
import os
gp('set title "'+str(info)+'"')
gp.plot( Gnuplot.Data( var[:] ) )
filename = os.path.join("/tmp", "imageCost_%02i.ps"%numero)
-print " imageCost %s"%filename
+print(" imageCost %s"%filename)
gp.hardcopy(filename=filename, color=1)
numero += 1
""",),),);
Analysis_config['From'] = 'String'
Analysis_config['Data'] = """import numpy
xa=numpy.ravel(ADD.get('Analysis')[-1])
-print 'Analysis:',xa"""
+print('Analysis:',xa)"""
study_config['UserPostAnalysis'] = Analysis_config
Init_config = {}
Init_config['Type'] = 'Dict'
observers["CostFunctionJ"] = {}
observers["CostFunctionJ"]["number"] = 3
observers["CostFunctionJ"]["nodetype"] = "String"
-observers["CostFunctionJ"]["String"] = """print " ---> observerCost"
-print " var =",var[:]
-print " info =",info
+observers["CostFunctionJ"]["String"] = """print(" ---> observerCost")
+print(" var =",var[:])
+print(" info =",info)
#
import Gnuplot
import os
gp('set title "'+str(info)+'"')
gp.plot( Gnuplot.Data( var[:] ) )
filename = os.path.join("/tmp", "imageCost_%02i.ps"%numero)
-print " imageCost %s"%filename
+print(" imageCost %s"%filename)
gp.hardcopy(filename=filename, color=1)
numero += 1
"""
return numpy.array( HX )
# ==============================================================================
-from daNumerics.ApproximatedDerivatives import FDApproximation
+from adao.daNumerics.ApproximatedDerivatives import FDApproximation
FDA = FDApproximation( DirectOperator )
TangentOperator = FDA.TangentOperator
AdjointOperator = FDA.AdjointOperator
<script><code>
<![CDATA[
-import numpy, logging
+import sys, numpy, logging
logging.debug("CREATE YI Entering in CreateAssimilationStudy")
print("Entering in the assimilation study")
print("Name is set to........:", Name)
try:
# Create Assimilation study
- import adao
+ if sys.version_info.major > 2:
+ import adao
from daYacsIntegration.daStudy import *
assim_study = daStudy(Name, Algorithm, Debug)
<inline name="ExtractDataNode">
<script><code><![CDATA[
-import logging
+import sys, logging
logging.debug("TERMINATE Entering in ExtractDataNode")
-try:
+if sys.version_info.major < 3:
import cPickle as pickle
-except:
+else:
import pickle
from daCore.AssimilationStudy import AssimilationStudy
var = None
import os
import sys
-import logging
-import copy
import numpy
import mimetypes
+import logging
+import copy
from daCore import Persistence
from daCore import PlatformInfo
from daCore import Templates
self._addLine("# -*- coding: utf-8 -*-")
self._addLine("#\n# Python script using ADAO TUI\n#")
self._addLine("from numpy import array, matrix")
- self._addLine("import adaoBuilder")
+ self._addLine("from adao import adaoBuilder")
self._addLine("%s = adaoBuilder.New('%s')"%(self._objname, self._name))
if self._content is not None:
for command in self._content:
self._addLine("Analysis_config['From'] = 'String'")
self._addLine("Analysis_config['Data'] = \"\"\"import numpy")
self._addLine("xa=numpy.ravel(ADD.get('Analysis')[-1])")
- self._addLine("print 'Analysis:',xa\"\"\"")
+ self._addLine("print('Analysis:',xa)\"\"\"")
self._addLine("study_config['UserPostAnalysis'] = Analysis_config")
def __loadVariablesByScript(self):
__ExecVariables = {} # Necessaire pour recuperer la variable
__author__ = "Jean-Philippe ARGAUD"
__all__ = []
-import sys, numpy, copy
+import os, sys, numpy, copy
+import gzip, bz2
from daCore.PlatformInfo import PathManagement ; PathManagement()
+from daCore.PlatformInfo import has_gnuplot
+if has_gnuplot:
+ import Gnuplot
if sys.version_info.major < 3:
range = xrange
self.__tags = []
#
self.__dynamic = False
- self.__gnuplot = None
self.__g = None
self.__title = None
self.__ltitle = None
"Préparation des plots"
#
# Vérification de la disponibilité du module Gnuplot
- try:
- import Gnuplot
- self.__gnuplot = Gnuplot
- except:
+ if not has_gnuplot:
raise ImportError("The Gnuplot module is required to plot the object.")
#
# Vérification et compléments sur les paramètres d'entrée
if persist:
- self.__gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -persist -geometry '+geometry
+ Gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -persist -geometry '+geometry
else:
- self.__gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -geometry '+geometry
+ Gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -geometry '+geometry
if ltitle is None:
ltitle = ""
- self.__g = self.__gnuplot.Gnuplot() # persist=1
- self.__g('set terminal '+self.__gnuplot.GnuplotOpts.default_term)
+ self.__g = Gnuplot.Gnuplot() # persist=1
+ self.__g('set terminal '+Gnuplot.GnuplotOpts.default_term)
self.__g('set style data lines')
self.__g('set grid')
self.__g('set autoscale')
attendant un Return
Par défaut, pause = True
"""
- import os
if not self.__dynamic:
self.__preplots(title, xlabel, ylabel, ltitle, geometry, persist, pause )
if dynamic:
else:
Steps = list(range(len(self.__values[index])))
#
- self.__g.plot( self.__gnuplot.Data( Steps, self.__values[index], title=ltitle ) )
+ self.__g.plot( Gnuplot.Data( Steps, self.__values[index], title=ltitle ) )
#
if filename != "":
i += 1
#
self.__g('set title "'+str(self.__title))
Steps = list(range(len(self.__values)))
- self.__g.plot( self.__gnuplot.Data( Steps, self.__values, title=self.__ltitle ) )
+ self.__g.plot( Gnuplot.Data( Steps, self.__values, title=self.__ltitle ) )
#
if self.__pause:
eval(input('Please press return to continue...\n'))
"""
#
# Vérification de la disponibilité du module Gnuplot
- try:
- import Gnuplot
- self.__gnuplot = Gnuplot
- except:
+ if not has_gnuplot:
raise ImportError("The Gnuplot module is required to plot the object.")
#
# Vérification et compléments sur les paramètres d'entrée
if persist:
- self.__gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -persist -geometry '+geometry
+ Gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -persist -geometry '+geometry
else:
- self.__gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -geometry '+geometry
+ Gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -geometry '+geometry
if ltitle is None:
ltitle = ""
if isinstance(steps,list) or isinstance(steps, numpy.ndarray):
Steps = list(steps)
else:
Steps = list(range(len(self.__values[0])))
- self.__g = self.__gnuplot.Gnuplot() # persist=1
- self.__g('set terminal '+self.__gnuplot.GnuplotOpts.default_term)
+ self.__g = Gnuplot.Gnuplot() # persist=1
+ self.__g('set terminal '+Gnuplot.GnuplotOpts.default_term)
self.__g('set style data lines')
self.__g('set grid')
self.__g('set autoscale')
#
# Tracé du ou des vecteurs demandés
indexes = list(range(len(self.__values)))
- self.__g.plot( self.__gnuplot.Data( Steps, self.__values[indexes.pop(0)], title=ltitle+" (pas 0)" ) )
+ self.__g.plot( Gnuplot.Data( Steps, self.__values[indexes.pop(0)], title=ltitle+" (pas 0)" ) )
for index in indexes:
- self.__g.replot( self.__gnuplot.Data( Steps, self.__values[index], title=ltitle+" (pas %i)"%index ) )
+ self.__g.replot( Gnuplot.Data( Steps, self.__values[index], title=ltitle+" (pas %i)"%index ) )
#
if filename != "":
self.__g.hardcopy(filename=filename, color=1)
Enregistre l'objet dans le fichier indiqué selon le "mode" demandé,
et renvoi le nom du fichier
"""
- import os
if filename is None:
if compress == "gzip":
filename = os.tempnam( os.getcwd(), 'dacp' ) + ".pkl.gz"
#
if mode == "pickle":
if compress == "gzip":
- import gzip
output = gzip.open( filename, 'wb')
elif compress == "bzip2":
- import bz2
output = bz2.BZ2File( filename, 'wb')
else:
output = open( filename, 'wb')
"""
Recharge un objet composite sauvé en fichier
"""
- import os
if filename is None:
raise ValueError("A file name if requested to load a composite.")
else:
#
if mode == "pickle":
if compress == "gzip":
- import gzip
pkl_file = gzip.open( filename, 'rb')
elif compress == "bzip2":
- import bz2
pkl_file = bz2.BZ2File( filename, 'rb')
else:
pkl_file = open(filename, 'rb')
le code et la plateforme sous forme de strings, ou d'afficher directement
les informations disponibles par les méthodes. L'impression directe d'un
objet de cette classe affiche les informations minimales. Par exemple :
- print PlatformInfo()
- print PlatformInfo().getVersion()
+ print(PlatformInfo())
+ print(PlatformInfo().getVersion())
created = PlatformInfo().getDate()
La classe "PathManagement" permet de mettre à jour les chemins système pour
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
from daCore.version import name, version, year, date
+from daYacsIntegration.daOptimizerLoop import *
Usage by an example:
from numpy import array, matrix
- import adaoBuilder
+ from adao import adaoBuilder
case = adaoBuilder.New()
case.set( 'AlgorithmParameters', Algorithm='3DVAR' )
case.set( 'Background', Vector=[0, 1, 2] )
ADAO_Case.edAddCFLink(CAS_node, compute_bloc)
# We use an optimizer loop
name = "Execute" + study_config["Algorithm"]
- algLib = "daYacsIntegration.py"
+ if sys.version_info.major < 3:
+ algLib = "daYacsIntegration.py"
+ else:
+ algLib = "adao.py"
factoryName = "AssimilationAlgorithm_asynch"
#~ optimizer_node = runtime.createOptimizerLoop(name, algLib, factoryName, "")
optimizer_node = runtime.createOptimizerLoop(name, algLib, factoryName, True)
node_script += """ DirectOperator\n"""
node_script += """except NameError:\n"""
node_script += """ raise ValueError("ComputationFunctionNode: DirectOperator not found in the imported user script file")\n"""
- node_script += """from daNumerics import ApproximatedDerivatives\n"""
+ if sys.version_info.major < 3:
+ node_script += """from daNumerics import ApproximatedDerivatives\n"""
+ else:
+ node_script += """from adao.daNumerics import ApproximatedDerivatives\n"""
node_script += """FDA = ApproximatedDerivatives.FDApproximation(\n"""
node_script += """ Function = DirectOperator,\n"""
node_script += """ increment = %s,\n"""%str(ScriptWithOneFunction['DifferentialIncrement'])
node_script += """ DirectOperator\n"""
node_script += """except NameError:\n"""
node_script += """ raise ValueError("ComputationFunctionNode: DirectOperator not found in the imported user script file")\n"""
- node_script += """from daNumerics import ApproximatedDerivatives\n"""
+ if sys.version_info.major < 3:
+ node_script += """from daNumerics import ApproximatedDerivatives\n"""
+ else:
+ node_script += """from adao.daNumerics import ApproximatedDerivatives\n"""
node_script += """FDA = ApproximatedDerivatives.FDApproximation(\n"""
node_script += """ Function = DirectOperator,\n"""
node_script += """ increment = %s,\n"""%str(ScriptWithOneFunction['DifferentialIncrement'])