From: Jean-Philippe ARGAUD Date: Thu, 1 Feb 2018 21:08:37 +0000 (+0100) Subject: Removing obsolete diagnostics and their use X-Git-Tag: V8_5_0rc1~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=142f105498859376e0367afb1f522fbcc8bf2d84;p=modules%2Fadao.git Removing obsolete diagnostics and their use --- diff --git a/src/daComposant/Makefile.am b/src/daComposant/Makefile.am index 5d5b2b2..3f3135c 100644 --- a/src/daComposant/Makefile.am +++ b/src/daComposant/Makefile.am @@ -22,7 +22,7 @@ include $(top_srcdir)/adm_local/make_common_starter.am -EXTRA_DIST = daCore daAlgorithms daDiagnostics daNumerics +EXTRA_DIST = daCore daAlgorithms daNumerics DIR = $(top_srcdir)/src/daComposant/ @@ -30,12 +30,10 @@ install-data-local: ${mkinstalldirs} $(DESTDIR)$(salomepythondir) cp -R $(DIR)daCore $(DESTDIR)$(salomepythondir) cp -R $(DIR)daAlgorithms $(DESTDIR)$(salomepythondir) - cp -R $(DIR)daDiagnostics $(DESTDIR)$(salomepythondir) cp -R $(DIR)daNumerics $(DESTDIR)$(salomepythondir) uninstall-local: chmod -R +w $(DESTDIR)$(salomepythondir) rm -rf $(DESTDIR)$(salomepythondir)/daCore rm -rf $(DESTDIR)$(salomepythondir)/daAlgorithms - rm -rf $(DESTDIR)$(salomepythondir)/daDiagnostics rm -rf $(DESTDIR)$(salomepythondir)/daNumerics diff --git a/src/daComposant/daCore/Aidsm.py b/src/daComposant/daCore/Aidsm.py index c5f0da2..15cbb83 100644 --- a/src/daComposant/daCore/Aidsm.py +++ b/src/daComposant/daCore/Aidsm.py @@ -31,7 +31,7 @@ import sys # from daCore.BasicObjects import State, Covariance, FullOperator, Operator from daCore.BasicObjects import AlgorithmAndParameters, DataObserver -from daCore.BasicObjects import DiagnosticAndParameters, CaseLogger +from daCore.BasicObjects import CaseLogger from daCore import PlatformInfo # from daCore import ExtendedLogging ; ExtendedLogging.ExtendedLogging() # A importer en premier @@ -69,7 +69,7 @@ class Aidsm(object): self.__adaoObject[ename] = None for ename in ("ObservationOperator", "EvolutionModel", "ControlModel"): self.__adaoObject[ename] = {} - for ename in ("Diagnostic", "Observer"): + for ename in ("Observer",): self.__adaoObject[ename] = [] self.__StoredInputs[ename] = [] # @@ -85,11 +85,8 @@ class Aidsm(object): Algorithm = None, AppliedInXb = None, AvoidRC = True, - BaseType = None, Checked = False, - Diagnostic = None, DiagonalSparseMatrix = None, - Identifier = None, Info = None, Matrix = None, ObjectFunction = None, @@ -103,7 +100,6 @@ class Aidsm(object): String = None, Template = None, ThreeFunctions = None, - Unit = None, Variable = None, Vector = None, VectorSerie = None, @@ -126,8 +122,6 @@ class Aidsm(object): self.setNoDebug() elif Concept == "Observer": self.setObserver( Variable, Template, String, Script, Info, ObjectFunction, Scheduler ) - elif Concept == "Diagnostic": - self.setDiagnostic( Diagnostic, Identifier, Parameters, Script, Unit, BaseType ) elif Concept == "ObservationOperator": self.setObservationOperator( Matrix, OneFunction, ThreeFunctions, AppliedInXb, @@ -515,29 +509,6 @@ class Aidsm(object): # ----------------------------------------------------------- - def setDiagnostic(self, - Diagnostic = None, - Identifier = None, - Parameters = None, - Script = None, - Unit = None, - BaseType = None): - "Definition d'un concept de calcul" - Concept = "Diagnostic" - self.__case.register("set"+Concept, dir(), locals()) - self.__adaoObject[Concept].append( DiagnosticAndParameters( - name = Concept, - asDiagnostic = Diagnostic, - asIdentifier = Identifier, - asDict = Parameters, - asScript = Script, - asUnit = Unit, - asBaseType = BaseType, - asExistingDiags = self.__StoredInputs[Concept], - )) - self.__StoredInputs[Concept].append(str(Identifier)) - return 0 - def get(self, Concept=None, noDetails=True ): "Recuperation d'une sortie du calcul" if Concept is not None: @@ -557,18 +528,13 @@ class Aidsm(object): elif Concept == "AlgorithmRequiredParameters" and self.__adaoObject["AlgorithmParameters"] is not None: return self.__adaoObject["AlgorithmParameters"].getAlgorithmRequiredParameters(noDetails) # - elif Concept in self.__StoredInputs["Diagnostic"]: - indice = self.__StoredInputs["Diagnostic"].index(Concept) - return self.__adaoObject["Diagnostic"][indice].get() - # else: - raise ValueError("The requested key \"%s\" does not exists as an input, a diagnostic or a stored variable."%Concept) + raise ValueError("The requested key \"%s\" does not exists as an input or a stored variable."%Concept) else: allvariables = {} allvariables.update( {"AlgorithmParameters":self.__adaoObject["AlgorithmParameters"].get()} ) # allvariables.update( self.__adaoObject["AlgorithmParameters"].get() ) allvariables.update( self.__StoredInputs ) - allvariables.pop('Diagnostic', None) allvariables.pop('Observer', None) return allvariables @@ -590,7 +556,6 @@ class Aidsm(object): variables.extend(list(self.__adaoObject["AlgorithmParameters"].keys())) if len(list(self.__StoredInputs.keys())) > 0: variables.extend( list(self.__StoredInputs.keys()) ) - variables.remove('Diagnostic') variables.remove('Observer') variables.sort() return variables @@ -614,27 +579,11 @@ class Aidsm(object): files.sort() return files - def get_available_diagnostics(self): - """ - Renvoie la liste des diagnostics potentiellement utilisables, identifiés - par les chaînes de caractères. - """ - files = [] - for directory in sys.path: - if os.path.isdir(os.path.join(directory,"daDiagnostics")): - for fname in os.listdir(os.path.join(directory,"daDiagnostics")): - root, ext = os.path.splitext(fname) - if ext == '.py' and root != '__init__': - files.append(root) - files.sort() - return files - # ----------------------------------------------------------- def get_algorithms_main_path(self): """ Renvoie le chemin pour le répertoire principal contenant les algorithmes - dans un sous-répertoire "daAlgorithms" """ return self.__parent @@ -642,9 +591,6 @@ class Aidsm(object): """ Ajoute au chemin de recherche des algorithmes un répertoire dans lequel se trouve un sous-répertoire "daAlgorithms" - - Remarque : si le chemin a déjà été ajouté pour les diagnostics, il n'est - pas indispensable de le rajouter ici. """ if not os.path.isdir(Path): raise ValueError("The given "+Path+" argument must exist as a directory") @@ -656,31 +602,6 @@ class Aidsm(object): sys.path = PlatformInfo.uniq( sys.path ) # Conserve en unique exemplaire chaque chemin return 0 - def get_diagnostics_main_path(self): - """ - Renvoie le chemin pour le répertoire principal contenant les diagnostics - dans un sous-répertoire "daDiagnostics" - """ - return self.__parent - - def add_diagnostics_path(self, Path=None): - """ - Ajoute au chemin de recherche des algorithmes un répertoire dans lequel - se trouve un sous-répertoire "daDiagnostics" - - Remarque : si le chemin a déjà été ajouté pour les algorithmes, il n'est - pas indispensable de le rajouter ici. - """ - if not os.path.isdir(Path): - raise ValueError("The given "+Path+" argument must exist as a directory") - if not os.path.isdir(os.path.join(Path,"daDiagnostics")): - raise ValueError("The given \""+Path+"\" argument must contain a subdirectory named \"daDiagnostics\"") - if not os.path.isfile(os.path.join(Path,"daDiagnostics","__init__.py")): - raise ValueError("The given \""+Path+"/daDiagnostics\" path must contain a file named \"__init__.py\"") - sys.path.insert(0, os.path.abspath(Path)) - sys.path = PlatformInfo.uniq( sys.path ) # Conserve en unique exemplaire chaque chemin - return 0 - # ----------------------------------------------------------- def execute(self, Executor=None, SaveCaseInFile=None): diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index a127da6..e4d0122 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -732,136 +732,6 @@ class Algorithm(object): self._parameters[k] = self.setParameterValue(k) logging.debug("%s %s : %s", self._name, self.__required_parameters[k]["message"], self._parameters[k]) -# ============================================================================== -class Diagnostic(object): - """ - Classe générale d'interface de type diagnostic - - Ce template s'utilise de la manière suivante : il sert de classe "patron" en - même temps que l'une des classes de persistance, comme "OneScalar" par - exemple. - - Une classe élémentaire de diagnostic doit implémenter ses deux méthodes, la - méthode "_formula" pour écrire explicitement et proprement la formule pour - l'écriture mathématique du calcul du diagnostic (méthode interne non - publique), et "calculate" pour activer la précédente tout en ayant vérifié - et préparé les données, et pour stocker les résultats à chaque pas (méthode - externe d'activation). - """ - def __init__(self, name = "", parameters = {}): - "Initialisation" - self.name = str(name) - self.parameters = dict( parameters ) - - def _formula(self, *args): - """ - Doit implémenter l'opération élémentaire de diagnostic sous sa forme - mathématique la plus naturelle possible. - """ - raise NotImplementedError("Diagnostic mathematical formula has not been implemented!") - - def calculate(self, *args): - """ - Active la formule de calcul avec les arguments correctement rangés - """ - raise NotImplementedError("Diagnostic activation method has not been implemented!") - -# ============================================================================== -class DiagnosticAndParameters(object): - """ - Classe générale d'interface d'interface de type diagnostic - """ - def __init__(self, - name = "GenericDiagnostic", - asDiagnostic = None, - asIdentifier = None, - asDict = None, - asScript = None, - asUnit = None, - asBaseType = None, - asExistingDiags = None, - ): - """ - """ - self.__name = str(name) - self.__D = None - self.__I = None - self.__P = {} - self.__U = "" - self.__B = None - self.__E = tuple(asExistingDiags) - self.__TheDiag = None - # - if asScript is not None: - __Diag = ImportFromScript(asScript).getvalue( "Diagnostic" ) - __Iden = ImportFromScript(asScript).getvalue( "Identifier" ) - __Dict = ImportFromScript(asScript).getvalue( self.__name, "Parameters" ) - __Unit = ImportFromScript(asScript).getvalue( "Unit" ) - __Base = ImportFromScript(asScript).getvalue( "BaseType" ) - else: - __Diag = asDiagnostic - __Iden = asIdentifier - __Dict = asDict - __Unit = asUnit - __Base = asBaseType - # - if __Diag is not None: - self.__D = str(__Diag) - if __Iden is not None: - self.__I = str(__Iden) - else: - self.__I = str(__Diag) - if __Dict is not None: - self.__P.update( dict(__Dict) ) - if __Unit is None or __Unit == "None": - self.__U = "" - if __Base is None or __Base == "None": - self.__B = None - # - self.__setDiagnostic( self.__D, self.__I, self.__U, self.__B, self.__P, self.__E ) - - def get(self): - "Renvoie l'objet" - return self.__TheDiag - - def __setDiagnostic(self, __choice = None, __name = "", __unit = "", __basetype = None, __parameters = {}, __existings = () ): - """ - Permet de sélectionner un diagnostic a effectuer - """ - if __choice is None: - raise ValueError("Error: diagnostic choice has to be given") - __daDirectory = "daDiagnostics" - # - # Recherche explicitement le fichier complet - # ------------------------------------------ - __module_path = None - for directory in sys.path: - if os.path.isfile(os.path.join(directory, __daDirectory, str(__choice)+'.py')): - __module_path = os.path.abspath(os.path.join(directory, __daDirectory)) - if __module_path is None: - raise ImportError("No diagnostic module named \"%s\" was found in a \"%s\" subdirectory\n The search path is %s"%(__choice, __daDirectory, sys.path)) - # - # Importe le fichier complet comme un module - # ------------------------------------------ - try: - __sys_path_tmp = sys.path ; sys.path.insert(0,__module_path) - self.__diagnosticFile = __import__(str(__choice), globals(), locals(), []) - sys.path = __sys_path_tmp ; del __sys_path_tmp - except ImportError as e: - raise ImportError("The module named \"%s\" was found, but is incorrect at the import stage.\n The import error message is: %s"%(__choice,e)) - # - # Instancie un objet du type élémentaire du fichier - # ------------------------------------------------- - if __name in __existings: - raise ValueError("A default input with the same name \"%s\" already exists."%str(__name)) - else: - self.__TheDiag = self.__diagnosticFile.ElementaryDiagnostic( - name = __name, - unit = __unit, - basetype = __basetype, - parameters = __parameters ) - return 0 - # ============================================================================== class AlgorithmAndParameters(object): """ diff --git a/src/daComposant/daDiagnostics/PlotVector.py b/src/daComposant/daDiagnostics/PlotVector.py deleted file mode 100644 index 3c4173b..0000000 --- a/src/daComposant/daDiagnostics/PlotVector.py +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2008-2018 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 - -import numpy -from daCore import BasicObjects -import os.path - -# ============================================================================== -class ElementaryDiagnostic(BasicObjects.Diagnostic): - """ - Classe pour tracer simplement un vecteur à chaque pas - """ - def __init__(self, name = "", unit = "", basetype = None, parameters = {}): - BasicObjects.Diagnostic.__init__(self, name, parameters) - try: - import Gnuplot - self.__gnuplot = Gnuplot - except: - raise ImportError("The Gnuplot module is required to plot the vector") - - def _formula(self, - Vector, Steps, - title, xlabel, ylabel, ltitle, - geometry, - filename, - persist, - pause ): - """ - Trace en gnuplot le vecteur Vector, avec une légende générale, en X et - en Y - """ - if persist: - self.__gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -persist -geometry '+geometry - else: - self.__gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -geometry '+geometry - # - self.__g = self.__gnuplot.Gnuplot() # persist=1 - self.__g('set terminal '+self.__gnuplot.GnuplotOpts.default_term) - self.__g('set style data lines') - self.__g('set grid') - self.__g('set autoscale') - self.__g('set title "'+title +'"') - self.__g('set xlabel "'+xlabel+'"') - self.__g('set ylabel "'+ylabel+'"') - self.__g.plot( self.__gnuplot.Data( Steps, Vector, title=ltitle ) ) - if filename != "": - self.__g.hardcopy(filename=filename, color=1) - if pause: - eval(input('Please press return to continue...\n')) - # - return 1 - - def calculate(self, vector = None, steps = None, - title = "", xlabel = "", ylabel = "", ltitle = "", - geometry = "600x400", - filename = "", - persist = False, - pause = True ): - """ - Arguments : - - vector : le vecteur à tracer, en liste ou en numpy.array - - steps : liste unique des pas de l'axe des X, ou None si c'est - la numérotation par défaut - - title : titre général du dessin - - xlabel : label de l'axe des X - - ylabel : label de l'axe des Y - - ltitle : titre associé au vecteur tracé - - geometry : taille en pixels de la fenêtre et position du coin haut - gauche, au format X11 : LxH+X+Y (défaut : 600x400) - - filename : nom de fichier Postscript pour une sauvegarde à 1 pas - Attention, il faut changer le nom à l'appel pour - plusieurs pas de sauvegarde - - persist : booléen indiquant que la fenêtre affichée sera - conservée lors du passage au dessin suivant - Par défaut, persist = False - - pause : booléen indiquant une pause après chaque tracé, et - attendant un Return - Par défaut, pause = True - """ - if vector is None: - raise ValueError("One vector must be given to plot it.") - Vector = numpy.array(vector) - if Vector.size < 1: - raise ValueError("The given vector must not be empty") - if steps is None: - Steps = list(range(len( vector ))) - elif not ( isinstance(steps, type([])) or not isinstance(steps, type(numpy.array([]))) ): - raise ValueError("The steps must be given as a list/tuple.") - else: - Steps = list(steps) - if os.path.isfile(filename): - raise ValueError("Error: a file with this name \"%s\" already exists."%filename) - # - value = self._formula( - Vector = Vector, - Steps = Steps, - title = str(title).encode('ascii','replace'), - xlabel = str(xlabel).encode('ascii','replace'), - ylabel = str(ylabel).encode('ascii','replace'), - ltitle = str(ltitle), - geometry = str(geometry), - filename = str(filename), - persist = bool(persist), - pause = bool(pause) ) - -# ============================================================================== -if __name__ == "__main__": - print('\n AUTODIAGNOSTIC \n') - - D = ElementaryDiagnostic("Mon Plot") - - vect = [1, 2, 1, 2, 1] - D.calculate(vect, title = "Vecteur 1", xlabel = "Axe X", ylabel = "Axe Y" ) - vect = [1, 3, 1, 3, 1] - D.calculate(vect, title = "Vecteur 2", filename = "vecteur.ps") - vect = [1, 1, 1, 1, 1] - D.calculate(vect, title = "Vecteur 3") - vect = [0.29, 0.97, 0.73, 0.01, 0.20] - D.calculate(vect, title = "Vecteur 4") - vect = [-0.23262176, 1.36065207, 0.32988102, 0.24400551, -0.66765848, -0.19088483, -0.31082575, 0.56849814, 1.21453443, 0.99657516] - D.calculate(vect, title = "Vecteur 5") - vect = [0.29, 0.97, 0.73, 0.01, 0.20] - D.calculate(vect, title = "Vecteur 6 affiche avec une autre geometrie et position", geometry="800x200+50+50") - vect = 100*[0.29, 0.97, 0.73, 0.01, 0.20] - D.calculate(vect, title = "Vecteur 7 : long construit par repetition") - vect = [0.29, 0.97, 0.73, 0.01, 0.20] - D.calculate(vect, title = "Vecteur 8", ltitle = "Vecteur 8") - temps = [0.1,0.2,0.3,0.4,0.5] - D.calculate(vect, temps, title = "Vecteur 8 avec axe du temps modifie") - print("") diff --git a/src/daComposant/daDiagnostics/PlotVectors.py b/src/daComposant/daDiagnostics/PlotVectors.py deleted file mode 100644 index 37b7222..0000000 --- a/src/daComposant/daDiagnostics/PlotVectors.py +++ /dev/null @@ -1,155 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2008-2018 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 - -import numpy -from daCore import BasicObjects -import os.path - -# ============================================================================== -class ElementaryDiagnostic(BasicObjects.Diagnostic): - """ - Classe pour tracer simplement une liste de vecteurs à chaque pas - """ - def __init__(self, name = "", unit = "", basetype = None, parameters = {}): - BasicObjects.Diagnostic.__init__(self, name, parameters) - try: - import Gnuplot - self.__gnuplot = Gnuplot - except: - raise ImportError("The Gnuplot module is required to plot the vector") - - def _formula(self, - Vector, Steps, - title, xlabel, ylabel, ltitle, - geometry, - filename, - persist, - pause ): - """ - Trace en gnuplot chaque vecteur de la liste Vector, avec une légende - générale, en X et en Y - """ - if persist: - self.__gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -persist -geometry '+geometry - else: - self.__gnuplot.GnuplotOpts.gnuplot_command = 'gnuplot -geometry '+geometry - # - self.__g = self.__gnuplot.Gnuplot() # persist=1 - self.__g('set terminal '+self.__gnuplot.GnuplotOpts.default_term) - self.__g('set style data lines') - self.__g('set grid') - self.__g('set autoscale') - self.__g('set title "'+title.decode() +'"') - self.__g('set xlabel "'+xlabel.decode()+'"') - self.__g('set ylabel "'+ylabel.decode()+'"') - self.__g.plot( self.__gnuplot.Data( Steps, Vector.pop(0), title=ltitle.pop(0) ) ) - for vector in Vector: - self.__g.replot( self.__gnuplot.Data( Steps, vector, title=ltitle.pop(0) ) ) - if filename != "": - self.__g.hardcopy(filename=filename, color=1) - if pause: - eval(input('Please press return to continue...\n')) - # - return 1 - - def calculate(self, vector = None, steps = None, - title = "", xlabel = "", ylabel = "", ltitle = None, - geometry = "600x400", - filename = "", - persist = False, - pause = True ): - """ - Arguments : - - vector : liste des vecteurs à tracer, chacun étant en liste ou - en numpy.array - - steps : liste unique des pas, ou None si c'est la numérotation - par défaut - - title : titre général du dessin - - xlabel : label de l'axe des X - - ylabel : label de l'axe des Y - - ltitle : liste des titres associés à chaque vecteur, dans le - même ordre que les vecteurs eux-mêmes - - geometry : taille en pixels de la fenêtre et position du coin haut - gauche, au format X11 : LxH+X+Y (défaut : 600x400) - - filename : nom de fichier Postscript pour une sauvegarde à 1 pas - Attention, il faut changer le nom à l'appel pour - plusieurs pas de sauvegarde - - persist : booléen indiquant que la fenêtre affichée sera - conservée lors du passage au dessin suivant - Par défaut, persist = False - - pause : booléen indiquant une pause après chaque tracé, et - attendant un Return - Par défaut, pause = True - """ - if vector is None: - raise ValueError("One vector must be given to plot it.") - if not isinstance(vector, (list, tuple)): - raise ValueError("The vector(s) must be given as a list/tuple.") - if ltitle is None or len(ltitle) != len(vector): - ltitle = ["" for i in range(len(vector))] - VectorList = [] - for onevector in vector: - VectorList.append( numpy.array( onevector ) ) - if VectorList[-1].size < 1: - raise ValueError("Each given vector must not be empty.") - if steps is None: - Steps = list(range(len(vector[0]))) - elif not ( isinstance(steps, type([])) or not isinstance(steps, type(numpy.array([]))) ): - raise ValueError("The steps must be given as a list/tuple.") - else: - Steps = list(steps) - if os.path.isfile(filename): - raise ValueError("Error: a file with this name \"%s\" already exists."%filename) - # - value = self._formula( - Vector = VectorList, - Steps = Steps, - title = str(title).encode('ascii','replace'), - xlabel = str(xlabel).encode('ascii','replace'), - ylabel = str(ylabel).encode('ascii','replace'), - ltitle = [str(lt) for lt in ltitle], - geometry = str(geometry), - filename = str(filename), - persist = bool(persist), - pause = bool(pause), - ) - -# ============================================================================== -if __name__ == "__main__": - print('\n AUTODIAGNOSTIC \n') - - D = ElementaryDiagnostic("Mon Plot") - - vect1 = [1, 2, 1, 2, 1] - D.calculate([vect1,], title = "Vecteur 1", xlabel = "Axe X", ylabel = "Axe Y" ) - vect2 = [1, 3, 1, 3, 1] - D.calculate([vect1,vect2], title = "Vecteurs 1 et 2", filename = "liste_de_vecteurs.ps") - vect3 = [-1, 1, -1, 1, -1] - D.calculate((vect1,vect2,vect3), title = "Vecteurs 1 a 3") - vect4 = 100*[0.29, 0.97, 0.73, 0.01, 0.20] - D.calculate([vect4,], title = "Vecteur 4 : long construit par repetition") - D.calculate( - (vect1,vect2,vect3), - [0.1,0.2,0.3,0.4,0.5], - title = "Vecteurs 1 a 3, temps modifie", - ltitle = ["Vecteur 1","Vecteur 2","Vecteur 3"]) - print("") diff --git a/src/daComposant/daDiagnostics/RMS.py b/src/daComposant/daDiagnostics/RMS.py deleted file mode 100644 index b9764cb..0000000 --- a/src/daComposant/daDiagnostics/RMS.py +++ /dev/null @@ -1,88 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2008-2018 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 - -import math, numpy -from daCore import BasicObjects, Persistence - -# ============================================================================== -class ElementaryDiagnostic(BasicObjects.Diagnostic,Persistence.OneScalar): - """ - Calcul d'une RMS - """ - def __init__(self, name = "", unit = "", basetype = None, parameters = {}): - BasicObjects.Diagnostic.__init__(self, name, parameters) - Persistence.OneScalar.__init__( self, name, unit, basetype = float) - - def _formula(self, V1, V2): - """ - Fait un écart RMS entre deux vecteurs V1 et V2 - """ - rms = math.sqrt( ((V2 - V1)**2).sum() / float(V1.size) ) - # - return rms - - def calculate(self, vector1 = None, vector2 = None, step = None): - """ - Teste les arguments, active la formule de calcul et stocke le résultat - """ - if vector1 is None or vector2 is None: - raise ValueError("Two vectors must be given to calculate their RMS") - V1 = numpy.array(vector1) - V2 = numpy.array(vector2) - if V1.size < 1 or V2.size < 1: - raise ValueError("The given vectors must not be empty") - if V1.size != V2.size: - raise ValueError("The two given vectors must have the same size") - # - value = self._formula( V1, V2 ) - # - self.store( value = value, step = step ) - -# ============================================================================== -if __name__ == "__main__": - print('\n AUTODIAGNOSTIC \n') - - D = ElementaryDiagnostic("Ma RMS") - - vect1 = [1, 2, 1, 2, 1] - vect2 = [2, 1, 2, 1, 2] - D.calculate(vect1,vect2) - vect1 = [1, 3, 1, 3, 1] - vect2 = [2, 2, 2, 2, 2] - D.calculate(vect1,vect2) - vect1 = [1, 1, 1, 1, 1] - vect2 = [2, 2, 2, 2, 2] - D.calculate(vect1,vect2) - vect1 = [1, 1, 1, 1, 1] - vect2 = [4, -2, 4, -2, -2] - D.calculate(vect1,vect2) - vect1 = [0.29, 0.97, 0.73, 0.01, 0.20] - vect2 = [0.92, 0.86, 0.11, 0.72, 0.54] - D.calculate(vect1,vect2) - vect1 = [-0.23262176, 1.36065207, 0.32988102, 0.24400551, -0.66765848, -0.19088483, -0.31082575, 0.56849814, 1.21453443, 0.99657516] - vect2 = [0,0,0,0,0,0,0,0,0,0] - D.calculate(vect1,vect2) - print(" Les valeurs de RMS attendues sont les suivantes : [1.0, 1.0, 1.0, 3.0, 0.53162016515553656, 0.73784217096601323]") - print(" Les RMS obtenues................................: %s"%(D[:],)) - print(" La moyenne......................................: %s"%(D.mean(),)) - print("") - diff --git a/src/daComposant/daDiagnostics/ReduceVariance.py b/src/daComposant/daDiagnostics/ReduceVariance.py deleted file mode 100644 index 45ccac2..0000000 --- a/src/daComposant/daDiagnostics/ReduceVariance.py +++ /dev/null @@ -1,111 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2008-2018 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 -# - -import numpy -from daCore import BasicObjects, Persistence - -# ============================================================================== -class ElementaryDiagnostic(BasicObjects.Diagnostic,Persistence.OneScalar): - """ - Diagnostic sur la reduction de la variance lors de l'analyse - """ - def __init__(self, name = "", unit = "", basetype = None, parameters = {}): - BasicObjects.Diagnostic.__init__(self, name, parameters) - Persistence.OneScalar.__init__( self, name, unit, basetype = bool ) - - def _formula(self, V1, V2): - """ - Vérification de la reduction de variance sur les écarts entre OMB et OMA - lors de l'analyse - """ - varianceOMB = V1.var() - varianceOMA = V2.var() - # - if varianceOMA > varianceOMB: - reducevariance = False - else : - reducevariance = True - # - return reducevariance - - def calculate(self, vectorOMB = None, vectorOMA = None, step = None): - """ - Teste les arguments, active la formule de calcul et stocke le résultat - Arguments : - - vectorOMB : vecteur d'écart entre les observations et l'ébauche - - vectorOMA : vecteur d'écart entre les observations et l'analyse - """ - if ( (vectorOMB is None) or (vectorOMA is None) ): - raise ValueError("Two vectors must be given to test the reduction of the variance after analysis") - V1 = numpy.array(vectorOMB) - V2 = numpy.array(vectorOMA) - if V1.size < 1 or V2.size < 1: - raise ValueError("The given vectors must not be empty") - if V1.size != V2.size: - raise ValueError("The two given vectors must have the same size") - # - value = self._formula( V1, V2 ) - # - self.store( value = value, step = step ) - -#=============================================================================== -if __name__ == "__main__": - print('\n AUTODIAGNOSTIC \n') - # - # Instanciation de l'objet diagnostic - # ----------------------------------- - D = ElementaryDiagnostic("Mon ReduceVariance") - # - # Vecteur de type matrix - # ---------------------- - x1 = numpy.matrix(([3. , 4., 5. ])) - x2 = numpy.matrix(([1.5, 2., 2.5])) - print(" L'écart entre les observations et l'ébauche est OMB : %s"%(x1,)) - print(" La moyenne de OMB (i.e. le biais) est de............: %s"%(x1.mean(),)) - print(" La variance de OMB est de...........................: %s"%(x1.var(),)) - print(" L'écart entre les observations et l'analyse est OMA : %s"%(x2,)) - print(" La moyenne de OMA (i.e. le biais) est de............: %s"%(x2.mean(),)) - print(" La variance de OMA est de...........................: %s"%(x2.var(),)) - # - D.calculate( vectorOMB = x1, vectorOMA = x2) - if not D[0] : - print(" Résultat : l'analyse NE RÉDUIT PAS la variance") - else : - print(" Résultat : l'analyse RÉDUIT la variance") - print("") - # - # Vecteur de type array - # --------------------- - x1 = numpy.array(range(11)) - x2 = numpy.matrix(range(-10,12,2)) - print(" L'écart entre les observations et l'ébauche est OMB : %s"%(x1,)) - print(" La moyenne de OMB (i.e. le biais) est de............: %s"%(x1.mean(),)) - print(" La variance de OMB est de...........................: %s"%(x1.var(),)) - print(" L'écart entre les observations et l'analyse est OMA : %s"%(x2,)) - print(" La moyenne de OMA (i.e. le biais) est de............: %s"%(x2.mean(),)) - print(" La variance de OMA est de...........................: %s"%(x2.var(),)) - # - D.calculate( vectorOMB = x1, vectorOMA = x2) - if not D[1] : - print(" Résultat : l'analyse NE RÉDUIT PAS la variance") - else : - print(" Résultat : l'analyse RÉDUIT la variance") - print("") diff --git a/src/daComposant/daDiagnostics/__init__.py b/src/daComposant/daDiagnostics/__init__.py deleted file mode 100644 index 52ece7b..0000000 --- a/src/daComposant/daDiagnostics/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2008-2018 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