{ "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 }