capacitor_bank_analysis.py
|
1 import csv
2 import pandas as pd
3
4 import scripts.capacitor_bank as cb
5
6
7 combinations = {
8 'comb1': ((1,), (cb.Z_st1,)),
9 'comb2': ((1, 2), (cb.Z_st1, cb.Z_st2)),
10 'comb3': ((1, 3), (cb.Z_st1, cb.Z_st3)),
11 'comb4': ((1, 2, 3), (cb.Z_st1, cb.Z_st2, cb.Z_st3)),
12 'comb5': ((1, 3, 4), (cb.Z_st1, cb.Z_st3, cb.Z_st4)),
13 'comb6': ((1, 2, 3, 4), (cb.Z_st1, cb.Z_st2, cb.Z_st3, cb.Z_st4))
14 }
15
16
17 def analyze(fp='../data/measurements.csv'):
18 results = []
19 with open(fp) as csv_file:
20 reader = csv.reader(csv_file)
21 for i, row in enumerate(reader):
22 if i == 0:
23 continue
24 time = pd.to_datetime(row[0])
25 comb_objs = _calculate_combinations(U_1=float(row[1]), I_1=float(row[2]), I_h=[float(v) for v in row[3:]])
26 sub_results = _check_combinations(time, comb_objs)
27 if sub_results:
28 results.extend(sub_results)
29 return pd.DataFrame(results)
30
31
32 def _calculate_combinations(U_1, I_1, I_h):
33 return [
34 cb.Combination(
35 name=key,
36 stages=val[0],
37 Z_stages=val[1],
38 U_l1=U_1,
39 I_l1=I_1,
40 I_lh=I_h
41 )
42 for key, val in combinations.items()
43 ]
44
45
46 def _check_combinations(time, comb_objs, I_rms_max=15.70):
47 results = []
48 for comb_obj in comb_objs:
49 index = comb_obj.I_df['RMS'].index
50 values = comb_obj.I_df['RMS']
51 for i, I_rms in zip(index, values):
52 if i in ('I1', 'I2'):
53 if I_rms >= I_rms_max:
54 results.append({'time': time, 'combination': comb_obj.name, 'stage': i, 'Irms': I_rms})
55 if i in ('I3', 'I4'):
56 if I_rms >= I_rms_max * 2.0:
57 results.append({'time': time, 'combination': comb_obj.name, 'stage': i, 'Irms': I_rms})
58 return results
59
60
61 if __name__ == '__main__':
62 results = analyze()
63 print(results)
64