Example #1
0
#				Main program
################################################################################




reponse = xmlParser.parse_xml_response("essai_xml_response.xml")
print(validation.validation_code(reponse,"essai_xml.xml","laplacian1DP1",0.32))
#print(validation.validation_code_norm(reponse,"essai_xml.xml","laplacian1DP1","H1",0.05))
data=[[1,2,20],[1,4,6.78]]
func="x**2"
#print(error.validation_all(data,func,0.1))

#data=datas[0]
#func=funcs[0]
data2=error.changedata(data,func)
func2=error.changefunc(func)
data3=error.slope_calc(data,func)

#print(data2)
#print(func2)

##V2 affichage en utilisant nos fonctions

#h=displayGraphics.create_graph_XlogYlin(12,1,20,1,20,"h","Error")





Example #2
0
def validation_code(name,param,output,xmlname,val_param,val_depend,precision,pathD):
	result=1
	for out in output:
		if len(out.getDependencies())==0:
			print "[Validation] error : no dependencies..."
			break
		depend=out.getDependencies()[0]
		func=out.getFuncs()[0]
		data=[]
		for val_dep in val_depend[depend]:
			list_param=[]
			val=[]
			for par in param:
				if (par.getName()!=depend):
					list_param.append(par.getName())
					val.append(val_param[par.getName()][0])
				else:
					list_param.append(par.getName())
					val.append(val_dep)
					par_depend=par
			data.append(xmlParser.parse_xml_result(xmlname,name,list_param,val,out.getName()))

		data=map(float,data)
		val=map(float,val_depend[depend])
		data_temp=[val,data]

		temp=error.validation(data_temp,func,depend,precision)
		result=temp and result

		nb_decimal=len(str(precision))-1

		#Transformation des donnees pour affichage graphique
		data2=error.changedata(data_temp,func)
		func2=error.changefunc(func)
		data3 = error.fit(data2[0],data2[1])

		#On veut un certain nombre de chiffres significatifs pour les estimations
		#bo abscisse a l'origine et b1 pente
		b0=str(decimal.Decimal(str(round(exp(data3[1][0]),nb_decimal))))
		b1=str(decimal.Decimal(str(round(data3[1][1],nb_decimal))))

		#On teste si le parametre variable contient une description latex
		if (par_depend.getAttrNames().count("latex")):
				chaine=par_depend.getAttrValues()[3]
				func=func.replace(par_depend.getName(),par_depend.getAttrValues()[3])
		else:
				chaine=depend

		#On teste le nombre de log appliques a la fonction
	   	#Permet de mettre les bons titres aux axes et de rappliquer un log aux donnees si besoin
		if ((func2.count("log")-func.count("log"))==2):
				debut_log="log(log("
				fin_log="))"
				data_temp=[data_temp[0],log(data_temp[1])]
				interp="exp(chaine+**{"+b1+"})"
		else:
				debut_log="log("
				fin_log=")"
				interp=chaine+"**{"+b1+"}"

		a=float(exp(data3[1][0]))
		b=float(data3[1][1])

		graph = displayGraphics.graphBuilder(name+" (generated on "+datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S)"),3,0,"log(x)","log(y)")

		graph.addTriangle(func.split("**")[-1],b1)

		graph.addFunction("y(x)="+func.replace(par_depend.getName(),'x'),"theoritical",color.rgb.red)
		graph.addFunction("y(x)="+str(a)+"*x**"+str(b),"practical",color.rgb.blue)

		graph.addPoints(data_temp,"data")

		graph.addInfo("$"+str(out.getAttrValues()[2])+"$"+" : "+"$"
                      +str(chaine)+"$"+"$\longrightarrow$"+"$"+func.replace("**","^")+"$",
                      "Interpolated : "+"$"+str(chaine)+"$"
					  +"$\longrightarrow$"+"$"+interp.replace("**","^")+"$",
                      temp,precision)

		print("[Validation] : writing "+ pathD+out.getName()+".pdf")
		graph.writePDFfile(pathD+out.getName())
	return result
Example #3
0
def data_interpol(name,param,out,xmlname,val_param,var,val_depend,precision,type,path):

	# Set properties of the defaulttexrunner, e.g. switch to LaTeX.
	text.set(mode="latex")

	data=[]
	for val_dep in val_depend[var]:
		list_param=[]
		val=[]
		for par in param:
			if (par.getName()!=var):
				list_param.append(par.getName())
				val.append(val_param[par.getName()][0])
			else:
				list_param.append(par.getName())
				val.append(val_dep)
				par_depend=par
		data.append(xmlParser.parse_xml_result(xmlname,name,list_param,val,out.getName()))
	data=map(float,data)
	val=map(float,val_depend[var])
	data_temp=[val,data]

	if (type==1):
		func=var
	elif (type==2):
		func="exp("+var+")"


	#Transformation des donnees pour affichage graphique
	data2=error.changedata(data_temp,func)
	a,b = error.fit(data2[0],data2[1])
	func2=error.changefunc(func)


	#On teste si le parametre variable contient une description latex
	if (par_depend.getAttrNames().count("latex")):
		chaine="$"+par_depend.getAttrValues()[3]+"$"
		func=func.replace("nu",par_depend.getAttrValues()[3])

		if (type==1):
			func_th="a*"+par_depend.getAttrValues()[3]+"**b"
			func=str(exp(b[0]))+"*"+var+"**"+str(b[1])
		elif (type==2):
			func_th="exp(a*"+par_depend.getAttrValues()[3]+"**b)"
			func="exp("+str(exp(b[0]))+"*"+var+"**"+str(b[1])+")"
	else:
		chaine=var
		if (type==1):
			func_th="a*"+chaine+"**b"
			func=str(exp(b[0]))+"*"+var+"**"+str(b[1])
		elif (type==2):
			func_th="exp(a*"+chaine+"**b)"
			func="exp("+str(exp(b[0]))+"*"+var+"**"+str(b[1])+")"
	print(b)
	b0=str(decimal.Decimal(str(round(exp(b[0]),3))))
	b1=str(decimal.Decimal(str(round(b[1],3))))
	print(b0,b1)

	graph = displayGraphics.graphBuilder(name+" (generated on "+datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S)"),0,1,"x","y")

	graph.addPoints(data_temp,"$"+out.getAttrValues()[2]+"$")
	graph.addFunction(func.replace(var,"x"),color.rgb.red,"Interpolated function",color.rgb.red)

	#x1,x2 = g.pos(min(data_temp[0])+0.1,max(data_temp[1]))
	#tbox0 =text.text(x1, x2+50*unit.x_pt,"$"+out.getAttrValues()[2]+"$"+" : "+chaine+"$\longrightarrow$"+"$"+func_th.replace("**","^")+"$")
	#tbox1 = text.text(x1, x2+30*unit.x_pt,"a : "+b0,[text.mathmode, text.valign.bottom])
	#tbox2  = text.text(x1, x2+10*unit.x_pt,"b : "+b1,[text.mathmode, text.valign.bottom])
	#c=canvas.canvas()
	#c.insert(tbox0)
	#c.insert(tbox1)
	#c.insert(tbox2)
	#g.insert(c)

	print("[Validation] : writing "+path+out.getName()+".pdf")

	graph.writePDFfile(path+out.getName())

	return 0
Example #4
0
def validation_code(name, param, output, xmlname, val_param, val_depend,
                    precision, pathD):
    result = 1
    for out in output:
        if len(out.getDependencies()) == 0:
            print "[Validation] error : no dependencies..."
            break
        depend = out.getDependencies()[0]
        func = out.getFuncs()[0]
        data = []
        for val_dep in val_depend[depend]:
            list_param = []
            val = []
            for par in param:
                if (par.getName() != depend):
                    list_param.append(par.getName())
                    val.append(val_param[par.getName()][0])
                else:
                    list_param.append(par.getName())
                    val.append(val_dep)
                    par_depend = par
            data.append(
                xmlParser.parse_xml_result(xmlname, name, list_param, val,
                                           out.getName()))

        data = map(float, data)
        val = map(float, val_depend[depend])
        data_temp = [val, data]

        temp = error.validation(data_temp, func, depend, precision)
        result = temp and result

        nb_decimal = len(str(precision)) - 1

        #Transformation des donnees pour affichage graphique
        data2 = error.changedata(data_temp, func)
        func2 = error.changefunc(func)
        data3 = error.fit(data2[0], data2[1])

        #On veut un certain nombre de chiffres significatifs pour les estimations
        #bo abscisse a l'origine et b1 pente
        b0 = str(decimal.Decimal(str(round(exp(data3[1][0]), nb_decimal))))
        b1 = str(decimal.Decimal(str(round(data3[1][1], nb_decimal))))

        #On teste si le parametre variable contient une description latex
        if (par_depend.getAttrNames().count("latex")):
            chaine = par_depend.getAttrValues()[3]
            func = func.replace(par_depend.getName(),
                                par_depend.getAttrValues()[3])
        else:
            chaine = depend

        #On teste le nombre de log appliques a la fonction
        #Permet de mettre les bons titres aux axes et de rappliquer un log aux donnees si besoin
        if ((func2.count("log") - func.count("log")) == 2):
            debut_log = "log(log("
            fin_log = "))"
            data_temp = [data_temp[0], log(data_temp[1])]
            interp = "exp(chaine+**{" + b1 + "})"
        else:
            debut_log = "log("
            fin_log = ")"
            interp = chaine + "**{" + b1 + "}"

        a = float(exp(data3[1][0]))
        b = float(data3[1][1])

        graph = displayGraphics.graphBuilder(
            name + " (generated on " +
            datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S)"), 3, 0,
            "log(x)", "log(y)")

        graph.addTriangle(func.split("**")[-1], b1)

        graph.addFunction("y(x)=" + func.replace(par_depend.getName(), 'x'),
                          "theoritical", color.rgb.red)
        graph.addFunction("y(x)=" + str(a) + "*x**" + str(b), "practical",
                          color.rgb.blue)

        graph.addPoints(data_temp, "data")

        graph.addInfo(
            "$" + str(out.getAttrValues()[2]) + "$" + " : " + "$" +
            str(chaine) + "$" + "$\longrightarrow$" + "$" +
            func.replace("**", "^") + "$",
            "Interpolated : " + "$" + str(chaine) + "$" + "$\longrightarrow$" +
            "$" + interp.replace("**", "^") + "$", temp, precision)

        print("[Validation] : writing " + pathD + out.getName() + ".pdf")
        graph.writePDFfile(pathD + out.getName())
    return result
Example #5
0
def data_interpol(name, param, out, xmlname, val_param, var, val_depend,
                  precision, type, path):

    # Set properties of the defaulttexrunner, e.g. switch to LaTeX.
    text.set(mode="latex")

    data = []
    for val_dep in val_depend[var]:
        list_param = []
        val = []
        for par in param:
            if (par.getName() != var):
                list_param.append(par.getName())
                val.append(val_param[par.getName()][0])
            else:
                list_param.append(par.getName())
                val.append(val_dep)
                par_depend = par
        data.append(
            xmlParser.parse_xml_result(xmlname, name, list_param, val,
                                       out.getName()))
    data = map(float, data)
    val = map(float, val_depend[var])
    data_temp = [val, data]

    if (type == 1):
        func = var
    elif (type == 2):
        func = "exp(" + var + ")"

    #Transformation des donnees pour affichage graphique
    data2 = error.changedata(data_temp, func)
    a, b = error.fit(data2[0], data2[1])
    func2 = error.changefunc(func)

    #On teste si le parametre variable contient une description latex
    if (par_depend.getAttrNames().count("latex")):
        chaine = "$" + par_depend.getAttrValues()[3] + "$"
        func = func.replace("nu", par_depend.getAttrValues()[3])

        if (type == 1):
            func_th = "a*" + par_depend.getAttrValues()[3] + "**b"
            func = str(exp(b[0])) + "*" + var + "**" + str(b[1])
        elif (type == 2):
            func_th = "exp(a*" + par_depend.getAttrValues()[3] + "**b)"
            func = "exp(" + str(exp(b[0])) + "*" + var + "**" + str(b[1]) + ")"
    else:
        chaine = var
        if (type == 1):
            func_th = "a*" + chaine + "**b"
            func = str(exp(b[0])) + "*" + var + "**" + str(b[1])
        elif (type == 2):
            func_th = "exp(a*" + chaine + "**b)"
            func = "exp(" + str(exp(b[0])) + "*" + var + "**" + str(b[1]) + ")"
    print(b)
    b0 = str(decimal.Decimal(str(round(exp(b[0]), 3))))
    b1 = str(decimal.Decimal(str(round(b[1], 3))))
    print(b0, b1)

    graph = displayGraphics.graphBuilder(
        name + " (generated on " +
        datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S)"), 0, 1, "x", "y")

    graph.addPoints(data_temp, "$" + out.getAttrValues()[2] + "$")
    graph.addFunction(func.replace(var, "x"), color.rgb.red,
                      "Interpolated function", color.rgb.red)

    #x1,x2 = g.pos(min(data_temp[0])+0.1,max(data_temp[1]))
    #tbox0 =text.text(x1, x2+50*unit.x_pt,"$"+out.getAttrValues()[2]+"$"+" : "+chaine+"$\longrightarrow$"+"$"+func_th.replace("**","^")+"$")
    #tbox1 = text.text(x1, x2+30*unit.x_pt,"a : "+b0,[text.mathmode, text.valign.bottom])
    #tbox2  = text.text(x1, x2+10*unit.x_pt,"b : "+b1,[text.mathmode, text.valign.bottom])
    #c=canvas.canvas()
    #c.insert(tbox0)
    #c.insert(tbox1)
    #c.insert(tbox2)
    #g.insert(c)

    print("[Validation] : writing " + path + out.getName() + ".pdf")

    graph.writePDFfile(path + out.getName())

    return 0
from pyx import *
from pyx.deco import barrow, earrow
from pyx.style import linewidth, linestyle
from pyx.graph.axis import *
from pyx.graph.axis import painter, tick

from scipy import *
from scipy.optimize import leastsq
#from scipy.io import array_import

from numpy import *

data = [[2, 3, 4], [7.0, 27.54, 74]]
func = 'x**3'
#func='exp(x**2)'
data2 = error.changedata(data, func)
func2 = error.changefunc(func)
#funcexp2=error.changefunc(funcexp)
print(data2)
print(func2)

data3 = error.slope_calc(data, func)
print(data3)

#V1 affichage sans utiliser nos fonctions
c = canvas.canvas()
g = c.insert(
    graph.graphxy(width=8,
                  x=graph.axis.log(min=1, max=10),
                  y=graph.axis.linear(min=1, max=10)))