Public API#

Remote client#

class cdlclient.SimpleRemoteProxy(autoconnect: bool = True)#

Object representing a proxy/client to DataLab XML-RPC server. This object is used to call DataLab functions from a Python script.

This is a subset of DataLab’s RemoteClient class, with only the methods that do not require DataLab object model to be implemented.

Parameters:

autoconnect – If True, automatically connect to DataLab XML-RPC server. Defaults to True.

Raises:

ConnectionRefusedError – DataLab is currently not running

Examples

Here is a simple example of how to use SimpleRemoteProxy in a Python script or in a Jupyter notebook:

>>> from cdlclient import SimpleRemoteProxy
>>> proxy = SimpleRemoteProxy()  # autoconnect is on by default
Connecting to DataLab XML-RPC server...OK (port: 28867)
>>> proxy.get_version()
'1.0.0'
>>> proxy.add_signal("toto", np.array([1., 2., 3.]), np.array([4., 5., -1.]))
True
>>> proxy.get_object_titles()
['toto']
>>> proxy["toto"]
<cdlclient.model.signal.SignalObj at 0x7f7f1c0b4a90>
>>> "toto" in proxy
True
>>> proxy[1]
<cdlclient.model.signal.SignalObj at 0x7f7f1c0b4a90>
>>> proxy[1].data
array([1., 2., 3.])
connect(port: str | None = None, timeout: float | None = None, retries: int | None = None) None#

Try to connect to DataLab XML-RPC server.

Parameters:
  • port (str | None) – XML-RPC port to connect to. If not specified, the port is automatically retrieved from DataLab configuration.

  • timeout (float | None) – Timeout in seconds. Defaults to 5.0.

  • retries (int | None) – Number of retries. Defaults to 10.

Raises:
disconnect() None#

Disconnect from DataLab XML-RPC server.

is_connected() bool#

Return True if connected to DataLab XML-RPC server.

get_method_list() list[str]#

Return list of available methods.

add_signal(title: str, xdata: ndarray, ydata: ndarray, xunit: str | None = None, yunit: str | None = None, xlabel: str | None = None, ylabel: str | None = None) bool#

Add signal data to DataLab.

Parameters:
  • title (str) – Signal title

  • xdata (numpy.ndarray) – X data

  • ydata (numpy.ndarray) – Y data

  • xunit (str | None) – X unit. Defaults to None.

  • yunit (str | None) – Y unit. Defaults to None.

  • xlabel (str | None) – X label. Defaults to None.

  • ylabel (str | None) – Y label. Defaults to None.

Returns:

True if signal was added successfully, False otherwise

Return type:

bool

Raises:
add_image(title: str, data: ndarray, xunit: str | None = None, yunit: str | None = None, zunit: str | None = None, xlabel: str | None = None, ylabel: str | None = None, zlabel: str | None = None) bool#

Add image data to DataLab.

Parameters:
  • title (str) – Image title

  • data (numpy.ndarray) – Image data

  • xunit (str | None) – X unit. Defaults to None.

  • yunit (str | None) – Y unit. Defaults to None.

  • zunit (str | None) – Z unit. Defaults to None.

  • xlabel (str | None) – X label. Defaults to None.

  • ylabel (str | None) – Y label. Defaults to None.

  • zlabel (str | None) – Z label. Defaults to None.

Returns:

True if image was added successfully, False otherwise

Return type:

bool

Raises:

ValueError – Invalid data dtype

calc(name: str, param: DataSet | None = None) None#

Call compute function name in current panel’s processor.

Parameters:
  • name – Compute function name

  • param – Compute function parameter. Defaults to None.

Raises:

ValueError – unknown function

get_object(nb_id_title: int | str | None = None, panel: str | None = None) SignalObj | ImageObj#

Get object (signal/image) from index.

Parameters:
  • nb_id_title – Object number, or object id, or object title. Defaults to None (current object).

  • panel – Panel name. Defaults to None (current panel).

Returns:

Object

Raises:

KeyError – if object not found

get_object_shapes(nb_id_title: int | str | None = None, panel: str | None = None) list#

Get plot item shapes associated to object (signal/image).

Parameters:
  • nb_id_title – Object number, or object id, or object title. Defaults to None (current object).

  • panel – Panel name. Defaults to None (current panel).

Returns:

List of plot item shapes

add_annotations_from_items(items: list, refresh_plot: bool = True, panel: str | None = None) None#

Add object annotations (annotation plot items).

Note

This method is only available if PlotPy is installed.

Parameters:
  • items (list) – annotation plot items

  • refresh_plot (bool | None) – refresh plot. Defaults to True.

  • panel (str | None) – panel name (valid values: “signal”, “image”). If None, current panel is used.

Base proxy#

class cdlclient.SimpleBaseProxy(cdlclient: ServerProxy | None = None)#

Simple common base class for DataLab proxies

This is a subset of DataLab’s BaseProxy, with only the methods that do not require DataLab object model to be implemented.

Parameters:

cdlclient (CDLMainWindow | ServerProxy | None) – CDLMainWindow instance or ServerProxy instance. If None, then the proxy implementation will have to set it later (e.g. see SimpleRemoteProxy).

get_version() str#

Return DataLab version.

Returns:

DataLab version

Return type:

str

close_application() None#

Close DataLab application

raise_window() None#

Raise DataLab window

get_current_panel() str#

Return current panel name.

Returns:

Panel name (valid values: “signal”, “image”, “macro”))

Return type:

str

set_current_panel(panel: str) None#

Switch to panel.

Parameters:

panel (str) – Panel name (valid values: “signal”, “image”, “macro”))

reset_all() None#

Reset all application data

toggle_auto_refresh(state: bool) None#

Toggle auto refresh state.

Parameters:

state (bool) – Auto refresh state

context_no_refresh() Callable#

Return a context manager to temporarily disable auto refresh.

Returns:

Context manager

Example

>>> with proxy.context_no_refresh():
...     proxy.add_image("image1", data1)
...     proxy.compute_fft()
...     proxy.compute_wiener()
...     proxy.compute_ifft()
...     # Auto refresh is disabled during the above operations
toggle_show_titles(state: bool) None#

Toggle show titles state.

Parameters:

state (bool) – Show titles state

save_to_h5_file(filename: str) None#

Save to a DataLab HDF5 file.

Parameters:

filename (str) – HDF5 file name

open_h5_files(h5files: list[str] | None = None, import_all: bool | None = None, reset_all: bool | None = None) None#

Open a DataLab HDF5 file or import from any other HDF5 file.

Parameters:
  • h5files (list[str] | None) – List of HDF5 files to open. Defaults to None.

  • import_all (bool | None) – Import all objects from HDF5 files. Defaults to None.

  • reset_all (bool | None) – Reset all application data. Defaults to None.

import_h5_file(filename: str, reset_all: bool | None = None) None#

Open DataLab HDF5 browser to Import HDF5 file.

Parameters:
  • filename (str) – HDF5 file name

  • reset_all (bool | None) – Reset all application data. Defaults to None.

load_from_files(filenames: list[str]) None#

Open objects from files in current panel (signals/images).

Parameters:

filenames – list of file names

add_group(title: str, panel: str | None = None, select: bool = False) None#

Add group to DataLab.

Parameters:
  • title – Group title

  • panel – Panel name (valid values: “signal”, “image”). Defaults to None.

  • select – Select the group after creation. Defaults to False.

get_sel_object_uuids(include_groups: bool = False) list[str]#

Return selected objects uuids.

Parameters:

include_groups – If True, also return objects from selected groups.

Returns:

List of selected objects uuids.

select_objects(selection: list[int | str], panel: str | None = None) None#

Select objects in current panel.

Parameters:
  • selection – List of object numbers (1 to N) or uuids to select

  • panel – panel name (valid values: “signal”, “image”). If None, current panel is used. Defaults to None.

select_groups(selection: list[int | str] | None = None, panel: str | None = None) None#

Select groups in current panel.

Parameters:
  • selection – List of group numbers (1 to N), or list of group uuids, or None to select all groups. Defaults to None.

  • panel (str | None) – panel name (valid values: “signal”, “image”). If None, current panel is used. Defaults to None.

delete_metadata(refresh_plot: bool = True, keep_roi: bool = False) None#

Delete metadata of selected objects

Parameters:
  • refresh_plot – Refresh plot. Defaults to True.

  • keep_roi – Keep ROI. Defaults to False.

get_group_titles_with_object_infos() tuple[list[str], list[list[str]], list[list[str]]]#

Return groups titles and lists of inner objects uuids and titles.

Returns:

groups titles, lists of inner objects uuids and titles

Return type:

Tuple

get_object_titles(panel: str | None = None) list[str]#

Get object (signal/image) list for current panel. Objects are sorted by group number and object index in group.

Parameters:

panel – panel name (valid values: “signal”, “image”, “macro”). If None, current data panel is used (i.e. signal or image panel).

Returns:

List of object titles

Raises:

ValueError – if panel not found

get_object_uuids(panel: str | None = None, group: int | str | None = None) list[str]#

Get object (signal/image) uuid list for current panel. Objects are sorted by group number and object index in group.

Parameters:
  • panel – panel name (valid values: “signal”, “image”). If None, current panel is used.

  • group – Group number, or group id, or group title. Defaults to None (all groups).

Returns:

List of object uuids

Raises:

ValueError – if panel not found

add_label_with_title(title: str | None = None, panel: str | None = None) None#

Add a label with object title on the associated plot

Parameters:
  • title (str | None) – Label title. Defaults to None. If None, the title is the object title.

  • panel (str | None) – panel name (valid values: “signal”, “image”). If None, current panel is used.

run_macro(number_or_title: int | str | None = None) None#

Run macro.

Parameters:

number – Number of the macro (starting at 1). Defaults to None (run current macro, or does nothing if there is no macro).

stop_macro(number_or_title: int | str | None = None) None#

Stop macro.

Parameters:

number – Number of the macro (starting at 1). Defaults to None (stop current macro, or does nothing if there is no macro).

import_macro_from_file(filename: str) None#

Import macro from file

Parameters:

filename – Filename.

Simple model#

DataLab Simple Client provides a simple model for accessing the DataLab objects.

Warning

This model is not complete and does not cover all the DataLab features.

class cdlclient.simplemodel.SignalObj(title: str | None = None, comment: str | None = None, icon: str = '', readonly: bool = False)#

Signal object (simplified version of DataLab’s Signal object)

class cdlclient.simplemodel.ImageObj(title: str | None = None, comment: str | None = None, icon: str = '', readonly: bool = False)#

Image object (simplified version of DataLab’s Image object)

Connection dialog#

Get object dialog#