From 5cf51d3b6a815278ea5453b8982595e6b1970847 Mon Sep 17 00:00:00 2001 From: Eric Fayolle Date: Fri, 7 Oct 2022 11:11:01 +0200 Subject: [PATCH] =?utf8?q?Affichage=20tabul=C3=A9=20des=20r=C3=A9sultats?= =?utf8?q?=20des=20=C3=A9tudes=20incertaines?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- generator/generator_UQ.py | 40 +++++++++++++++++++-------- generator/post_csv_rn.py | 48 ++++++++++++++++++++++++++++++++- generator/textePersalys.py | 55 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 129 insertions(+), 14 deletions(-) diff --git a/generator/generator_UQ.py b/generator/generator_UQ.py index 6eac0f42..03a7b6c3 100644 --- a/generator/generator_UQ.py +++ b/generator/generator_UQ.py @@ -41,6 +41,7 @@ from .textePersalys import optionalResultTaylor, optionalPrintResultTaylor from .textePersalys import centralTendencyMC, resultMC from .textePersalys import critereArretMC, advancedParameterMC from .textePersalys import optionalResultMC, optionalPrintResultMC +from .textePersalys import printResult from .textePersalys import yacsJobParameters, yacsJobClusterParameters, yacsJobClusterMultiJob def entryPoint(): @@ -217,7 +218,8 @@ class UQGenerator(PythonGenerator): 'valeur maximale':'vMax' } - index=0; + index=0; + self.resultSkList=[0] for mc in self.lesVariablesOutput : nomShortVariableOutputList='' nomFctAggPyList='' @@ -232,10 +234,10 @@ class UQGenerator(PythonGenerator): nomOutput=nomVarEncode+'_'+nomFctAggPy nomOutputList += nomOutput + ', ' self.chaineDesVariablesOutputEncodee+=nomOutput+ ', ' - variablesOutputDesc = nomFctAgg+'('+nomVarPostraite+')' + variablesOutputDesc = '("'+nomFctAgg+'","'+nomVarPostraite+'")' #TODO : Interdire ',' dans FctAgg et nomVarPost nomShortVariableOutputList+='a'+str(index)+', ' # Avoid a Persalys Bug index+=1 - self.txtOutputVariableInitList += self.indent1 + nomOutput + " = persalys.Output('"+ nomVar+' (Agg: '+nomFctAgg+')' + "', '"+variablesOutputDesc + "')\n" + self.txtOutputVariableInitList += self.indent1 + nomOutput + " = persalys.Output('"+ nomVar+' ('+nomFctAgg+')' + "', '"+variablesOutputDesc + "')\n" # tmpGetResultCall = getResultCall.format( tmpGetResultCall = getResultCallAvoidPersalysBug.format( # Avoid a Persalys Bug variableOutputList = nomOutputList[0:-2], @@ -244,6 +246,7 @@ class UQGenerator(PythonGenerator): shortVariableOutputList = nomShortVariableOutputList[0:-2] # Avoid a Persalys Bug ) self.txtGetAllResults += tmpGetResultCall + self.resultSkList.append(index) self.chaineDesVariablesOutputEncodee=self.chaineDesVariablesOutputEncodee[0:-2] self.chaineDesShortVariablesOutput = reduce(lambda x,y:x+y, @@ -304,11 +307,13 @@ class UQGenerator(PythonGenerator): return texte def creeScriptPersalys(self, debug=True) : - from functools import reduce as reduce + from functools import reduce # chaineDesVariablesInput=reduce(lambda x,y:x+','+y,l) - def getStrVarList(l,sep): - return reduce(lambda x,y:x+sep+y, l) + def getStrVarList(l,sep=','): + return reduce(lambda x,y:str(x)+sep+str(y), l) + def getStrVarStrList(l,sep=','): + return reduce(lambda x,y:"'"+str(x)+"'"+sep+"'"+str(y)+"'", l) def getStrInitList(l): return getStrVarList( map(lambda x:'self.{} = {}'.format(x,x),l), '\n'+2*self.indent1 ) def getStrReplaceVarList(l): @@ -344,13 +349,14 @@ class UQGenerator(PythonGenerator): chaineDesVariablesInput = self.chaineDesVariablesInput, getAllResults = self.txtGetAllResults, #chaineDesVariablesOutput = self.chaineDesVariablesOutputEncodee - chaineDesVariablesOutput = self.chaineDesShortVariablesOutput # Avoid a Persalys Bug + chaineDesVariablesOutput = self.chaineDesShortVariablesOutput # Avoid a Persalys Bug until v9.9 ) self.txtScriptPersalys += codePersalys.format( fonctionPersalys =txtFonctionPersalys ) - ## Propagation des incertitudes : Choix de la méthode et de ses paramètres + ## Propagation des incertitudes : + ## Choix de la méthode, de ses paramètres, et des résultats attendus if (self.Methode == 'Taylor' ): txtCentralTendencyPersalys = centralTendencyTaylor optionalResult = optionalResultTaylor @@ -379,27 +385,39 @@ class UQGenerator(PythonGenerator): return(0, "Impossible de gérer la méthode :",self.Methode) result="" + optionalResultNames=[] if self.Result : for mc in self.Result.mcListe: # print('mc : ',mc) # print('mc.nature : ',mc.nature) # print('mc.valeur : ',mc.valeur) if mc.nom == 'EmpiricalQuantile' and mc.valeur == 'yes' : + mc_nom=mc.nom[0].lower()+mc.nom[1:] ##TODO: Utiliser un nv dict commun des symboles avec optionalResult + optionalResultNames.append(mc_nom) empiricalQuantile_Order = self.Result.getChildOrChildInBloc("EmpiricalQuantile_Order") result+= self.indent1+optionalResult[mc.nom].format( **{empiricalQuantile_Order.nom : empiricalQuantile_Order.valeur} ) + '\n' result+= self.indent1+optionalPrintResult["EmpiricalQuantile_Order"] + '\n' result+= self.indent1+optionalPrintResult[mc.nom] + '\n' - elif mc.nature == 'MCSIMP' and mc.valeur == 'yes' : + elif mc.nature == 'MCSIMP' and mc.valeur == 'yes' : + mc_nom=mc.nom[0].lower()+mc.nom[1:] ##TODO: Utiliser un nv dict commun des symboles avec optionalResult + optionalResultNames.append(mc_nom) result+= self.indent1+optionalResult[mc.nom] + '\n' - result+= self.indent1+optionalPrintResult[mc.nom] + '\n' + # result+= self.indent1+optionalPrintResult[mc.nom] + '\n' # print('result:',result) # print('txtResultCT:',txtResultCT) + optionalResultList=getStrVarList(optionalResultNames) + optionalResultStrList=getStrVarStrList(optionalResultNames) + txtPrintResult=printResult.format( + optionalResultList = optionalResultList, + optionalResultStrList = optionalResultStrList, + resultSkList = getStrVarList(self.resultSkList)) txtResult= txtResultCT.format( optionalResult=result ) - + txtResult+=txtPrintResult + #TODO ;: Tester si Cluster== Gaia, ajouter les champs suivants # resourceName = 'gaia' # login='C65845' diff --git a/generator/post_csv_rn.py b/generator/post_csv_rn.py index e3ad0685..4e9338a6 100644 --- a/generator/post_csv_rn.py +++ b/generator/post_csv_rn.py @@ -1,4 +1,4 @@ -# Exemple de script pour lire la sortie csv du banc +# Exemple de script pour lire la sortie csv du banc d'intégration odysee # # Lecture des valeurs dans le csv et renvoi de la valeur après application de la fonction d'agragation max,min et moy @@ -96,3 +96,49 @@ def get_result_from_csv(variableName:str, functionList, filename:str=None, delim valList.append(func(date_value_array)) return valList + +# Fuel-temperature_Thermalhydraulics_MAX +# value at t_initial value at t_mid value at t_final mean value cumsum value min value max value +# MeanFirstOrder (°C): 1113.040047 1009.112047 968.544065 207597.218716 1113.040047 968.544064 1032.821984 +# StandardDeviationFirstOrder (°C): 203.302658 250.504351 255.172144 43724.195535 203.302658 256.008518 217.533311 + +def write_result_from_persalys(resultNp, indexNp, resSk, outputs): + + import numpy as np + import pandas as pnd + from functools import reduce + + #resultNp = np.array([meanFirstOrder, meanSecondOrderOrder, standardDeviationFirstOrder ]) + #Lignes de résultats demandés pour toutes les fcts d'aggrégation en colonne + #resultNp = np.array([ {optionalResultList} ]) + #Noms de lignes + #index = ['meanFirstOrder', 'meanSecondOrderOrder', 'standardDeviationFirstOrder' ] + #indexNp = [ {optionalResultStrList} ] + nResult = len(indexNp) + #Tableau skyline localisant les variables (hors fctAgg) dans le tableau de résultat global + #resultSk = [0,7,10] + #resSk = [ {resultSkList} ] + nOutVar = len(resSk)-1 + + print('\n') + for i in range(nOutVar): + # Récupère les couples (fctAggrégation,Nom de variable ss fct Agg) + # des champs de description des sorties. + # Les sorties concernées proviennent de la section de résultatNp + # qui doit correspondre à une même variable hors fct Agg + fctAgg_outVarName = list( map(lambda o: eval(o.getDescription()), + outputs[resSk[i]:resSk[i+1]]) ) + outVarName = fctAgg_outVarName[0][1] + checkOutVarName = reduce( lambda n1,n2: n1 == n2, + [True]+list( map(lambda o: o[1] == outVarName, + fctAgg_outVarName) ) ) + assert(checkOutVarName == True) + print(outVarName) + columns = list(map(lambda o1: o1[0], fctAgg_outVarName) ) + resultDf = pnd.DataFrame(resultNp[:,resSk[i]:(resSk[i+1])], + index = indexNp, + columns = columns ) + print(resultDf,'\n') + #name_csv = str.replace(str.replace(outVarName,"@","_"),' ','-') + name_csv = outVarName + resultDf.to_csv(name_csv+'-uncertainty.csv') diff --git a/generator/textePersalys.py b/generator/textePersalys.py index f3aeb278..d047c782 100644 --- a/generator/textePersalys.py +++ b/generator/textePersalys.py @@ -217,16 +217,66 @@ if __name__ == '__main__': # inputs = [a, b] # outputs = [d] +printResult=""" import numpy as np + from post_csv_rn import write_result_from_persalys + # import pandas as pnd + # from functools import reduce + + #resultNp = np.array([meanFirstOrder, meanSecondOrderOrder, standardDeviationFirstOrder ]) + #Lignes de résultats demandés pour toutes les fcts d'aggrégation en colonne + resultNp = np.array([ {optionalResultList} ]) + + #Noms de lignes + #index = ['meanFirstOrder', 'meanSecondOrderOrder', 'standardDeviationFirstOrder' ] + indexNp = [ {optionalResultStrList} ] + + #nResult = len(indexNp) + + #Tableau skyline localisant les variables (hors fctAgg) dans le tableau de résultat global + #resultSk = [0,7,10] + resSk = [ {resultSkList} ] + + #nOutVar = len(resSk)-1 + + write_result_from_persalys(resultNp, indexNp, resSk, outputs) + + # print('\\n') + # for i in range(nOutVar): + # # Récupère les couples (fctAggrégation,Nom de variable ss fct Agg) + # # des champs de description des sorties. + # # Les sorties concernées proviennent de la section de résultatNp + # # qui doit correspondre à une même variable hors fct Agg + # fctAgg_outVarName = list( map(lambda o: eval(o.getDescription()), + # outputs[resSk[i]:resSk[i+1]]) ) + # outVarName = fctAgg_outVarName[0][1] + # checkOutVarName = reduce( lambda n1,n2: n1 == n2, + # [True]+list( map(lambda o: o[1] == outVarName, + # fctAgg_outVarName) ) ) + # assert(checkOutVarName == True) + # print(outVarName) + # columns = list(map(lambda o1: o1[0], fctAgg_outVarName) ) + # resultDf = pnd.DataFrame(resultNp[:,resSk[i]:(resSk[i+1])], + # index = indexNp, + # columns = columns ) + # print(resultDf,'\\n') + # #name_csv = str.replace(str.replace(outVarName,"@","_"),' ','-') + # name_csv = outVarName + # resultDf.to_csv(name_csv+'-uncertainty.csv') + +""" + ## Tendance Centrale Taylor centralTendencyTaylor =""" centralTendency = persalys.TaylorExpansionMomentsAnalysis('centralTendencyTaylor', yacsPhysicalModel) """ -#Les retours sont des listes de taille +#Le result est une liste de taille resultTaylor=""" result = centralTendency.getResult() {optionalResult} + """ + optionalResultTaylor={ 'MeanFirstOrder' : 'meanFirstOrder = result.getMeanFirstOrder()', 'StandardDeviationFirstOrder' : 'standardDeviationFirstOrder = result.getStandardDeviation()', @@ -259,11 +309,12 @@ advancedParameterMC = { 'ComputeConfidenceIntervalAt' : 'centralTendency.setLevelConfidenceInterval({ComputeConfidenceIntervalAt})' } -#TODO: Associer les noms de variables au résultat +#TODO: Gérer les unités resultMC=""" result = centralTendency.getResult() {optionalResult} """ + optionalResultMC={ 'EmpiricalMean' : 'empiricalMean = result.getMean()', #TOCHECK 'Variance' : 'variance = result.getVariance()', -- 2.39.2