The widgets.silx_plot sub-package#

Package with subclassed silx widgets and actions.

class pydidas.widgets.silx_plot.AutoscaleToMeanAndThreeSigma(plot: PydidasPlot2d, **kwargs: dict)#

Bases: PlotAction

A new custom PlotAction to set the colormap to autoscale with mean +/- 3 sigma.

Parameters:
  • plot (silx.gui.plot.PlotWidget) – The associated plot widget.

  • **kwargs

    Supported keyword arguments are:

    parentUnion[None, QObject], optional

    The parent QObject. The default is None.

    forced_image_legendUnion[None, str], optional

    A fixed image legend to use for enforcing the rescaling, if multiple image items are in a plot. None defaults to the active image. The default is None.

class pydidas.widgets.silx_plot.ChangeCanvasToData(plot: PydidasPlot2d, **kwargs: dict)#

Bases: PlotAction

A customized silx Action to change the size of the figure canvas to the data dimensions.

class pydidas.widgets.silx_plot.CropHistogramOutliers(plot: PydidasPlot2d, **kwargs: dict)#

Bases: PlotAction, PydidasQsettingsMixin

A new custom PlotAction to crop outliers from the histogram.

This action will use the global ‘histogram_outlier_fraction’ QSettings value to determine where to limit the histogram and pick the respective value as new upper limit.

The resolution for the upper limit is 27 bit, implemented in two tiers of 12 bit and 15 bit, respective to the full range of the image. For an Eiger detector, this corresponds to minimal final bins of 32 counts.

The lower limit is implemented in two tiers of 12 bit.

Parameters:
  • plot (silx.gui.plot.PlotWidget) – The associated plot widget.

  • **kwargs

    Supported keyword arguments are:

    parentUnion[None, QObject], optional

    The parent QObject. The default is None.

    forced_image_legendUnion[None, str], optional

    A fixed image legend to use for enforcing the rescaling, if multiple image items are in a plot. None defaults to the active image. The default is None.

class pydidas.widgets.silx_plot.ExpandCanvas(plot: PydidasPlot2d, **kwargs: dict)#

Bases: PlotAction

A modified silx ResetZoomAction which also resets the figure canvas to the maximum size allowed by the widget.

class pydidas.widgets.silx_plot.PydidasGetDataInfoAction(plot: PydidasPlot2d, **kwargs: dict)#

Bases: PlotAction

Action to select a datapoint and show more information about this datapoint.

class pydidas.widgets.silx_plot.PydidasImageView(**kwargs: dict)#

Bases: ImageView, PydidasQsettingsMixin

A customized silx.gui.plot.ImageView with an additional configuration.

Parameters:

**kwargs (dict) –

Supported keyword arguments are:

parentUnion[QWidget, None], optional

The parent widget or None for no parent. The default is None.

backendUnion[None, silx.gui.plot.backends.BackendBase], optional

The silx backend to use. If None, this defaults to the standard silx settings. The default is None.

show_cs_transformbool, optional

Flag whether to show the coordinate transform action. The default is True.

display_image(data: ndarray, **kwargs: dict)#

Set the image data, handle the coordinate system and forward the data to plotting.

Parameters:
  • data (np.ndarray) – The image data.

  • **kwargs (dict) – Optional kwargs for the ImageView.setImage method.

update_from_diffraction_exp()#

Get the detector size from the DiffractionExperimentContext and store it.

update_mpl_fonts()#

Update the plot’s fonts.

user_config_update(key: str, value: str)#

Handle a user config update.

Parameters:
  • key (str) – The name of the updated key.

  • value – The new value of the updated key.

class pydidas.widgets.silx_plot.PydidasLoadImageAction(parent, caption='Select image file', ref=None)#

Bases: QAction

Action to load an image using the pydidas file dialog.

This action is used as additional option in the pyFAI calibration widgets.

Parameters:
  • caption (str, optional) – The caption string for the file dialog. The default is ‘Select image file.’

  • ref (str, optional) – The reference for a persistent QSettings reference to the directory. The default is None.

class pydidas.widgets.silx_plot.PydidasMaskToolsWidget(parent: None | QWidget = None, plot: None | QWidget = None, **kwargs: dict)#

Bases: MaskToolsWidget

A customized silx.gui.plot.MaskToolsWidget with larger buttons.

class pydidas.widgets.silx_plot.PydidasPlot1D(**kwargs: dict)#

Bases: Plot1D

A customized silx.gui.plot.Plot1D with an additional configuration.

clear_plot(clear_data: bool = True)#

Clear the plot and remove all items.

Parameters:

clear_data (bool, optional) – Flag to remove all items from the stored data dictionary as well.

plot_pydidas_dataset(data: Dataset, **kwargs: dict)#

Plot a pydidas dataset.

Parameters:
  • data (pydidas.core.Dataset) – The data to be plotted.

  • **kwargs (dict) – Additional keyword arguments to be passed to the silx plot method.

update_mpl_fonts()#

Update the plot’s fonts.

class pydidas.widgets.silx_plot.PydidasPlot2D(**kwargs: dict)#

Bases: Plot2D, PydidasQsettingsMixin

A customized silx.gui.plot.Plot2D with an additional features.

Additional features are implemented through additional SilxActions which are added to the toolbar.

addImage(data: ndarray, **kwargs: dict)#

Add an image to the plot.

This method implements an additional dimensionality check before passing the image to the Plot2d.addImage method.

Parameters:
  • data (np.ndarray) – The input data to be displayed.

  • **kwargs (dict) – Any supported Plot2d.addImage keyword arguments.

clear_plot()#

Clear the plot and remove all items.

enable_cs_transform(enable: bool)#

Enable or disable the coordinate system transformations.

Parameters:

enable (bool) – Flag to enable the coordinate system transformations.

plot_pydidas_dataset(data: Dataset, **kwargs: dict)#

Plot a pydidas dataset.

Parameters:
  • data (pydidas.core.Dataset) – The data to be plotted.

  • **kwargs (dict) – Additional keyword arguments to be passed to the silx plot method.

setData(data, legend=None, info=None, replace=False, z=None, selectable=None, draggable=None, colormap=None, pixmap=None, xlabel=None, ylabel=None, origin=None, scale=None, resetzoom=True, copy=True)#

Add a 2D dataset or an image to the plot.

It displays either an array of data using a colormap or a RGB(A) image.

Images are uniquely identified by their legend. To add multiple images, call addImage() multiple times with different legend argument. To replace/update an existing image, call addImage() with the existing image legend.

When image parameters are not provided, if an image with the same legend is displayed in the plot, its parameters are used.

Parameters:
  • data (numpy.ndarray) – (nrows, ncolumns) data or (nrows, ncolumns, RGBA) ubyte array Note: boolean values are converted to int8.

  • legend (str) – The legend to be associated to the image (or None)

  • info – User-defined information associated to the image

  • replace (bool) – True to delete already existing images (Default: False).

  • z (int) – Layer on which to draw the image (default: 0) This allows to control the overlay.

  • selectable (bool) – Indicate if the image can be selected. (default: False)

  • draggable (bool) – Indicate if the image can be moved. (default: False)

  • colormap (Union[Colormap, dict]) – Colormap object to use (or None). This is ignored if data is a RGB(A) image.

  • pixmap ((nrows, ncolumns, RGBA) ubyte array or None (default)) – Pixmap representation of the data (if any)

  • xlabel (str) – X axis label to show when this curve is active, or None to keep default axis label.

  • ylabel (str) – Y axis label to show when this curve is active, or None to keep default axis label.

  • origin (float or 2-tuple of float) – (origin X, origin Y) of the data. It is possible to pass a single float if both coordinates are equal. Default: (0., 0.)

  • scale (float or 2-tuple of float) – (scale X, scale Y) of the data. It is possible to pass a single float if both coordinates are equal. Default: (1., 1.)

  • resetzoom (bool) – True (the default) to reset the zoom.

  • copy (bool) – True make a copy of the data (default), False to use provided arrays.

Returns:

The image item

update_cs_units(x_unit: str, y_unit: str)#

Update the coordinate system units.

Note: Any changes to the CS transform will overwrite these settings.

Parameters:
  • x_unit (str) – The unit for the data x-axis.

  • y_unit (str) – The unit for the data y-axis

update_exp_setup_params()#

Check that the detector is valid for a CS transform.

update_mpl_fonts()#

Update the plot’s fonts.

user_config_update(key: str, value: str)#

Handle a user config update.

Parameters:
  • key (str) – The name of the updated key.

  • value – The new value of the updated key.

class pydidas.widgets.silx_plot.PydidasPlot2DwithIntegrationRegions(**kwargs: dict)#

Bases: PydidasPlot2D

An extended PydidasPlot2D which allows to show integration regions.

draw_circle(radius: float, legend: str, center: None | Tuple[float, float] = None)#

Draw a circle with the given radius and store it as the given legend.

Parameters:
  • radius (float) – The circle radius in pixels.

  • legend (str) – The shape’s legend for referencing it in the plot.

  • center (Union[None, Tuple[float, float]], optional) – The center of the circle. If None, this defaults to the DiffractionExperiment beamcenter. The default is None.

draw_integration_region(radial: None | Tuple[float, float], azimuthal: None | Tuple[float, float])#

Draw the given integration region.

Parameters:
  • radial (Union[None, Tuple[float, float]]) – The radial integration region. Use None for the full detector or a tuple with (r_inner, r_outer) in pixels to select a region.

  • azimuthal (Union[None, Tuple[float, float]]) – The azimuthal integration region. Use None for the full detector or a tuple with (azi_start, azi_end) in radians for a region.

draw_line_from_beamcenter(chi: float, legend: str)#

Draw a line from the beamcenter in the direction given by the angle chi.

Parameters:
  • chi (float) – The pointing angle, given in rad.

  • legend (str) – The reference legend entry for this line.

set_marker_color(color: str)#

Set the new marker color.

Parameters:

color (str) – The marker color name.

class pydidas.widgets.silx_plot.PydidasPlotStack(**kwargs: dict)#

Bases: QStackedWidget

A stack with two plots for 1d and 2d data which selects the correct to display.

Parameters:

**kwargs (dict) –

Supported keyword arguments are:

parentUnion[QtWidgets.QWidget, None]

The parent widget.

use_data_info_actionbool, optional

Flag to use the PydidasGetDataInfoAction to display information about a result datapoint. The default is False.

diffraction_expDiffractionExperiment, optional

The DiffractionExperiment instance to be used in the PydidasPlot2D for the coordinate system. The default is the generic DiffractionExperimentContext.

cs_transformbool, optional

Flag to enable coordinate system transformations.

clear_plots()#

Clear all plots.

plot_data(data: Dataset, **kwargs: dict)#

Plot the given data.

Parameters:
  • data (pydidas.core.Dataset) – The data to be plotted.

  • **kwargs (dict) – Any additional keywords to be passed to the plot.

pydidas.widgets.silx_plot.get_2d_silx_plot_ax_settings(axis: ndarray) tuple[float, float]#

Get the axis settings to have pixels centered at their values.

Parameters:

axis (np.ndarray) – The numpy array with the axis positions.

Returns:

  • _origin (float) – The value for the axis origin.

  • _scale (float) – The value for the axis scale to squeeze it into the correct dimensions for silx ImageView.

pydidas.widgets.silx_plot.user_config_update_func(self, key: str, value: str)#

Handle a user config update.

Parameters:
  • key (str) – The name of the updated key.

  • value – The new value of the updated key.