{ "cells": [ { "cell_type": "markdown", "id": "76b9af91-1233-485b-a616-826a8ccfcbc8", "metadata": {}, "source": [ "DataLab remote control example\n", "==============================\n", "\n", "Example of remote control of DataLab current session, \n", "from asimple notebook.\n", "\n", "The only requirement is to install the *Sigima* package (using `pip install sigima`, for example).b" ] }, { "cell_type": "code", "execution_count": null, "id": "47c889ba-ca07-46dd-bec0-b08d67bd1eb2", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from sigima.client import SimpleRemoteProxy\n", "proxy = SimpleRemoteProxy()" ] }, { "cell_type": "markdown", "id": "721d52f6-2df8-4559-89d2-f7088a5e2ee2", "metadata": {}, "source": [ "Connecting to DataLab current session:" ] }, { "cell_type": "code", "execution_count": 20, "id": "1de8616a-619c-4d5b-869f-fb41cf72b7cf", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connecting to DataLab XML-RPC server...OK (port: 62547)\n" ] } ], "source": [ "proxy.connect()" ] }, { "cell_type": "markdown", "id": "9246a105-d73d-4ba3-81e1-4fadd042a4c6", "metadata": {}, "source": [ "Executing commands in DataLab:" ] }, { "cell_type": "code", "execution_count": 21, "id": "ccdddb07-cc54-42dd-b744-751516ae73d9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "z = np.random.rand(20, 20)\n", "proxy.add_image(\"toto\", z)" ] }, { "cell_type": "code", "execution_count": 22, "id": "7216fc12-2675-48ff-a62a-64b5516c2e09", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = np.array([1.0, 2.0, 3.0])\n", "y = np.array([4.0, 5.0, -1.0])\n", "proxy.add_signal(\"toto\", x, y)" ] }, { "cell_type": "code", "execution_count": null, "id": "4a094ecb-5314-42d8-be60-0ce419275e8f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "proxy.calc(\"derivative\")" ] }, { "cell_type": "code", "execution_count": 24, "id": "94fc3b6d-8d4a-40d6-ad34-9ecb4888db58", "metadata": {}, "outputs": [], "source": [ "proxy.set_current_panel(\"image\")" ] }, { "cell_type": "code", "execution_count": null, "id": "2b0b4fc7-c282-4c2c-bb57-6df3241524ce", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "proxy.calc(\"fft\")" ] } ], "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }