concentracao.py 1.59 KB
Newer Older
Matheus Müller's avatar
Matheus Müller committed
1
2
from pylab import *

3
#xy0 = np.loadtxt('H2.py')
Matheus Müller's avatar
Matheus Müller committed
4

5
6
#####################################################################################################
# Funcoes que corrigem erros de arredondamento
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)
Matheus Müller's avatar
Matheus Müller committed
30
31
32
    concent = profundidade*0

    if modo == 'step':
33
34
35
36
37
38
39
40
        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)
Matheus Müller's avatar
Matheus Müller committed
41
42

    if modo == 'reta':
43
44
45
46
47
48
49
50
51
        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)    
Matheus Müller's avatar
Matheus Müller committed
52

53
    print concent
Matheus Müller's avatar
Matheus Müller committed
54
55
    plot(profundidade, concent)
    show()
56