0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

docs: remove BECFigure from docs, fix wrong api for docs of plotting widgets

This commit is contained in:
2025-04-23 17:33:50 +02:00
parent 75cc45d767
commit a1c859c743
4 changed files with 98 additions and 155 deletions

View File

@ -7,7 +7,7 @@
The Image Widget is a versatile tool designed for visualizing both 1D and 2D data, such as camera images or waveform data, in real-time. Directly integrated with the `BEC` framework, it can display live data streams from connected detectors or other data sources within the current `BEC` session. The widget provides advanced customization options for color maps and scale bars, allowing users to tailor the visualization to their specific needs.
## Key Features:
- **Flexible Integration**: The widget can be integrated into both [`BECFigure`](user.widgets.bec_figure) and [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`.
- **Flexible Integration**: The widget can be integrated into [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`.
- **Live Data Visualization**: Real-time plotting of both 1D and 2D data from detectors or other data sources, provided that a data stream is available in the BEC session.
- **Support for Multiple Monitor Types**: The Image Widget supports different monitor types (`'1d'` and `'2d'`), allowing visualization of various data dimensions.
- **Customizable Color Maps and Scale Bars**: Users can customize the appearance of images with various color maps and adjust scale bars to better interpret the visualized data.
@ -29,19 +29,20 @@ By specifying the appropriate `monitor_type`, you can configure the Image Widget
````{tab} Examples - CLI
`ImageWidget` can be embedded in both [`BECFigure`](user.widgets.bec_figure) and [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`. The command-line API is the same for all cases.
`ImageWidget` can be embedded in [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`. The command-line API is the same for all cases.
## Example 1 - Visualizing 2D Image Data from a Detector
In this example, we demonstrate how to add an `ImageWidget` to a [`BECFigure`](user.widgets.bec_figure) to visualize live 2D image data from a connected camera detector.
In this example, we demonstrate how to add an `ImageWidget` to a [`BECDockArea`](user.widgets.bec_dock_area) to visualize live 2D image data from a connected camera detector.
```python
# Add a new dock with BECFigure widget
fig = gui.add_dock().add_widget('BECFigure')
dock_area = gui.new()
img_widget = dock_area.new().new(gui.available_widgets.Image)
# Add an ImageWidget to the BECFigure for a 2D detector
img_widget = fig.image(monitor='eiger', monitor_type='2d')
img_widget.set_title("Camera Image - Eiger Detector")
img_widget.image(monitor='eiger', monitor_type='2d')
img_widget.title = "Camera Image - Eiger Detector"
```
## Example 2 - Visualizing 1D Waveform Data from a Detector
@ -49,56 +50,41 @@ img_widget.set_title("Camera Image - Eiger Detector")
This example demonstrates how to set up the Image Widget to visualize 1D waveform data from a detector, such as a line detector or a spectrometer. The widget will stack incoming 1D data arrays to construct a 2D image.
```python
# Add an ImageWidget to the BECFigure for a 1D detector
img_widget = fig.image(monitor='line_detector', monitor_type='1d')
img_widget.set_title("Line Detector Data")
# Add a new dock with BECFigure widget
dock_area = gui.new()
img_widget = dock_area.new().new(gui.available_widgets.Image)
# Add an ImageWidget to the BECFigure for a 2D detector
img_widget.image(monitor='waveform', monitor_type='1d')
img_widget.title = "Line Detector Data"
# Optional: Set the color map and value range
img_widget.set_colormap("plasma")
img_widget.set_vrange(vmin=0, vmax=100)
img_widget.colormap = "plasma"
img_widget.vrange= [0, 100]
```
## Example 3 - Adding Image Widget as a Dock in BECDockArea
Adding an `ImageWidget` into a [`BECDockArea`](user.widgets.bec_dock_area) is similar to adding any other widget. The widget has the same API as the one in [`BECFigure`](user.widgets.bec_figure); however, as an independent widget outside of `BECFigure`, it has its own toolbar, allowing users to configure the widget without needing CLI commands.
```python
# Add an ImageWidget to the BECDockArea for a 2D detector
img_widget = gui.add_dock().add_widget('BECImageWidget')
# Visualize live data from a camera with a specified value range
img_widget.image(monitor='eiger', monitor_type='2d')
img_widget.set_vrange(vmin=0, vmax=100)
```
## Example 4 - Customizing Image Display
This example demonstrates how to customize the color map and scale bar for an image being visualized in an `ImageWidget`.
```python
# Set the color map and adjust the value range
img_widget.set_colormap("viridis")
img_widget.set_vrange(vmin=10, vmax=200)
```
## Example 5 - Real-time Image Processing
## Example 3 - Real-time Image Processing
The `ImageWidget` provides real-time image processing capabilities, such as rotating, scaling, applying logarithmic scaling, and performing FFT on the displayed images. The following example demonstrates how to apply these transformations to an image.
```python
# Rotate the image by 90 degrees
img_widget.set_rotation(deg_90=1)
# Rotate the image by 90 degrees (1,2,3,4 are multiplied by 90 degrees)
img_widget.rotation = 1
# Transpose the image
img_widget.set_transpose(enable=True)
img_widget.transpose = True
# Apply FFT to the image
img_widget.set_fft(enable=True)
img_widget.fft = True
# Set logarithmic scaling for the image display
img_widget.set_log(enable=True)
```
img_widget.log = True
# Set autorange for the image color map
img_widget.autorange = True
img_widget.autorange_mode = 'mean'# or 'max'
```
<!--
## Example 6 - Setting Up for Different Detectors
The Image Widget can be configured for different detectors by specifying the correct monitor name and monitor type. Here's how to set it up for various detectors:
@ -121,13 +107,13 @@ img_widget.set_title("Line Detector Data")
```{note}
Since the Image Widget does not have prior information about the shape of incoming data, it is essential to specify the correct `monitor_type` when setting up the widget. This ensures that the data is processed and displayed correctly.
```
``` -->
````
````{tab} API
```{eval-rst}
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.BECImageWidget.rst
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.Image.rst
```
````

View File

@ -7,7 +7,7 @@
The Motor Map Widget is a specialized tool for tracking and visualizing the positions of motors in real-time. This widget is crucial for applications requiring precise alignment and movement tracking during scans. It provides an intuitive way to monitor motor trajectories, ensuring accurate positioning throughout the scanning process.
## Key Features:
- **Flexible Integration**: The widget can be integrated into both [`BECFigure`](user.widgets.bec_figure) and [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`.
- **Flexible Integration**: The widget can be integrated into [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`.
- **Real-time Motor Position Visualization**: Tracks motor positions in real-time and visually represents motor trajectories.
- **Customizable Visual Elements**: The appearance of all widget components is fully customizable, including scatter size and background values.
- **Interactive Controls**: Interactive controls for zooming, panning, and adjusting the visual properties of motor trajectories on the fly.
@ -16,51 +16,39 @@ The Motor Map Widget is a specialized tool for tracking and visualizing the posi
````
````{tab} Examples CLI
`MotorMapWidget` can be embedded in both [`BECFigure`](user.widgets.bec_figure) and [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`. However, the command-line API is the same for all cases.
`MotorMapWidget` can be embedded in [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`. However, the command-line API is the same for all cases.
## Example 1 - Adding Motor Map Widget to BECFigure
## Example 1 - Adding Motor Map Widget as a Dock in BECDockArea
In this example, we will demonstrate how to add two different `MotorMapWidgets` into a single [`BECFigure`](user.widgets.bec_figure) widget.
```python
# Add new dock with BECFigure widget
fig = gui.add_dock().add_widget('BECFigure')
# Add two WaveformWidgets to the BECFigure
mm1 = fig.motor_map(motor_x='samx', motor_y='samy')
mm2 = fig.motor_map(motor_x='aptrx', motor_y='aptry',new=True)
```
## Example 2 - Adding Motor Map Widget as a Dock in BECDockArea
Adding `MotorMapWidget` into a [`BECDockArea`](user.widgets.bec_dock_area) is similar to adding any other widget. The widget has the same API as the one in BECFigure; however, as an independent widget outside BECFigure, it has its own toolbar, allowing users to configure the widget without needing CLI commands.
Adding `MotorMapWidget` into a [`BECDockArea`](user.widgets.bec_dock_area) is similar to adding any other widget.
```python
# Add new MotorMaps to the BECDockArea
mm1 = gui.add_dock().add_widget('BECMotorMapWidget')
mm2 = gui.add_dock().add_widget('BECMotorMapWidget')
dock_area = gui.new()
mm1 = dock_area.new().new(gui.available_widgets.MotorMap)
mm2 = dock_area.new().new(gui.available_widgets.MotorMap)
# Add signals to the MotorMaps
mm1.change_motors(motor_x='samx', motor_y='samy')
mm2.change_motors(motor_x='aptrx', motor_y='aptry')
mm1.map(x_name='samx', y_name='samy')
mm2.map(x_name='aptrx', y_name='aptry')
```
## Example 3 - Customizing Motor Map Display
## Example 2 - Customizing Motor Map Display
The `MotorMapWidget` allows customization of its visual elements to better suit the needs of your application. Below is an example of how to adjust the scatter size, set background values, and limit the number of points displayed from the position buffer.
```python
# Set scatter size
mm1.set_scatter_size(scatter_size=5)
mm1.scatter_size = 10
# Set background value
mm1.set_background_value(background_value=0)
# Set background value (between 0 and 100)
mm1.background_value = 0
# Limit the number of points displayed and saved in the position buffer
mm1.set_max_points(max_points=500)
mm1.max_points = 500
```
## Example 4 - Changing Motors and Resetting History
## Example 3 - Changing Motors and Resetting History
You can dynamically change the motors being tracked and reset the history of the motor trajectories during the session.
@ -69,12 +57,12 @@ You can dynamically change the motors being tracked and reset the history of the
mm1.reset_history()
# Change the motors being tracked
mm1.change_motors(motor_x='aptrx', motor_y='aptry')
mm1.map(x_name='aptrx', y_name='aptry')
```
````
````{tab} API
```{eval-rst}
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.BECMotorMap.rst
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.MotorMap.rst
```
````

View File

@ -11,81 +11,64 @@ The Multi Waveform Widget is designed to display multiple 1D detector signals ov
- **Interactive Controls**: Highlight specific curves, adjust opacity, and interact with the plot using zoom and pan tools.
- **Customizable Appearance**: Customize the colormap, curve opacity, and highlight settings to enhance data visualization.
- **Data Export**: Export the displayed data for further analysis, including exporting to Matplotlib for advanced plotting.
- **Flexible Integration**: Can be integrated into both [`BECFigure`](user.widgets.bec_figure) and [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`.
- **Flexible Integration**: Can be integrated into [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`.
````
````{tab} Examples - CLI
`BECMultiWaveform` can be embedded in both [`BECFigure`](user.widgets.bec_figure) and [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`. The command-line API is consistent across these contexts.
`BECMultiWaveform` can be embedded in [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`. The command-line API is consistent across these contexts.
## Example 1 - Adding Multi Waveform to BECFigure
In this example, we demonstrate how to add a `MultiWaveform` plot to a `BECFigure` widget and connect it to a monitor.
```python
# Add a new dock and BECFigure to the GUI
fig = gui.add_dock().add_widget('BECFigure')
# Add a MultiWaveform plot to the figure and set the monitor
multi_waveform = fig.multi_waveform(monitor='waveform1d')
# Optionally, set plot properties
multi_waveform.set_title("Real-Time Multi Waveform")
multi_waveform.set_x_label("Time (s)")
multi_waveform.set_y_label("Amplitude")
```
## Example 2 - Using BECMultiWaveformWidget in BECDockArea
## Example 1 - Using BECMultiWaveformWidget in BECDockArea
You can add `BECMultiWaveformWidget` directly to a `BECDockArea`. This widget includes its own toolbar and controls for interacting with the multi waveform plot.
```python
# Add a new BECMultiWaveformWidget to the BECDockArea
multi_waveform_widget = gui.add_dock().add_widget('BECMultiWaveformWidget')
# Add a new MultiWaveform to the BECDockArea
dock_area = gui.new()
multi_waveform_widget = dock_area.new().new(gui.available_widgets.MultiWaveform)
# Set the monitor from the command line
multi_waveform_widget.set_monitor('waveform1d')
multi_waveform_widget.plot('waveform')
# Optionally, adjust settings
multi_waveform_widget.set_opacity(60)
multi_waveform_widget.set_curve_limit(100)
multi_waveform_widget.opacity = 60
```
## Example 3 - Customizing the Multi Waveform Plot
## Example 2 - Customizing the Multi Waveform Plot
You can customize various aspects of the plot, such as the colormap, opacity, and curve limit.
```python
# Change the colormap to 'viridis'
multi_waveform.set_colormap('viridis')
multi_waveform_widget.color_palette = 'viridis'
# Adjust the opacity of the curves to 70%
multi_waveform.set_opacity(70)
multi_waveform_widget.opacity = 60
# Limit the number of curves displayed to 50
multi_waveform.set_curve_limit(50)
multi_waveform_widget.max_trace = 10
# Enable buffer flush when the curve limit is reached
multi_waveform.set_curve_limit(50, flush_buffer=True)
multi_waveform_widget.flush_buffer = True
```
## Example 4 - Highlighting Curves
## Example 3 - Highlighting Curves
You can highlight specific curves to emphasize important data.
```python
# Disable automatic highlighting of the last curve
multi_waveform.set_highlight_last_curve(False)
multi_waveform.highlight_last_curve = False
# Highlight the third curve (indexing starts from 0)
multi_waveform.set_curve_highlight(2)
multi_waveform.highlighted_index = 2
# Re-enable automatic highlighting of the last curve
multi_waveform.set_highlight_last_curve(True)
multi_waveform.highlight_last_curve = True
```
## Example 5 - Exporting Data
<!-- ## Example 4 - Exporting Data
You can export the data from the multi waveform plot for further analysis.
@ -98,14 +81,14 @@ data_df = multi_waveform.get_all_data(output='pandas')
# Export the plot to Matplotlib for further customization
multi_waveform.export_to_matplotlib()
```
``` -->
````
````{tab} API
```{eval-rst}
.. autoclass:: bec_widgets.widgets.figure.plots.multi_waveform.multi_waveform.BECMultiWaveform
:members:
:inherited-members:
````{tab} API
```{eval-rst}
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.MultiWaveform.rst
```
```
````

View File

@ -7,7 +7,7 @@
The Waveform Widget is used to display 1D detector signals. The widget is directly integrated with the `BEC` framework and can display real-time data from detectors loaded in the current `BEC` session as well as custom data from users.
## Key Features:
- **Flexible Integration**: The widget can be integrated into both [`BECFigure`](user.widgets.bec_figure) and [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`.
- **Flexible Integration**: The widget can be integrated into [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`.
- **Data Visualization**: Real-time plotting of positioner versus detector values from the BEC session, as well as static plotting of custom data.
- **Real-time Data Processing**: Add real-time Data Processing Pipeline (DAP) to the real-time acquisition.
- **Data Export**: Export data to CSV, H5, and other formats.
@ -19,47 +19,27 @@ The Waveform Widget is used to display 1D detector signals. The widget is direct
````{tab} Examples - CLI
`WaveformWidget` can be embedded in both [`BECFigure`](user.widgets.bec_figure) and [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`. However, the command-line API is the same for all cases.
`WaveformWidget` can be embedded in [`BECDockArea`](user.widgets.bec_dock_area), or used as an individual component in your application through `BECDesigner`. However, the command-line API is the same for all cases.
## Example 1 - Adding Waveform Widget to BECFigure
## Example 1 - Adding Waveform Widget as a dock with BECDockArea
In this example, we will demonstrate how to add two different `WaveformWidgets` into a single [`BECFigure`](user.widgets.bec_figure) widget.
```python
# Add new dock with BECFigure widget
fig = gui.add_dock().add_widget('BECFigure')
# Add two WaveformWidgets to the BECFigure
plt1 = fig.plot(x_name='samx', y_name='bpm4i')
plt2 = fig.plot(x_name='samx', y_name='bpm3i')
```
## Example 2 - Adding Waveform Widget as a dock with BECDockArea
Adding `WaveformWidget` into a [`BECDockArea`](user.widgets.bec_dock_area) is similar to adding any other widget. The widget has the same API as the one in BECFigure; however, as an independent widget outside BECFigure, it has its own toolbar, allowing users to configure the widget without needing CLI commands.
Adding `Waveform` into a [`BECDockArea`](user.widgets.bec_dock_area) is similar to adding any other widget.
```python
# Add new WaveformWidgets to the BECDockArea
plt1 = gui.add_dock().add_widget('BECWaveformWidget')
plt2 = gui.add_dock().add_widget('BECWaveformWidget')
dock_area = gui.new('my_new_dock_area') # Create a new dock area
plt1 = dock_area.new().new('Waveform')
plt2 = gui.my_new_dock_area.new().new(gui.available_widgets.Waveform) # as an alternative example via dynamic name space
# Add signals to the WaveformWidget
plt1.plot(x_name='samx', y_name='bpm4i')
plt2.plot(x_name='samx', y_name='bpm3i')
```
## Example 3 - Adding Waveform Widget with curves
```python
# adds a new dock, a new BECFigure and a BECWaveForm to the dock
plt = gui.add_dock().add_widget('BECFigure').plot(x_name='samx', y_name='bpm4i')
# add a second curve to the same plot
plt.plot(x_name='samx', y_name='bpm3i')
# set axis labels
plt.set_title("Gauss plots vs. samx")
plt.set_x_label("Motor X")
plt.set_y_label("Gauss Signal (A.U.")
plt1.set_title("Gauss plots vs. samx")
plt1.set_x_label("Motor X")
plt1.set_y_label("Gauss Signal (A.U.")
```
```{note}
@ -73,27 +53,25 @@ dev.bpm4i.sim.select_sim_model("GaussianModel")
# bpm3i uses StepModel and samx as a reference; default settings
dev.bpm3i.sim.select_sim_model("StepModel")
```
## Example 4 - Adding Data Processing Pipeline Curve with LMFit Models
## Example 2- Adding Data Processing Pipeline Curve with LMFit Models
In addition to the scan curve, you can also add a second curve that fits the signal using a specified model from [LMFit](https://lmfit.github.io/lmfit-py/builtin_models.html). The following code snippet demonstrates how to create a 1D waveform curve with an attached DAP process, or how to add a DAP process to an existing curve using the BEC CLI. Please note that for this example, both devices were set as Gaussian signals. You can also add a region of interest (roi) to the plot which will respected by all running DAP processes.
```python
# Add a new dock, a new BECFigure, and a BECWaveForm to the dock with a GaussianModel DAP
plt = gui.add_dock().add_widget('BECFigure').plot(x_name='samx', y_name='bpm4i', dap="GaussianModel")
# Add a new dock_area, dock and Waveform and plot bpm4i vs samx with a GaussianModel DAP
plt = gui.new().new().new('Waveform')
plt.plot(x_name='samx', y_name='bpm4i', dap="GaussianModel")
# Add a second curve to the same plot without DAP
plt.plot(x_name='samx', y_name='bpm3a')
# Add DAP to the second curve
plt.add_dap(x_name='samx', y_name='bpm3a', dap="GaussianModel")
plt.add_dap_curve(device_label='bpm3a-bpm3a', dap_name='GaussianModel')
# Add roi to the plot, this limits the DAP fit to the selected region x_min=-1, x_max=1
# Add ROI to the plot, this limits the DAP fit to the selected region x_min=-1, x_max=1
# The fit will automatically update
plt.select_roi(region=(-1, 1))
# To remove the DAP from the curve, you can use the toggle button in the toolbar or the following command
plt.toggle_roi(False)
```
To get the parameters of the fit, you need to retrieve the curve objects and call the `dap_params` property.
@ -119,21 +97,29 @@ print(dap_bpm3a.dap_params)
![Waveform 1D_DAP](./bec_figure_dap.gif)
## Example 5 - 2D Waveform Scatter Plot
## Example 3 - 2D ScatterWaveform plot
The 2D scatter plot widget is designed for more complex data visualization. It employs a false color map to represent a third dimension (z-axis), making it an ideal tool for visualizing multidimensional data sets.
```python
# adds a new dock, a new BECFigure and a BECWaveForm to the dock
# Add a new dock_area, a new dock and a BECWaveForm to the dock
plt = gui.new().new().new(gui.available_widgets.ScatterWaveform)
plt.plot(x_name='samx', y_name='samy', z_name='bpm4i')
plt = gui.add_dock().add_widget('BECFigure').add_plot(x_name='samx', y_name='samy', z_name='bpm4i')
```
![Scatter 2D](./scatter_2D.gif)
```{note}
The ScatterWaveform widget only plots the data points if both x and y axis motors are moving. Or more generally, if all signals are of readout type *monitored*.
```
````
````{tab} API
```{eval-rst}
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.BECWaveform.rst
.. include:: /api_reference/_autosummary/bec_widgets.cli.client.Waveform.rst
```
````