diff --git a/concentracao.py b/concentracao.py index fb0ae05fa5a9a1df40efacd0bc2ec301c55c5412..460b2aba02a22444d1b57034d859ec38f4697f7d 100644 --- a/concentracao.py +++ b/concentracao.py @@ -1,25 +1,56 @@ from pylab import * -u = 0 +#xy0 = np.loadtxt('H2.py') -def montaperfil( x, y , step, modo): +##################################################################################################### +# Funcoes que corrigem erros de arredondamento - profundidade = arange(0, len(x), step) +def fix1(y, x): + for k in arange(1, (len(y)-1)): + if y[k] == 0: + if y[k-1] and y[k+1] != 0: + y[k] = y[k-1] + +def fix2(y, x): + for k in arange(1, (len(y)-1)): + if y[k] == 0: + if y[k-1] and y[k+1] != 0: + if y[k-1] == y[k+1]: + y[k] = y[k-1] + else: + y[k] = (y[k+1]+y[k-1])/2 + +##################################################################################################### + +def montaperfil( xy , step, modo): + u = 0. + yu = 0. + + profundidade = arange(0, max(xy[:,0]), step) concent = profundidade*0 if modo == 'step': - global u - for i in x: - for j in arange (u, i, step): - concent[int(j/step)] = y[i] - u = i + for i in xy: + for j in arange (u, i[0], step): + if j>max(xy[:,0])/2 : + concent[math.ceil(j/step)] = i[1] + else : + concent[math.floor(j/step)] = i[1] + u = i[0] + fix1(concent, profundidade) if modo == 'reta': - global u - for i in x: - for j in arange (u, i, step): - concent[int(j/step)] = (j-u)*(y[i]-y[u])/(x[i]-x[u]) - u = i + for i in xy: + for j in arange (u, i[0], step): + if j>max(xy[:,0])/2 : + concent[math.ceil(j/step)] = yu + (j-u)*(i[1] - yu)/(i[0] - u) + else : + concent[math.floor(j/step)] = yu + (j-u)*(i[1] - yu)/(i[0] - u) + u = i[0] + yu = i[1] + fix2(concent, profundidade) + print concent plot(profundidade, concent) show() + diff --git a/prof.txt b/prof.txt new file mode 100644 index 0000000000000000000000000000000000000000..12e70f7bccba8ef40e3421a7181e5acd5ea5089c --- /dev/null +++ b/prof.txt @@ -0,0 +1,8 @@ +1 1 +2 0.5 +3 1 +4.3 0.7 +4.5 1 +5 0.9 +6 .1 + diff --git a/teste.py b/teste.py index b6cdf92f0439693c85bef91e05f995e8bdde49cd..0a534e3775d13dcc904648987b17ac6381c8e7f3 100644 --- a/teste.py +++ b/teste.py @@ -1,8 +1,12 @@ from concentracao import * +from pylab import * + +xy = np.loadtxt('prof.txt') -x,y = np.loadtxt('H2.py', unpack=True) modo = 'step' modo2 = 'reta' -montaperfil( x, y, 0.05, modo) -#montaperfil( x, y, 0.05, modo2) + +montaperfil( xy, 0.02, modo) +#montaperfil( xy, 0.02, modo2) +