-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_output_smart-v2020.01.28.py
55 lines (45 loc) · 1.57 KB
/
convert_output_smart-v2020.01.28.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Change log
# v2020.01.28
import numpy as np
var = 1
while var == 1:
name = input("Digite o nome do arquivo: ")
try:
with open(name, 'r')as row:
characters = row.read()
separator = characters[309]
if separator != ';':
delimiters = ','
else:
characters = characters.replace(',', '.')
with open(name, "w") as row:
row.write(characters)
delimiters = ';'
var = 0
except (IOError, OSError, NameError) as err:
print(err, 'arquivo não encontrado!. Digite novamente')
var = 1
all_data = np.loadtxt(name, delimiter=delimiters,
skiprows=4, usecols=(8, 4, 10, 11))
magnitude_and_phase_are_given = characters.find(
'Impedance Magnitude (Ohms)') != -1
current_index = 0
current_temperature = 0
vector = []
for index in range(len(all_data)):
temperature = all_data[index][0]
if temperature != current_temperature:
current_temperature = temperature
vector.append(index)
vector.append(len(all_data) - 1)
for i in range(len(vector) - 2):
matriz = all_data[vector[i]: vector[i+1], 1:4]
if magnitude_and_phase_are_given:
z_re = matriz[:, 1]*np.cos(np.radians(matriz[:, 2]))
z_im = matriz[:, 1]*np.sin(np.radians(matriz[:, 2]))
matriz[:, 1] = z_re
matriz[:, -1] = z_im
#print(all_data[vector[i]][0])
np.savetxt(str(all_data[vector[i]][0])+'.txt', matriz, delimiter=' ')
else:
np.savetxt(str(all_data[vector[i]][0])+'.txt', matriz, delimiter=' ')