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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np, pandas as pd\n",
"import pickle\n",
"import os\n",
"\n",
"if not os.path.isdir(\"./lut_plot\"):\n",
" os.mkdir(\"./lut_plot\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def get_meas(path):\n",
" measurements = pickle.load(open(path, \"rb\"))\n",
" df = pd.DataFrame(measurements, columns=[\"ampl\",\"mag_gen_sq\",\"mag_feedback_sq\",\"phase_diff\"])\n",
" df[\"mag_gen\"] = np.sqrt(df[\"mag_gen_sq\"])\n",
" df[\"mag_feedback\"] = np.sqrt(df[\"mag_feedback_sq\"])\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = get_meas(\"./measurements.pkl\")\n",
"df_lut = get_meas(\"./measurements_lut.pkl\")\n",
"df_lut_sq = get_meas(\"./measurements_lut_sq.pkl\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def get_slope(ampl, mag_feedback):\n",
" slope, intersect = np.polyfit(x = ampl[0:20], y = mag_feedback[0:20], deg = 1)\n",
" return slope, intersect\n",
"\n",
"#get_slope(df[\"ampl\"], df[\"mag_feedback\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def get_fac(ampl, mag_feedback):\n",
" slope, intersect = get_slope(df[\"ampl\", df[\"mag_feedback\"]])\n",
" return[(x*slope + intersect) / y for (x,y) in zip(df[\"ampl\"], df[\"mag_feedback\"])]\n",
"def interp(x): return np.interp(x, df[\"ampl\"], fac)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace(0.1, 0.5, num = 50)\n",
"\n",
"plt.plot(df[\"ampl\"], df[\"mag_feedback\"], label=\"measurement\")\n",
"plt.plot(x, x*slope + intersect, label = \"linear model\")\n",
"\n",
"plt.legend(loc=0)\n",
"plt.title(\"Original Measurement\")\n",
"\n",
"plt.savefig(\"./lut_plot/original_measurement.png\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"slope, intersect = get_slope(df[\"ampl\"], df[\"mag_feedback\"])\n",
"\n",
"plt.plot(df_lut[\"ampl\"], df_lut[\"mag_feedback\"], label=\"measurement\")\n",
"plt.plot(x, x*slope + intersect, label = \"linear model\")\n",
"\n",
"plt.legend(loc=0)\n",
"plt.title(\"Lut Measurement\")\n",
"\n",
"plt.savefig(\"./lut_plot/lut_measurement.png\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"slope, intersect = get_slope(df[\"ampl\"], df[\"mag_feedback\"])\n",
"\n",
"plt.plot(df_lut_sq[\"ampl\"], df_lut_sq[\"mag_feedback\"], label=\"measurement\")\n",
"plt.plot(x, x*slope + intersect, label = \"linear model\")\n",
"\n",
"plt.legend(loc=0)\n",
"plt.title(\"Lut Squared Measurement\")\n",
"\n",
"plt.savefig(\"./lut_plot/lut_sq_measurement.png\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"slope, intersect = get_slope(df[\"ampl\"], df[\"mag_feedback\"])\n",
"\n",
"plt.plot(df[\"ampl\"], df[\"mag_feedback\"], label=\"measurement\")\n",
"plt.plot(df_lut[\"ampl\"], df_lut[\"mag_feedback\"], label=\"measurement lut\")\n",
"plt.plot(df_lut_sq[\"ampl\"], df_lut_sq[\"mag_feedback\"], label=\"measurement lut sq\")\n",
"plt.plot(x, x*slope + intersect, label = \"linear model\")\n",
"\n",
"plt.legend(loc=0)\n",
"plt.title(\"All Measurements\")\n",
"\n",
"plt.savefig(\"./lut_plot/all_measurement.png\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pickle.dump({\"ampl\":df[\"ampl\"],\"fac\":[f for f in fac]}, open(\"lut.pkl\", \"wb\"))\n",
"pickle.dump({\"ampl\":df[\"ampl\"],\"fac\":[f**2 for f in fac]}, open(\"lut_sq.pkl\", \"wb\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
|