-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_rfi_mask.py
116 lines (92 loc) · 3.11 KB
/
test_rfi_mask.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from __future__ import print_function
import matplotlib
matplotlib.use('Agg')
import pylab as plt
import simulate_l0
import numpy as np
from rpc_client import read_msgpack_file, RpcClient
from time import sleep
import subprocess
import os
from glob import glob
print('Deleting existing msgpack files...')
fns = glob('chunk-test-rfi-mask-*.msgpack')
for fn in fns:
print(' ', fn)
os.remove(fn)
l0 = simulate_l0.l0sim('l0_configs/l0_test_rfi.yml', 1.0)
client = RpcClient({'a':'tcp://127.0.0.1:5555'})
if True:
l1cmd = './ch-frb-l1 -fv l1_configs/l1_test_rfi.yml rfi_configs/rfi_testing.json bonsai_production_noups_nbeta1_v2.hdf5 xxx'
need_rfi = True
else:
l1cmd = './ch-frb-l1 -fv l1_configs/l1_test_norfi.yml rfi_configs/rfi_testing_no.json bonsai_production_noups_nbeta1_v2.hdf5 xxx'
need_rfi = False
l1 = subprocess.Popen(l1cmd, shell=True)
# wait until L1 is ready to receive
sleep(5)
beam_id = 0
fpga_counts_per_sample = 384
nt = 1024
nf = 16384
nrfi = 1024
nt_coarse = nt // 16
nf_coarse = 1024
chunk0 = 50
offset = np.empty((nf_coarse, nt_coarse), np.float32)
scale = np.empty((nf_coarse, nt_coarse), np.float32)
rfi = None
offset[:,:] = -128.
scale[:,:] = 1.
prom_cmd = 'wget http://127.0.0.1:9999/metrics -O -'
writereq = None
for i in range(20):
data = np.clip(128. + 20. * np.random.normal(size=(nf, nt)), 1, 254).astype(np.uint8)
# Make an RFI spike
#data[:, i*50:i*50+100] = 200
# in the frequency direction (where we have better counting)
data[i*50:i*50+100, :] = 200
ichunk = i + chunk0
ch = simulate_l0.assembled_chunk(beam_id, fpga_counts_per_sample, ichunk,
data, offset, scale, rfi)
#print('Chunk:', ch)
print('Sending chunk...')
l0.send_chunk(0, ch)
if i == 5:
os.system(prom_cmd)
print('After sending 5 chunks:')
print(client.get_statistics())
print('Sending write request...')
res = client.write_chunks([0], 0, (50 + 4) * 384 * 1024,
'chunk-test-rfi-mask-(FPGA0).msgpack', need_rfi=need_rfi,
waitAll=False)
print('Got write request result:', res)
reqs,token = res
writereq = reqs[0]
for c in writereq:
print(' ', c)
sleep(1)
if writereq is not None:
for c in writereq:
print('Status of', c.filename, ':', client.get_writechunk_status(c.filename))
# Give L1 some time to process...
sleep(2)
os.system(prom_cmd)
l1.terminate()
# Check contents of msgpack files.
fns = glob('chunk-test-rfi-mask-*.msgpack')
assert(len(fns) == 4)
fns.sort()
for i,fn in enumerate(fns):
chunk = read_msgpack_file(fn)
print('Chunk: ', chunk)
assert(chunk.rfi_mask is not None)
nf,nt = chunk.rfi_mask.shape
sample0 = chunk.fpga0 / chunk.fpga_counts_per_sample
plt.clf()
plt.imshow(chunk.rfi_mask, interpolation='nearest', origin='lower',
vmin=0, vmax=1, cmap='gray',
extent=[sample0, sample0+nt * chunk.binning, 0, nf])
fn = 'chunk-%i.png' % i
plt.savefig(fn)
print('Wrote', fn)