-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirfile_functions.py
More file actions
124 lines (114 loc) · 4.88 KB
/
dirfile_functions.py
File metadata and controls
124 lines (114 loc) · 4.88 KB
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
117
118
119
120
121
122
123
import numpy as np
import pygetdata as gd
import matplotlib.pyplot as plt
#import pykst as kst
fs = 488.28125 # Hz
def loadIQAllChan(dirfile, nsec):
nframes = np.int(nsec * fs)
d = gd.dirfile(dirfile, gd.RDWR|gd.UNENCODED)
vectors = d.field_list()
ifiles = [v for v in vectors if v[0] == "i" and v != "INDEX"]
qfiles = [v for v in vectors if v[0] == "q" and v != "INDEX"]
ifiles = sorted(ifiles, key=lambda x: x.split('_')[1])
qfiles = sorted(qfiles, key=lambda x: x.split('_')[1])
ivals, qvals = [], []
for i in range(len(ifiles)):
ivals.append(d.getdata(ifiles[i], gd.FLOAT32, num_frames = nframes))
qvals.append(d.getdata(qfiles[i], gd.FLOAT32, num_frames = nframes))
d.close()
ivals = np.asarray(ivals)
qvals = np.asarray(qvals)
return ivals, qvals
def loadArbData(dirfile, file):
d = gd.dirfile(dirfile, gd.RDWR|gd.UNENCODED)
vectors = d.field_list()
for i in range (len(vectors)):
if vectors[i] == file:
values = d.getdata(file, gd.UINT16, num_frames = d.nframes)
return np.asarray(values, dtype = 'int')
def avg_arrays(how_long, array):
counter = 0
current_sum = 0.
out_array = []
for i in range(len(array)):
current_sum += array[i]
counter += 1
print counter, current_sum
if counter == how_long:
counter = 0
print current_sum/how_long
out_array.append(float(current_sum/how_long))
current_sum = 0.
return out_array
def loadIQsingleChan(dirfile, chan):
d = gd.dirfile(dirfile, gd.RDWR|gd.UNENCODED)
vectors = d.field_list()
ifiles = [v for v in vectors if v[0] == "i" and v != "INDEX"]
qfiles = [v for v in vectors if v[0] == "q" and v != "INDEX"]
ifiles = sorted(ifiles, key=lambda x: x.split('_')[1])
qfiles = sorted(qfiles, key=lambda x: x.split('_')[1])
print ifiles[chan], qfiles[chan]
ivals = d.getdata(ifiles[chan], gd.FLOAT32, num_frames = d.nframes)
qvals = d.getdata(qfiles[chan], gd.FLOAT32, num_frames = d.nframes)
d.close()
return np.asarray(ivals, dtype = 'float'), np.asarray(qvals, dtype = 'float')
def avgAllChan(dirfile):
d = gd.dirfile(dirfile, gd.RDWR|gd.UNENCODED)
vectors = d.field_list()
ifiles = [v for v in vectors if v[0] == "i" and v != "INDEX"]
qfiles = [v for v in vectors if v[0] == "q" and v != "INDEX"]
ifiles = sorted(ifiles, key=lambda x: x.split('_')[1])
qfiles = sorted(qfiles, key=lambda x: x.split('_')[1])
ivals = np.zeros(d.nframes)
qvals = np.zeros(d.nframes)
count = 0
for chan in range(len(ifiles)):
print count
ivals += d.getdata(ifiles[chan], gd.FLOAT32, num_frames = d.nframes)
qvals += d.getdata(qfiles[chan], gd.FLOAT32, num_frames = d.nframes)
count += 1
d.close()
return np.asarray(ivals, dtype = 'float'), np.asarray(qvals, dtype = 'float')
def loadChanPhase(dirfile, chan):
d = gd.dirfile(dirfile, gd.RDWR|gd.UNENCODED)
vectors = d.field_list()
ifiles = [v for v in vectors if v[0] == "i" and v != "INDEX"]
qfiles = [v for v in vectors if v[0] == "q" and v != "INDEX"]
ifiles = sorted(ifiles, key=lambda x: x.split('_')[1])
qfiles = sorted(qfiles, key=lambda x: x.split('_')[1])
ivals = d.getdata(ifiles[chan], gd.FLOAT32, num_frames = d.nframes)
qvals = d.getdata(qfiles[chan], gd.FLOAT32, num_frames = d.nframes)
d.close()
phi_rot = np.arctan2(np.mean(qvals), np.mean(ivals))
s21 = ivals + 1j*qvals
s21_rot = s21 * np.exp(-1j * phi_rot)
phase = np.angle(s21_rot)
return np.asarray(phase, dtype = 'float')
def loadChanPhaseRange(dirfile, chan, first_sample, num_samples):
d = gd.dirfile(dirfile, gd.RDWR|gd.UNENCODED)
vectors = d.field_list()
ifiles = [v for v in vectors if v[0] == "i" and v != "INDEX"]
qfiles = [v for v in vectors if v[0] == "q" and v != "INDEX"]
ifiles = sorted(ifiles, key=lambda x: x.split('_')[1])
qfiles = sorted(qfiles, key=lambda x: x.split('_')[1])
ivals = d.getdata(ifiles[chan], gd.FLOAT32,
first_sample = first_sample, num_samples = num_samples)
qvals = d.getdata(qfiles[chan], gd.FLOAT32,
first_sample = first_sample, num_samples = num_samples)
d.close()
phi_rot = np.arctan2(np.mean(qvals), np.mean(ivals))
s21 = ivals + 1j*qvals
s21_rot = s21 * np.exp(-1j * phi_rot)
phase = np.angle(s21_rot)
return np.asarray(phase, dtype = 'float')
#def plotVectorKst(x, y, xname, yname):
# start a kst session with the arbitrary name "NumpyVector"
#client=kst.Client("Vector")
# copy the numpy arrays into kst
#V1 = client.new_editable_vector(x, name=xname) # the name is for the label
#V2 = client.new_editable_vector(y, name=yname) # the name is for the label
# inside kst, create a curve, a plot, and add the curve to the plot
#c1 = client.new_curve(V1, V2)
#p1 = client.new_plot()
#p1.add(c1)
#return