| 1 |
# -*- coding: utf-8 -*- |
| 2 |
""" |
| 3 |
Example of remote control of DataLab current session, |
| 4 |
from a Python script running outside DataLab (e.g. in Spyder) |
| 5 |
|
| 6 |
Created on Fri May 12 12:28:56 2023 |
| 7 |
|
| 8 |
@author: p.raybaut |
| 9 |
""" |
| 10 |
|
| 11 |
# %% Importing necessary modules |
| 12 |
|
| 13 |
# NumPy for numerical array computations: |
| 14 |
import numpy as np |
| 15 |
|
| 16 |
# DataLab remote control client: |
| 17 |
from cdlclient import SimpleRemoteProxy as RemoteProxy |
| 18 |
|
| 19 |
# %% Connecting to DataLab current session |
| 20 |
|
| 21 |
proxy = RemoteProxy() |
| 22 |
|
| 23 |
# %% Executing commands in DataLab (...) |
| 24 |
|
| 25 |
z = np.random.rand(20, 20) |
| 26 |
proxy.add_image("toto", z) |
| 27 |
|
| 28 |
# %% Executing commands in DataLab (...) |
| 29 |
|
| 30 |
proxy.toggle_auto_refresh(False) # Turning off auto-refresh |
| 31 |
x = np.array([1.0, 2.0, 3.0]) |
| 32 |
y = np.array([4.0, 5.0, -1.0]) |
| 33 |
proxy.add_signal("toto", x, y) |
| 34 |
|
| 35 |
# %% Executing commands in DataLab (...) |
| 36 |
|
| 37 |
proxy.compute_derivative() |
| 38 |
proxy.toggle_auto_refresh(True) # Turning on auto-refresh |
| 39 |
|
| 40 |
# %% Executing commands in DataLab (...) |
| 41 |
|
| 42 |
proxy.set_current_panel("image") |
| 43 |
|
| 44 |
# %% Executing a lot of commands without refreshing DataLab |
| 45 |
|
| 46 |
z = np.random.rand(400, 400) |
| 47 |
proxy.add_image("foobar", z) |
| 48 |
with proxy.context_no_refresh(): |
| 49 |
for _idx in range(100): |
| 50 |
proxy.compute_fft() |