diff options
author | andreas128 <Andreas> | 2016-12-02 10:03:43 +0100 |
---|---|---|
committer | andreas128 <Andreas> | 2016-12-02 10:03:43 +0100 |
commit | 9623ce222ae217b816eb11dcb4bdf3289dc616cb (patch) | |
tree | c12230ebcb3ea77ead6814585c2b897646f2d2ba /lut_generator.ipynb | |
parent | d31ea5a51f0cc17b0556423896b7b0b7b3c2c217 (diff) | |
download | ODR-StaticPrecorrection-9623ce222ae217b816eb11dcb4bdf3289dc616cb.tar.gz ODR-StaticPrecorrection-9623ce222ae217b816eb11dcb4bdf3289dc616cb.tar.bz2 ODR-StaticPrecorrection-9623ce222ae217b816eb11dcb4bdf3289dc616cb.zip |
Linearised by using search for best amplitude
Diffstat (limited to 'lut_generator.ipynb')
-rw-r--r-- | lut_generator.ipynb | 136 |
1 files changed, 130 insertions, 6 deletions
diff --git a/lut_generator.ipynb b/lut_generator.ipynb index 489203f..d19ac58 100644 --- a/lut_generator.ipynb +++ b/lut_generator.ipynb @@ -38,7 +38,8 @@ "source": [ "df = get_meas(\"./measurements.pkl\")\n", "df_lut = get_meas(\"./measurements_lut.pkl\")\n", - "df_lut_sq = get_meas(\"./measurements_lut_sq.pkl\")" + "df_lut_sq = get_meas(\"./measurements_lut_sq.pkl\")\n", + "df_tab = get_meas(\"./measurements_tab.pkl\")" ] }, { @@ -46,7 +47,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "df.plot()" + ] }, { "cell_type": "code", @@ -68,8 +71,8 @@ "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", + " slope, intersect = get_slope(ampl, mag_feedback)\n", + " return[(x*slope + intersect) / y for (x,y) in zip(ampl, mag_feedback)]\n", "def interp(x): return np.interp(x, df[\"ampl\"], fac)" ] }, @@ -80,6 +83,7 @@ "outputs": [], "source": [ "x = np.linspace(0.1, 0.5, num = 50)\n", + "slope, intersect = get_slope(df[\"ampl\"], df[\"mag_feedback\"])\n", "\n", "plt.plot(df[\"ampl\"], df[\"mag_feedback\"], label=\"measurement\")\n", "plt.plot(x, x*slope + intersect, label = \"linear model\")\n", @@ -130,11 +134,36 @@ "metadata": {}, "outputs": [], "source": [ + "slope, intersect = get_slope(df_tab[\"ampl\"], df_tab[\"mag_feedback\"])\n", + "\n", + "plt.plot(df_tab[\"ampl\"], df_tab[\"mag_feedback\"], label=\"measurement\")\n", + "plt.plot(x, x*slope + intersect, label = \"linear model\")\n", + "\n", + "plt.legend(loc=0)\n", + "plt.title(\"Lut Tab Measurement\")\n", + "\n", + "plt.savefig(\"./lut_plot/lut_tab_measurement.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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(df_tab[\"ampl\"], df_tab[\"mag_feedback\"], label=\"measurement tab sq\")\n", "plt.plot(x, x*slope + intersect, label = \"linear model\")\n", "\n", "plt.legend(loc=0)\n", @@ -149,8 +178,103 @@ "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\"))" + "fac = get_fac(df[\"ampl\"], df[\"mag_feedback\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pickle.dump({\"ampl\":list(df[\"ampl\"]),\"fac\":[f for f in fac]}, open(\"lut.pkl\", \"wb\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pickle.dump({\"ampl\":list(df[\"ampl\"]),\"fac\":[f**2 for f in fac]}, open(\"lut_sq.pkl\", \"wb\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "slope, intersect = get_slope(df[\"ampl\"], df[\"mag_feedback\"])\n", + "ampl_corr = []\n", + "for ampl in df[\"ampl\"]:\n", + " y = ampl * slope + intersect\n", + " mag_feedback_idx = np.argmin(np.abs(df[\"mag_feedback\"] - y))\n", + " ampl_corr.append(df[\"ampl\"][mag_feedback_idx])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ampl_corr = np.array(ampl_corr)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "idx_start = np.argmax(ampl_corr != ampl_corr.min()) - 1\n", + "idx_end = np.argmin(ampl_corr != ampl_corr.max()) \n", + "start = 1.0 * idx_start / len(ampl_corr)\n", + "end = 1.0 * idx_end / len(ampl_corr)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "orig_range = np.linspace(start,end,num=len(ampl_corr))\n", + "new_range = np.linspace(0,1,num=len(ampl_corr))\n", + "\n", + "ampl_corr_new = []\n", + "for f in new_range:\n", + " ratio = np.interp(f, new_range, orig_range)\n", + " new_ampl = np.interp(ratio, new_range, ampl_corr)\n", + " ampl_corr_new.append(new_ampl)\n", + "ampl_corr_new" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fac = ampl_corr_new / df[\"ampl\"]\n", + "pickle.dump({\"ampl\":list(df[\"ampl\"]),\"fac\":[f for f in list(fac)]}, open(\"lut_tab.pkl\", \"wb\"))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pickle.load(open(\"./lut_tab.pkl\"))" ] }, { |