File size: 1,699 Bytes
7df9186 | 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 56 57 58 59 60 61 62 63 64 | import numpy as np
from numpy import angle as ang
import sys
from matplotlib import pyplot as plt
def read():
A = np.loadtxt('cryomodule_p.dat')
cav = A[:, 0] + 1j*A[:, 1]
fwd = A[:, 2] + 1j*A[:, 3]
rfl = A[:, 4] + 1j*A[:, 5]
return cav, fwd, rfl
def show(data, f_cvt=abs):
cav, fwd, rfl = data
plt.plot(f_cvt(cav), label='cav')
plt.plot(f_cvt(fwd), label='fwd')
plt.plot(f_cvt(rfl), label='rfl')
plt.legend()
plt.show()
def fail_pass(condition):
if not condition:
print('FAIL')
sys.exit(1)
else:
print('PASS')
def check_err(test_val, bound, err):
check = abs(test_val - bound) < err
print(test_val, bound, err, check)
return check
def make_check(data):
cav, fwd, rfl = data
cav_len = len(cav) // 2
err_bar = 5
fail_pass(check_err(abs(cav[cav_len]), 1934, err_bar) and
check_err(abs(fwd[cav_len]), 1318, err_bar) and
check_err(abs(rfl[cav_len]), 847, err_bar))
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='cryomodule')
parser.add_argument('-c', '--check', action='store_true', default=True,
help='Purely run the check')
parser.add_argument('-s', '--show', action='store_true',
help='Show plots first and then run the check')
parser.add_argument('-p', '--phase', action='store_true',
help='Choose phase instead of default magnitude plot')
args = parser.parse_args()
data = read()
if args.show:
show(data, f_cvt=ang if args.phase else abs)
make_check(data)
else:
make_check(data)
|