Proxy objects (cdl.proxy
)#
The cdl.proxy
module provides a way to access DataLab features from a proxy
class.
The list of compute methods accessible from the proxy objects is available in the Calling processor methods using proxy objects section.
Remote proxy#
The remote proxy is used when DataLab is started from a different process than the proxy. In this case, the proxy connects to DataLab XML-RPC server.
- class cdl.proxy.RemoteProxy(autoconnect: bool = True)[source]#
DataLab remote proxy class.
This class provides access to DataLab features from a proxy class. This is the remote version of proxy, which is used when DataLab is started from a different process than the proxy.
- Parameters:
autoconnect (bool) β Automatically connect to DataLab XML-RPC server.
- Raises:
ConnectionRefusedError β Unable to connect to DataLab
ValueError β Invalid timeout (must be >= 0.0)
ValueError β Invalid number of retries (must be >= 1)
Note
The proxy object also allows to access DataLab computing methods exposed by the processor classes (see Calling processor methods using proxy objects).
Examples
Here is a simple example of how to use RemoteProxy in a Python script or in a Jupyter notebook:
>>> from cdl.proxy import RemoteProxy >>> proxy = RemoteProxy() 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"] # from title <cdl.core.model.signal.SignalObj at 0x7f7f1c0b4a90> >>> proxy[1] # from number <cdl.core.model.signal.SignalObj at 0x7f7f1c0b4a90> >>> proxy[1].data array([1., 2., 3.]) >>> proxy.set_current_panel("image")
- add_annotations_from_items(items: list, refresh_plot: bool = True, panel: str | None = None) None #
Add object annotations (annotation plot items).
- 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:
- Raises:
ValueError β Invalid data dtype
- add_label_with_title(title: str | None = None, panel: str | None = None) None #
Add a label with object title on the associated plot
- 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:
- Raises:
ValueError β Invalid xdata dtype
ValueError β Invalid ydata 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
- connect(port: str | None = None, timeout: float | None = None, retries: int | None = None) None #
Try to connect to DataLab XML-RPC server.
- Parameters:
- Raises:
ConnectionRefusedError β Unable to connect to DataLab
ValueError β Invalid timeout (must be >= 0.0)
ValueError β Invalid number of retries (must be >= 1)
- context_no_refresh() Generator[None, None, None] #
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
- 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_current_panel() str #
Return current panel name.
- Returns:
Panel name (valid values: βsignalβ, βimageβ, βmacroβ))
- Return type:
- 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(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
- 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) list[str] #
Get object (signal/image) uuid list for current panel. Objects are sorted by group number and object index in group.
- Parameters:
panel (str | None) β panel name (valid values: βsignalβ, βimageβ). If None, current panel is used.
- Returns:
list of object uuids
- Return type:
- Raises:
ValueError β if panel not found
- 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.
- import_h5_file(filename: str, reset_all: bool | None = None) None #
Open DataLab HDF5 browser to Import HDF5 file.
- import_macro_from_file(filename: str) None #
Import macro from file
- Parameters:
filename β Filename.
- load_from_files(filenames: list[str]) None #
Open objects from files in current panel (signals/images).
- Parameters:
filenames β list of file names
- 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.
- run_macro(number_or_title: int | str | None = None) None #
Run macro.
- Parameters:
number_or_title β Macro number, or macro title. Defaults to None (current macro).
- Raises:
ValueError β if macro not found
- save_to_h5_file(filename: str) None #
Save to a DataLab HDF5 file.
- Parameters:
filename (str) β HDF5 file name
- 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.
- 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.
- set_current_panel(panel: str) None #
Switch to panel.
- Parameters:
panel (str) β Panel name (valid values: βsignalβ, βimageβ, βmacroβ))
- stop_macro(number_or_title: int | str | None = None) None #
Stop macro.
- Parameters:
number_or_title β Macro number, or macro title. Defaults to None (current macro).
- Raises:
ValueError β if macro not found
Local proxy#
The local proxy is used when DataLab is started from the same process as the proxy. In this case, the proxy is directly connected to DataLab main window instance. The typical use case is high-level scripting.
- class cdl.proxy.LocalProxy(cdl: CDLMainWindow | ServerProxy | None = None)[source]#
DataLab local proxy class.
This class provides access to DataLab features from a proxy class. This is the local version of proxy, which is used when DataLab is started from the same process as the proxy.
- Parameters:
cdl (CDLMainWindow) β CDLMainWindow instance.
Note
The proxy object also allows to access DataLab computing methods exposed by the processor classes (see Calling processor methods using proxy objects).
- 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 [source]#
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:
- Raises:
ValueError β Invalid xdata dtype
ValueError β Invalid ydata dtype
- 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 [source]#
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:
- Raises:
ValueError β Invalid data dtype
- calc(name: str, param: DataSet | None = None) None [source]#
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 [source]#
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 [source]#
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 [source]#
Add object annotations (annotation plot items).
- add_label_with_title(title: str | None = None, panel: str | None = None) None #
Add a label with object title on the associated plot
- context_no_refresh() Generator[None, None, None] #
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
- 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_current_panel() str #
Return current panel name.
- Returns:
Panel name (valid values: βsignalβ, βimageβ, βmacroβ))
- Return type:
- 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) list[str] #
Get object (signal/image) uuid list for current panel. Objects are sorted by group number and object index in group.
- Parameters:
panel (str | None) β panel name (valid values: βsignalβ, βimageβ). If None, current panel is used.
- Returns:
list of object uuids
- Return type:
- Raises:
ValueError β if panel not found
- 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.
- import_h5_file(filename: str, reset_all: bool | None = None) None #
Open DataLab HDF5 browser to Import HDF5 file.
- import_macro_from_file(filename: str) None #
Import macro from file
- Parameters:
filename β Filename.
- load_from_files(filenames: list[str]) None #
Open objects from files in current panel (signals/images).
- Parameters:
filenames β list of file names
- 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.
- run_macro(number_or_title: int | str | None = None) None #
Run macro.
- Parameters:
number_or_title β Macro number, or macro title. Defaults to None (current macro).
- Raises:
ValueError β if macro not found
- save_to_h5_file(filename: str) None #
Save to a DataLab HDF5 file.
- Parameters:
filename (str) β HDF5 file name
- 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.
- 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.
- set_current_panel(panel: str) None #
Switch to panel.
- Parameters:
panel (str) β Panel name (valid values: βsignalβ, βimageβ, βmacroβ))
- stop_macro(number_or_title: int | str | None = None) None #
Stop macro.
- Parameters:
number_or_title β Macro number, or macro title. Defaults to None (current macro).
- Raises:
ValueError β if macro not found
Proxy context manager#
The proxy context manager is a convenient way to handle proxy creation and destruction. It is used as follows:
with proxy_context("local") as proxy:
proxy.add_signal(...)
The proxy type can be βlocalβ or βremoteβ. For remote proxy, the port can be specified as βremote:portβ.
Note
The proxy context manager allows to use the proxy in various contexts (Python script, Jupyter notebook, etc.). It also allows to switch seamlessly between local and remote proxy, keeping the same code inside the context.
- cdl.proxy.proxy_context(what: str) Generator[LocalProxy | RemoteProxy, None, None] [source]#
Context manager handling CDL proxy creation and destruction.
- Parameters:
what (str) β proxy type (βlocalβ or βremoteβ) For remote proxy, the port can be specified as βremote:portβ
- Yields:
Generator[LocalProxy | RemoteProxy, None, None] β
- proxy
LocalProxy if what == βlocalβ RemoteProxy if what == βremoteβ or βremote:portβ
Example
- with proxy_context(βlocalβ) as proxy:
proxy.add_signal(β¦)
Calling processor methods using proxy objects#
All the proxy objects provide access to the DataLab computing methods exposed by the processor classes:
See also
The list of processor methods is available in tables below.
There are two ways to call a processor method:
Using the
calc()
method of the proxy object:
# Call a method without parameter
proxy.calc("compute_average")
# This is equivalent to:
proxy.calc("average")
# Call a method with parameters
p = cdl.param.MovingAverageParam.create(n=30)
proxy.calc("compute_moving_average", p)
Directly calling the processor method from the proxy object:
# Call a method without parameter
proxy.compute_average()
# Call a method with parameters
p = cdl.param.MovingAverageParam.create(n=30)
proxy.compute_moving_average(p)
Warning
The compute_{name} methods are not statically defined in the proxy classes (and
not even dynamically). They are nevertheless available through the proxy objects
thanks to the magic method __getattr__()
which forwards the call to the
calc()
method. However, this means that the methods are not listed in the
proxy classes documentation, and they are not available in the auto-completion
feature of your IDE.
Number of compute methods#
Signal |
Image |
Total |
---|---|---|
59 |
100 |
159 |
Signal processing#
The following table lists the signal processor methods - it is automatically generated from the source code:
Compute method |
Description |
---|---|
Compute absolute value with |
|
Compute sum with a constant |
|
Compute arithmetic operation between two signals |
|
Convert data type with |
|
Compute average with |
|
Compute band-pass filter |
|
Compute band-stop filter |
|
Compute bandwidth at -3dB |
|
Compute data linear calibration |
|
Compute maximum data clipping |
|
Compute contrast with |
|
Compute convolution |
|
Compute derivative |
|
Compute detrending |
|
Compute difference between two signals |
|
Compute difference with a constant |
|
Compute division between two signals |
|
Compute division by a constant |
|
Compute Dynamic Parameters (ENOB, SINAD, THD, SFDR, SNR) |
|
Compute Log10 with |
|
Compute FFT with |
|
Compute fitting curve using an interactive dialog |
|
Compute FW at 1/eΒ² with |
|
Compute FWHM with |
|
Compute gaussian filter |
|
Compute high-pass filter |
|
Compute histogram |
|
Compute iFFT with |
|
Compute imaginary part with |
|
Compute integral with |
|
Compute interpolation |
|
Compute Log10 with |
|
Compute high-pass filter |
|
Compute magnitude spectrum |
|
Compute moving average |
|
Compute moving median |
|
Compute multi-Gaussian fitting curve using an interactive dialog |
|
Normalize data with |
|
Compute offset correction |
|
Detect peaks from data |
|
Compute phase spectrum |
|
Compute polynomial fitting curve |
|
Compute power with |
|
Compute product with |
|
Compute product with a constant |
|
Compute power spectral density |
|
Compute quadratic difference between two signals |
|
Compute real part with |
|
Compute resampling |
|
Reverse X axis with |
|
|
Extract Region Of Interest (ROI) from data with: |
Compute sampling rate and period (mean and std) |
|
Compute square root with |
|
Compute data statistics |
|
Compute sum with |
|
Swap data axes with |
|
Compute Wiener filter |
|
Compute windowing |
|
Compute x at min/max |
Image processing#
The following table lists the image processor methods - it is automatically generated from the source code:
Compute method |
Description |
---|---|
Compute absolute value with |
|
Compute sum with a constant using |
|
Compute gamma correction |
|
Compute log correction |
|
Compute sigmoid correction |
|
Compute all denoising filters |
|
Compute all edges filters |
|
Compute all morphology filters |
|
Compute all threshold algorithms |
|
Compute arithmetic operation between two images |
|
Convert data type with |
|
Compute average with |
|
Compute average profile |
|
Binning image with |
|
Compute Black Top-Hat |
|
Compute blob detection using Difference of Gaussian method |
|
Compute blob detection using Determinant of Hessian method |
|
Compute blob detection using Laplacian of Gaussian method |
|
Compute blob detection using OpenCV |
|
Compute Butterworth filter |
|
Compute data linear calibration |
|
Compute Canny filter |
|
Compute image centroid |
|
Compute maximum data clipping |
|
Compute morphological closing |
|
Compute contour shape fit |
|
Compute bilateral filter denoising |
|
Denoise using White Top-Hat |
|
Compute Total Variation denoising |
|
Compute Wavelet denoising |
|
Compute difference between two images |
|
Compute difference with a constant |
|
Compute Dilation |
|
Compute division between two images |
|
Compute division by a constant |
|
Compute minimum enclosing circle |
|
Adaptive histogram equalization |
|
Histogram equalization |
|
Compute Erosion |
|
Compute Log10 with |
|
Compute Farid filter |
|
Compute Farid filter (horizontal) |
|
Compute Farid filter (vertical) |
|
Compute FFT with |
|
Compute flat field correction |
|
Flip data horizontally using |
|
Flip data vertically with |
|
Compute gaussian filter |
|
Compute histogram with |
|
Compute peak detection based on a circle Hough transform |
|
Compute iFFT with |
|
Compute imaginary part with |
|
Compute Laplace filter |
|
Compute profile along a vertical or horizontal line |
|
Compute Log10 with |
|
Compute base 10 logarithm using |
|
Compute magnitude spectrum |
|
Compute moving average |
|
Compute moving median |
|
Normalize data with |
|
Compute offset correction |
|
Compute morphological opening |
|
Compute 2D peak detection |
|
Compute phase spectrum |
|
Compute Prewitt filter |
|
Compute Prewitt filter (horizontal) |
|
Compute Prewitt filter (vertical) |
|
Compute product with |
|
Compute product with a constant using |
|
Compute Power Spectral Density (PSD) |
|
Compute quadratic difference between two images |
|
Compute radial profile |
|
Compute real part with |
|
Rescale image intensity levels |
|
Resize image with |
|
Compute Roberts filter |
|
|
Extract Region Of Interest (ROI) from data with: |
Rotate data arbitrarily using |
|
Rotate data 270Β° with |
|
Rotate data 90Β° with |
|
Compute Scharr filter |
|
Compute Scharr filter (horizontal) |
|
Compute Scharr filter (vertical) |
|
Compute profile along a segment |
|
Compute Sobel filter |
|
Compute Sobel filter (horizontal) |
|
Compute Sobel filter (vertical) |
|
Compute data statistics |
|
Compute sum with |
|
Swap data axes with |
|
Compute parametric threshold |
|
Compute threshold using Isodata algorithm |
|
Compute threshold using Li algorithm |
|
Compute threshold using Mean algorithm |
|
Compute threshold using Minimum algorithm |
|
Compute threshold using Otsu algorithm |
|
Compute threshold using Triangle algorithm |
|
Compute threshold using Yen algorithm |
|
Compute White Top-Hat |
|
Compute Wiener filter |