diff --git a/Measurement.ipynb b/Measurement.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..0598320139a432c92fcf3661b38db2d71a1e01f5 --- /dev/null +++ b/Measurement.ipynb @@ -0,0 +1,315 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "86e0de15", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "a6aeb700", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<style>.container { width:50% !important; }</style>" + ], + "text/plain": [ + "<IPython.core.display.HTML object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "<style>.output_result { max-width:90% !important; }</style>" + ], + "text/plain": [ + "<IPython.core.display.HTML object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "<style>.prompt { display:none !important; }</style>" + ], + "text/plain": [ + "<IPython.core.display.HTML object>" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "\n", + " <script>\n", + " function code_toggle_15576857267444703097() {\n", + " $('div.cell.code_cell.rendered.selected').find('div.input').toggle();\n", + " }\n", + "\n", + " \n", + " </script>\n", + "\n", + " <a href=\"javascript:code_toggle_15576857267444703097()\">Toggle show/hide</a>\n", + " " + ], + "text/plain": [ + "<IPython.core.display.HTML object>" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# %matplotlib nbagg\n", + "from IPython.display import display, HTML\n", + "display(HTML(\"<style>.container { width:50% !important; }</style>\"))\n", + "display(HTML(\"<style>.output_result { max-width:90% !important; }</style>\"))\n", + "display(HTML(\"<style>.prompt { display:none !important; }</style>\"))\n", + "\n", + "import random\n", + "\n", + "def hide_toggle(for_next=False):\n", + " this_cell = \"\"\"$('div.cell.code_cell.rendered.selected')\"\"\"\n", + " next_cell = this_cell + '.next()'\n", + "\n", + " toggle_text = 'Toggle show/hide' # text shown on toggle link\n", + " target_cell = this_cell # target cell to control with toggle\n", + " js_hide_current = '' # bit of JS to permanently hide code in current cell (only when toggling next cell)\n", + "\n", + " if for_next:\n", + " target_cell = next_cell\n", + " toggle_text += ' next cell'\n", + " js_hide_current = this_cell + '.find(\"div.input\").hide();'\n", + "\n", + " js_f_name = 'code_toggle_{}'.format(str(random.randint(1,2**64)))\n", + "\n", + " html = \"\"\"\n", + " <script>\n", + " function {f_name}() {{\n", + " {cell_selector}.find('div.input').toggle();\n", + " }}\n", + "\n", + " {js_hide_current}\n", + " </script>\n", + "\n", + " <a href=\"javascript:{f_name}()\">{toggle_text}</a>\n", + " \"\"\".format(\n", + " f_name=js_f_name,\n", + " cell_selector=target_cell,\n", + " js_hide_current=js_hide_current, \n", + " toggle_text=toggle_text\n", + " )\n", + "\n", + " return HTML(html)\n", + "\n", + "hide_toggle()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "4cd24dd9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[31m ________________________________\n", + "| _ | | | || \\/ || ___ \\_ _|\n", + "| | | | |_| || . . || |_/ / | |\n", + "| | | | _ || |\\/| || __/ | |\n", + "\\ \\_/ / | | || | | || | _| |_\n", + " \\___/\\_| |_/\\_| |_/\\_| \\___/ \u001b[0m\n", + "Version: 2.1.5\n", + "\u001b[32m☑ Running on raspberry pi 3 model b rev 1.2\u0000 platform\u001b[0m\n", + "local date and time : 2023-04-26 08:20:07\n" + ] + } + ], + "source": [ + "from ohmpi import OhmPi\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "ba2c6305", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2023-04-26 08:20:07 UTC | 1495 | INFO: \n", + "2023-04-26 08:20:07 UTC | 1495 | INFO: ****************************\n", + "2023-04-26 08:20:07 UTC | 1495 | INFO: *** NEW SESSION STARTING ***\n", + "2023-04-26 08:20:07 UTC | 1495 | INFO: ****************************\n", + "2023-04-26 08:20:07 UTC | 1495 | INFO: \n", + "2023-04-26 08:20:07 UTC | 1495 | INFO: Remaining disk space : 7244.7 MB\n", + "2023-04-26 08:20:07 UTC | 1495 | INFO: Saving data log to /home/pi/OhmPi/data/data.log\n", + "2023-04-26 08:20:07 UTC | 1495 | INFO: Starting_session\n", + "\u001b[34m\n", + "☑ Publishes execution as ohmpi_0001/exec topic on the localhost broker\u001b[0m\u001b[34m\n", + "☑ Publishes data as ohmpi_0001/data topic on the localhost broker\u001b[0m\n", + "\u001b[34m☑ Subscribed to control topic ohmpi_0001/ctrl on localhost broker\u001b[0m\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " <script>\n", + " function code_toggle_8777935057456225021() {\n", + " $('div.cell.code_cell.rendered.selected').find('div.input').toggle();\n", + " }\n", + "\n", + " \n", + " </script>\n", + "\n", + " <a href=\"javascript:code_toggle_8777935057456225021()\">Toggle show/hide</a>\n", + " " + ], + "text/plain": [ + "<IPython.core.display.HTML object>" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from OhmPi_ML import run_measurement_new, append_and_save_new\n", + "\n", + "setattr(OhmPi,\"run_measurement\",run_measurement_new)\n", + "k = OhmPi(idps=False,use_mux=False)\n", + "\n", + "k.append_and_save = append_and_save_new\n", + "\n", + "hide_toggle()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "d226fbce", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2023-04-26 08:21:17 UTC | 1495 | INFO: \n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: \n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: \n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: ****************************\n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: ****************************\n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: ****************************\n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: *** NEW SESSION STARTING ***\n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: *** NEW SESSION STARTING ***\n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: *** NEW SESSION STARTING ***\n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: ****************************\n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: ****************************\n", + "2023-04-26 08:21:17 UTC | 1495 | INFO: ****************************\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: \n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: \n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: \n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Remaining disk space : 7244.6 MB\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Remaining disk space : 7244.6 MB\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Remaining disk space : 7244.6 MB\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Saving data log to /home/pi/OhmPi/data/data.log\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Saving data log to /home/pi/OhmPi/data/data.log\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Saving data log to /home/pi/OhmPi/data/data.log\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Starting_session\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Starting_session\n", + "2023-04-26 08:21:18 UTC | 1495 | INFO: Starting_session\n", + "\u001b[34m\n", + "☑ Publishes execution as ohmpi_0001/exec topic on the localhost broker\u001b[0m\u001b[34m\n", + "☑ Publishes data as ohmpi_0001/data topic on the localhost broker\u001b[0m\n", + "\u001b[34m☑ Subscribed to control topic ohmpi_0001/ctrl on localhost broker\u001b[0m\n" + ] + }, + { + "ename": "AssertionError", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[5], line 5\u001b[0m\n\u001b[1;32m 1\u001b[0m quad \u001b[38;5;241m=\u001b[39m [[\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m4\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m],[\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m4\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m]]\n\u001b[1;32m 4\u001b[0m k \u001b[38;5;241m=\u001b[39m OhmPi(idps\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m,use_mux\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[0;32m----> 5\u001b[0m \u001b[43mk\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msequence\u001b[49m \u001b[38;5;241m=\u001b[39m quad\n\u001b[1;32m 6\u001b[0m k\u001b[38;5;241m.\u001b[39mreset_mux()\n\u001b[1;32m 7\u001b[0m k\u001b[38;5;241m.\u001b[39mswitch_mux_on(quad)\n", + "File \u001b[0;32m~/OhmPi/ohmpi.py:1688\u001b[0m, in \u001b[0;36mOhmPi.sequence\u001b[0;34m(self, sequence)\u001b[0m\n\u001b[1;32m 1686\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Sets sequence\"\"\"\u001b[39;00m\n\u001b[1;32m 1687\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sequence \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m-> 1688\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(sequence, np\u001b[38;5;241m.\u001b[39mndarray)\n\u001b[1;32m 1689\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39muse_mux \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m 1690\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n", + "\u001b[0;31mAssertionError\u001b[0m: " + ] + } + ], + "source": [ + "quad = [1,4,2,3]\n", + "\n", + "\n", + "k = OhmPi(idps=False,use_mux=False)\n", + "k.reset_mux()\n", + "k.switch_mux_on(quad)\n", + "out = k.run_measurement(quad,tx_volt=12,injection_duration=1,strategy='constant',nb_stack=3,autogain=False,duty_cycle=0.8)\n", + "k.switch_mux_off(quad)\n", + "k.reset_mux()\n", + "\n", + "data = out['fulldata']\n", + "fig, (ax1,ax2) = plt.subplots(2, sharex=True)\n", + "ax1.plot(data[:, 2], data[:, 0], 'r.-', label='current [mA]')\n", + "ax1.set_ylabel('Current (mA)')\n", + "ax1.set_title('Current')\n", + "ax2.plot(data[:, 2], data[:, 1], '.-', label='Voltage [mV]',alpha=.5)\n", + "ax2.set_xlabel('Time (s)')\n", + "ax2.set_ylabel('Voltage (mV)')\n", + "ax2.set_title('Voltage')\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aa7433b5", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}