-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_write.py
93 lines (61 loc) · 1.49 KB
/
read_write.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
import numpy as np
import builtins as blt
import sys
def write_vis(filename, data):
orig_stdout = sys.stdout
f = open(filename, 'w')
sys.stdout = f
for ii in range (0, N_c):
nu = nu_c - (B_bw/2.0) + ii * dnu_c
lam = C/nu
for jj in range (0, Nbl):
U = (jj+1)*d/lam
print("%d\t"%(jj+1),"%f\t"%U,"%e\t"%data[jj,ii].real,"%e\t"%data[jj,ii].imag)
sys.stdout = orig_stdout
f.close()
def read_vis(filename):
data = np.loadtxt(filename)
print(data.shape)
mm , nn = data.shape
Nchan = int(mm/Nbl)
V = np.zeros([Nbl, Nchan],dtype = 'complex_')
B = int(0)
N = int(0)
for ii in range (0, mm):
V[B, N] = data[ii, nn-2] + 1j*data[ii, nn-1]
#V[B, N].real = data[ii, 2]
#V[B, N].imag = data[ii, 3]
B = B+1
if (B == Nbl):
N = N + 1
B = 0
return (V)
def mod_format_vis(data):
#data = np.loadtxt(filename)
mm, nn =data.shape
Nchan = int(mm/Nbl)
V = np.zeros([Nbl, Nchan],dtype = 'complex_')
#mm = data.shape
B = int(0)
N = int(0)
for ii in range (0, mm):
V[B, N] = data[ii]
#V[B, N].real = data[ii, 2]
#V[B, N].imag = data[ii, 3]
B = B+1
if (B == Nbl):
N = N + 1
B = 0
return (V)
def reduce_chan(data, Nchan, keep_bandwidth=True):
bl, nc = data.shape
V = np.zeros([bl, Nchan],dtype = 'complex_')
if (keep_bandwidth==True):
nf = int(nc/Nchan)
for ii in range (0, Nchan):
V[:, ii] = data[:, nf*ii]
else:
ns = int(nc/2 - Nchan/2)
for ii in range (0, Nchan):
V[:, ii] = data[:, ns+ii]
return(V)