Lucas Teske revised this gist 8 years ago. Go to revision
1 file changed, 35 insertions
molahisto.py(file created)
| @@ -0,0 +1,35 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | # -*- coding: utf-8 -*- | |
| 3 | + | from __future__ import unicode_literals | |
| 4 | + | ||
| 5 | + | import sys | |
| 6 | + | import numpy as np | |
| 7 | + | import matplotlib.mlab as mlab | |
| 8 | + | import matplotlib.pyplot as plt | |
| 9 | + | ||
| 10 | + | width = 20 # cm | |
| 11 | + | height = 15 # cm | |
| 12 | + | ||
| 13 | + | if len(sys.argv) < 4: | |
| 14 | + | print "Usage: molahisto.py data.txt title output" | |
| 15 | + | exit(1) | |
| 16 | + | ||
| 17 | + | type = sys.argv[2].decode(encoding='UTF-8',errors='strict') | |
| 18 | + | output = sys.argv[3] | |
| 19 | + | ||
| 20 | + | data = np.fromfile(sys.argv[1], sep='\n') | |
| 21 | + | ||
| 22 | + | num_bins = 8 | |
| 23 | + | ||
| 24 | + | fig, ax = plt.subplots() | |
| 25 | + | n, bins, patches = ax.hist(data, num_bins, color='burlywood', histtype='stepfilled') | |
| 26 | + | ||
| 27 | + | ax.set_xlabel('Constante Elástica (N/m)') | |
| 28 | + | ax.set_ylabel('Contagem') | |
| 29 | + | ax.set_title('%s' %type) | |
| 30 | + | ax.set_ylim( None, n.max() * 1.2) | |
| 31 | + | ||
| 32 | + | fig.tight_layout() | |
| 33 | + | ||
| 34 | + | fig.set_size_inches(width / 2.54, height / 2.54) | |
| 35 | + | plt.savefig('%s.png' %output, dpi=100) | |
Lucas Teske revised this gist 8 years ago. Go to revision
1 file changed, 31 insertions, 10 deletions
super.py
| @@ -1,7 +1,5 @@ | |||
| 1 | 1 | #!/usr/bin/env python | |
| 2 | 2 | # -*- coding: utf-8 -*- | |
| 3 | - | ||
| 4 | - | # Just saving this, because it works beautifully, but its crap because it isn't what teacher asked :(( | |
| 5 | 3 | from __future__ import unicode_literals | |
| 6 | 4 | ||
| 7 | 5 | import sys | |
| @@ -17,7 +15,7 @@ if len(sys.argv) < 4: | |||
| 17 | 15 | def GenHistogram(data, output, type, unit, title): | |
| 18 | 16 | width = 20 # cm | |
| 19 | 17 | height = 15 # cm | |
| 20 | - | num_bins = max(len(data) / 3, 2) | |
| 18 | + | num_bins = min(max(len(data) / 3, 2), 12) | |
| 21 | 19 | avg = np.average(data) | |
| 22 | 20 | std = np.std(data) | |
| 23 | 21 | ||
| @@ -40,6 +38,25 @@ def GenHistogram(data, output, type, unit, title): | |||
| 40 | 38 | fig.set_size_inches(width / 2.54, height / 2.54) | |
| 41 | 39 | plt.savefig('%s.png' %output, dpi=100) | |
| 42 | 40 | ||
| 41 | + | def GenSigmaChart(data, output, type, std): | |
| 42 | + | #Tstd, "%s-sigma" %(output), 'Tempo de Queda' | |
| 43 | + | width = 20 # cm | |
| 44 | + | height = 15 # cm | |
| 45 | + | x = [2**i for i in range(len(data))] | |
| 46 | + | s = std / np.sqrt(x) | |
| 47 | + | fig, ax = plt.subplots() | |
| 48 | + | ax.plot(x, data, label="Calculado") | |
| 49 | + | ax.plot(x, s, label="Teórico") | |
| 50 | + | ||
| 51 | + | ax.set_xlabel('Número de Amostras usadas na média') | |
| 52 | + | ax.set_ylabel('Desvio Padrão') | |
| 53 | + | ax.set_title('Desvio Padrão da Média de %s' %type) | |
| 54 | + | ||
| 55 | + | legend = ax.legend(loc='upper right', shadow=True, prop={'size':10}) | |
| 56 | + | fig.tight_layout() | |
| 57 | + | ||
| 58 | + | fig.set_size_inches(width / 2.54, height / 2.54) | |
| 59 | + | plt.savefig('%s.png' %output, dpi=100) | |
| 43 | 60 | ||
| 44 | 61 | deltaS = 34 # metros | |
| 45 | 62 | ||
| @@ -57,7 +74,7 @@ Tavg = [] | |||
| 57 | 74 | Vavg = [] | |
| 58 | 75 | Aavg = [] | |
| 59 | 76 | ||
| 60 | - | for i in range(1,6): | |
| 77 | + | for i in range(0,6): | |
| 61 | 78 | n = 2**i | |
| 62 | 79 | arrT = [] | |
| 63 | 80 | arrV = [] | |
| @@ -77,9 +94,9 @@ for i in range(1,6): | |||
| 77 | 94 | avgT = 0 | |
| 78 | 95 | avgV = 0 | |
| 79 | 96 | avgA = 0 | |
| 97 | + | if z+n >= len(data): | |
| 98 | + | break; | |
| 80 | 99 | for k in range(0, n): | |
| 81 | - | if z+k >= len(data): | |
| 82 | - | break | |
| 83 | 100 | avgT += data[z+k] | |
| 84 | 101 | avgV += dataV[z+k] | |
| 85 | 102 | avgA += dataA[z+k] | |
| @@ -108,12 +125,16 @@ for i in range(1,6): | |||
| 108 | 125 | Vstd.append(np.std(npV)) | |
| 109 | 126 | Astd.append(np.std(npA)) | |
| 110 | 127 | ||
| 111 | - | GenHistogram(npT, "%s-%s-T" %(output, n), 'Tempo de Queda', 's', 'Histograma de Tempo de Queda Média N=%s (%s)' %(n, type)) | |
| 112 | - | GenHistogram(npV, "%s-%s-V" %(output, n), 'Velocidade', 'm/s', 'Histograma de Velocidade Média N=%s (%s)' %(n, type)) | |
| 113 | - | GenHistogram(npA, "%s-%s-A" %(output, n), 'Aceleração', 'm/s²', 'Histograma de Aceleração Média N=%s (%s)' %(n, type)) | |
| 128 | + | print "Salvando Gráfico de Histograma do Tempo de Queda" | |
| 129 | + | GenHistogram(npT, "%s-%s-hist" %(output, n), 'Tempo de Queda', 's', 'Histograma de Tempo de Queda Média N=%s (%s)' %(n, type)) | |
| 114 | 130 | ||
| 115 | 131 | Tavg.append(np.average(npT)) | |
| 116 | 132 | Vavg.append(np.average(npV)) | |
| 117 | 133 | Aavg.append(np.average(npA)) | |
| 118 | 134 | ||
| 119 | - | print Tstd, Vstd, Astd | |
| 135 | + | ||
| 136 | + | print "Desenhando gráfico sigma" | |
| 137 | + | ||
| 138 | + | GenSigmaChart(Tstd, "%s-sigma" %(output), 'Tempo de Queda (%s)' %type, np.std(data)) | |
| 139 | + | ||
| 140 | + | ||
Lucas Teske revised this gist 8 years ago. Go to revision
1 file changed, 119 insertions
super.py(file created)
| @@ -0,0 +1,119 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | # -*- coding: utf-8 -*- | |
| 3 | + | ||
| 4 | + | # Just saving this, because it works beautifully, but its crap because it isn't what teacher asked :(( | |
| 5 | + | from __future__ import unicode_literals | |
| 6 | + | ||
| 7 | + | import sys | |
| 8 | + | import numpy as np | |
| 9 | + | import matplotlib.mlab as mlab | |
| 10 | + | import matplotlib.pyplot as plt | |
| 11 | + | ||
| 12 | + | ||
| 13 | + | if len(sys.argv) < 4: | |
| 14 | + | print "Usage: generate.py data.txt type output" | |
| 15 | + | exit(1) | |
| 16 | + | ||
| 17 | + | def GenHistogram(data, output, type, unit, title): | |
| 18 | + | width = 20 # cm | |
| 19 | + | height = 15 # cm | |
| 20 | + | num_bins = max(len(data) / 3, 2) | |
| 21 | + | avg = np.average(data) | |
| 22 | + | std = np.std(data) | |
| 23 | + | ||
| 24 | + | fig, ax = plt.subplots() | |
| 25 | + | n, bins, patches = ax.hist(data, num_bins, color='burlywood', histtype='stepfilled') | |
| 26 | + | ||
| 27 | + | ax.axvline(avg, color='red', label="Média = %.2f %s" % (avg, unit)) | |
| 28 | + | ax.axvline(avg-std, color='lightblue', label="Média - Desvio Padrão = %.2f %s" %(avg-std, unit)) | |
| 29 | + | ax.axvline(avg+std, color='darkblue', label="Média + Desvio Padrão = %.2f %s" % (avg+std, unit)) | |
| 30 | + | ||
| 31 | + | plt.text(0.025, 0.8, r'$\sigma = %.2f$' % std, transform = ax.transAxes) | |
| 32 | + | ax.set_xlabel('%s (%s)' %(type, unit)) | |
| 33 | + | ax.set_ylabel('Contagem (n)') | |
| 34 | + | ax.set_title('%s' %title) | |
| 35 | + | ax.set_ylim( None, n.max() * 1.2) | |
| 36 | + | ||
| 37 | + | legend = ax.legend(loc='upper left', shadow=True, prop={'size':10}) | |
| 38 | + | fig.tight_layout() | |
| 39 | + | ||
| 40 | + | fig.set_size_inches(width / 2.54, height / 2.54) | |
| 41 | + | plt.savefig('%s.png' %output, dpi=100) | |
| 42 | + | ||
| 43 | + | ||
| 44 | + | deltaS = 34 # metros | |
| 45 | + | ||
| 46 | + | type = sys.argv[2].decode(encoding='UTF-8',errors='strict') | |
| 47 | + | output = sys.argv[3] | |
| 48 | + | data = np.fromfile(sys.argv[1], sep='\n') | |
| 49 | + | dataV = deltaS / data | |
| 50 | + | dataA = (2 * deltaS) / (data ** 2) | |
| 51 | + | ||
| 52 | + | Tstd = [] | |
| 53 | + | Vstd = [] | |
| 54 | + | Astd = [] | |
| 55 | + | ||
| 56 | + | Tavg = [] | |
| 57 | + | Vavg = [] | |
| 58 | + | Aavg = [] | |
| 59 | + | ||
| 60 | + | for i in range(1,6): | |
| 61 | + | n = 2**i | |
| 62 | + | arrT = [] | |
| 63 | + | arrV = [] | |
| 64 | + | arrA = [] | |
| 65 | + | ||
| 66 | + | print "Calculando para %s" %n | |
| 67 | + | filenameT = "o/%s-%s-t.txt" %(output, n) | |
| 68 | + | filenameV = "o/%s-%s-v.txt" %(output, n) | |
| 69 | + | filenameA = "o/%s-%s-a.txt" %(output, n) | |
| 70 | + | ||
| 71 | + | print "Salvando em %s %s %s" % (filenameT, filenameV, filenameA) | |
| 72 | + | fT = open(filenameT, "w") | |
| 73 | + | fV = open(filenameV, "w") | |
| 74 | + | fA = open(filenameA, "w") | |
| 75 | + | ||
| 76 | + | for z in range(0, len(data), n): | |
| 77 | + | avgT = 0 | |
| 78 | + | avgV = 0 | |
| 79 | + | avgA = 0 | |
| 80 | + | for k in range(0, n): | |
| 81 | + | if z+k >= len(data): | |
| 82 | + | break | |
| 83 | + | avgT += data[z+k] | |
| 84 | + | avgV += dataV[z+k] | |
| 85 | + | avgA += dataA[z+k] | |
| 86 | + | ||
| 87 | + | avgT /= n | |
| 88 | + | avgV /= n | |
| 89 | + | avgA /= n | |
| 90 | + | ||
| 91 | + | arrT.append(avgT) | |
| 92 | + | arrV.append(avgV) | |
| 93 | + | arrA.append(avgA) | |
| 94 | + | ||
| 95 | + | fT.write("%.2f\n" %avgT) | |
| 96 | + | fV.write("%.2f\n" %avgV) | |
| 97 | + | fA.write("%.2f\n" %avgA) | |
| 98 | + | ||
| 99 | + | fT.close() | |
| 100 | + | fV.close() | |
| 101 | + | fA.close() | |
| 102 | + | ||
| 103 | + | npT = np.array(arrT) | |
| 104 | + | npV = np.array(arrV) | |
| 105 | + | npA = np.array(arrA) | |
| 106 | + | ||
| 107 | + | Tstd.append(np.std(npT)) | |
| 108 | + | Vstd.append(np.std(npV)) | |
| 109 | + | Astd.append(np.std(npA)) | |
| 110 | + | ||
| 111 | + | GenHistogram(npT, "%s-%s-T" %(output, n), 'Tempo de Queda', 's', 'Histograma de Tempo de Queda Média N=%s (%s)' %(n, type)) | |
| 112 | + | GenHistogram(npV, "%s-%s-V" %(output, n), 'Velocidade', 'm/s', 'Histograma de Velocidade Média N=%s (%s)' %(n, type)) | |
| 113 | + | GenHistogram(npA, "%s-%s-A" %(output, n), 'Aceleração', 'm/s²', 'Histograma de Aceleração Média N=%s (%s)' %(n, type)) | |
| 114 | + | ||
| 115 | + | Tavg.append(np.average(npT)) | |
| 116 | + | Vavg.append(np.average(npV)) | |
| 117 | + | Aavg.append(np.average(npA)) | |
| 118 | + | ||
| 119 | + | print Tstd, Vstd, Astd | |
Lucas Teske revised this gist 8 years ago. Go to revision
2 files changed, 97 insertions
grafa.py(file created)
| @@ -0,0 +1,49 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | # -*- coding: utf-8 -*- | |
| 3 | + | from __future__ import unicode_literals | |
| 4 | + | ||
| 5 | + | import sys | |
| 6 | + | import numpy as np | |
| 7 | + | import matplotlib.mlab as mlab | |
| 8 | + | import matplotlib.pyplot as plt | |
| 9 | + | ||
| 10 | + | width = 20 # cm | |
| 11 | + | height = 15 # cm | |
| 12 | + | ||
| 13 | + | deltaS = 34 # metros | |
| 14 | + | ||
| 15 | + | ||
| 16 | + | if len(sys.argv) < 4: | |
| 17 | + | print "Usage: generate.py data.txt type output" | |
| 18 | + | exit(1) | |
| 19 | + | ||
| 20 | + | type = sys.argv[2].decode(encoding='UTF-8',errors='strict') | |
| 21 | + | output = sys.argv[3] | |
| 22 | + | ||
| 23 | + | data = np.fromfile(sys.argv[1], sep='\n') | |
| 24 | + | ||
| 25 | + | data = (2 * 34) / (data ** 2) | |
| 26 | + | ||
| 27 | + | num_bins = 12 | |
| 28 | + | avg = np.average(data) | |
| 29 | + | std = np.std(data) | |
| 30 | + | ||
| 31 | + | fig, ax = plt.subplots() | |
| 32 | + | n, bins, patches = ax.hist(data, num_bins, color='burlywood', histtype='stepfilled') | |
| 33 | + | ||
| 34 | + | print "Média: %s Desvio Padrão: %s" %(avg, std) | |
| 35 | + | ||
| 36 | + | ax.axvline(avg, color='red', label="Média = %.2f m/s²" %avg) | |
| 37 | + | ax.axvline(avg-std, color='lightblue', label="Média - Desvio Padrão = %.2f m/s²" %(avg-std)) | |
| 38 | + | ax.axvline(avg+std, color='darkblue', label="Média + Desvio Padrão = %.2f m/s²" % (avg+std)) | |
| 39 | + | ||
| 40 | + | ax.set_xlabel('Aceleração (m/s²)') | |
| 41 | + | ax.set_ylabel('Contagem (n)') | |
| 42 | + | ax.set_title('Histograma das Acelerações Médias (%s)' %type) | |
| 43 | + | ax.set_ylim( None, n.max() * 1.2) | |
| 44 | + | ||
| 45 | + | legend = ax.legend(loc='upper left', shadow=True, prop={'size':10}) | |
| 46 | + | fig.tight_layout() | |
| 47 | + | ||
| 48 | + | fig.set_size_inches(width / 2.54, height / 2.54) | |
| 49 | + | plt.savefig('%s.png' %output, dpi=100) | |
grafv.py(file created)
| @@ -0,0 +1,48 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | # -*- coding: utf-8 -*- | |
| 3 | + | from __future__ import unicode_literals | |
| 4 | + | ||
| 5 | + | import sys | |
| 6 | + | import numpy as np | |
| 7 | + | import matplotlib.mlab as mlab | |
| 8 | + | import matplotlib.pyplot as plt | |
| 9 | + | ||
| 10 | + | width = 20 # cm | |
| 11 | + | height = 15 # cm | |
| 12 | + | ||
| 13 | + | deltaS = 34 # metros | |
| 14 | + | ||
| 15 | + | if len(sys.argv) < 4: | |
| 16 | + | print "Usage: generate.py data.txt type output" | |
| 17 | + | exit(1) | |
| 18 | + | ||
| 19 | + | type = sys.argv[2].decode(encoding='UTF-8',errors='strict') | |
| 20 | + | output = sys.argv[3] | |
| 21 | + | ||
| 22 | + | data = np.fromfile(sys.argv[1], sep='\n') | |
| 23 | + | ||
| 24 | + | data = deltaS / data | |
| 25 | + | ||
| 26 | + | num_bins = 12 | |
| 27 | + | avg = np.average(data) | |
| 28 | + | std = np.std(data) | |
| 29 | + | ||
| 30 | + | fig, ax = plt.subplots() | |
| 31 | + | n, bins, patches = ax.hist(data, num_bins, color='burlywood', histtype='stepfilled') | |
| 32 | + | ||
| 33 | + | print "Média: %s Desvio Padrão: %s" %(avg, std) | |
| 34 | + | ||
| 35 | + | ax.axvline(avg, color='red', label="Média = %.2f m/s" %avg) | |
| 36 | + | ax.axvline(avg-std, color='lightblue', label="Média - Desvio Padrão = %.2f m/s" %(avg-std)) | |
| 37 | + | ax.axvline(avg+std, color='darkblue', label="Média + Desvio Padrão = %.2f m/s" % (avg+std)) | |
| 38 | + | ||
| 39 | + | ax.set_xlabel('Velocidade (m/s)') | |
| 40 | + | ax.set_ylabel('Contagem (n)') | |
| 41 | + | ax.set_title('Histograma das Velocidades Médias (%s)' %type) | |
| 42 | + | ax.set_ylim( None, n.max() * 1.2) | |
| 43 | + | ||
| 44 | + | legend = ax.legend(loc='upper left', shadow=True, prop={'size':10}) | |
| 45 | + | fig.tight_layout() | |
| 46 | + | ||
| 47 | + | fig.set_size_inches(width / 2.54, height / 2.54) | |
| 48 | + | plt.savefig('%s.png' %output, dpi=100) | |
Lucas Teske revised this gist 8 years ago. Go to revision
1 file changed, 44 insertions
generate.py(file created)
| @@ -0,0 +1,44 @@ | |||
| 1 | + | #!/usr/bin/env python | |
| 2 | + | # -*- coding: utf-8 -*- | |
| 3 | + | from __future__ import unicode_literals | |
| 4 | + | ||
| 5 | + | import sys | |
| 6 | + | import numpy as np | |
| 7 | + | import matplotlib.mlab as mlab | |
| 8 | + | import matplotlib.pyplot as plt | |
| 9 | + | ||
| 10 | + | width = 20 # cm | |
| 11 | + | height = 15 # cm | |
| 12 | + | ||
| 13 | + | if len(sys.argv) < 4: | |
| 14 | + | print "Usage: generate.py data.txt title output" | |
| 15 | + | exit(1) | |
| 16 | + | ||
| 17 | + | output = sys.argv[3] | |
| 18 | + | title = sys.argv[2].decode(encoding='UTF-8',errors='strict') | |
| 19 | + | ||
| 20 | + | data = np.fromfile(sys.argv[1], sep='\n') | |
| 21 | + | ||
| 22 | + | num_bins = 28 | |
| 23 | + | avg = np.average(data) | |
| 24 | + | std = np.std(data) | |
| 25 | + | ||
| 26 | + | fig, ax = plt.subplots() | |
| 27 | + | n, bins, patches = ax.hist(data, num_bins, color='burlywood', histtype='stepfilled') | |
| 28 | + | ||
| 29 | + | print "Média: %s Desvio Padrão: %s" %(avg, std) | |
| 30 | + | ||
| 31 | + | ax.axvline(avg, color='red', label="Média = %.2f s" %avg) | |
| 32 | + | ax.axvline(avg-std, color='lightblue', label="Média - Desvio Padrão = %.2f s" %(avg-std)) | |
| 33 | + | ax.axvline(avg+std, color='darkblue', label="Média + Desvio Padrão = %.2f s" % (avg+std)) | |
| 34 | + | ||
| 35 | + | ax.set_xlabel('Tempo (s)') | |
| 36 | + | ax.set_ylabel('Contagem (n)') | |
| 37 | + | ax.set_title(title) | |
| 38 | + | ax.set_ylim( None, n.max() * 1.2) | |
| 39 | + | ||
| 40 | + | legend = ax.legend(loc='upper left', shadow=True, prop={'size':10}) | |
| 41 | + | fig.tight_layout() | |
| 42 | + | ||
| 43 | + | fig.set_size_inches(width / 2.54, height / 2.54) | |
| 44 | + | plt.savefig('%s.png' %output, dpi=100) | |