reborn.viewers.qtviews package

Subpackages

Submodules

reborn.viewers.qtviews.padviews module

class reborn.viewers.qtviews.padviews.PADViewMainWindow(main=True)[source]

Bases: QMainWindow

A QMainWindow that closes all windows when it is closed. Be careful…

closeEvent(self, a0: Optional[QCloseEvent])[source]
class reborn.viewers.qtviews.padviews.PADView(frame_getter=None, data=None, pad_geometry=None, mask=None, beam=None, levels=None, percentiles=None, debug_level=0, main=True, dataframe_preprocessor=None, title=None, **kwargs)[source]

Bases: QObject

This is supposed to be an easy way to view PAD data. It is a work in progress… but here is the basic concept:

PADView relies on a FrameGetter subclass to serve up DataFrame instances.

Parameters:
  • frame_getter (FrameGetter subclass) – The preferred way to flip through many frames.

  • data (DataFrame or ndarray) – The data to be displayed.

  • pad_geometry (PADGeometryList) – PAD geometry information.

  • mask (ndarray) – Data masks.

  • beam (Beam) – X-ray beam parameters.

  • levels (tuple) – The minimum and maximum levels for the colormap.

  • percentiles (tuple) – The minimum and maximum percentages for the colormap.

  • debug_level (int) – The debug level. Larger values are more verbose.

  • main (bool) – Set to False if you don’t want this window to close all other windows when it is closed.

  • hold_levels (bool) – If True, do not attempt to re-scale the colormap for each frame.

  • dataframe_preprocessor (function) – Upon updating the DataFrame instance, apply this function. Must return a DataFrame instance.

show_histogram = True
downsample_function = None
hold_pad_geometry = True
hold_beam = True
hold_mask = True
hold_levels = False
skip_empty_frames = True
sig_geometry_changed

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

sig_beam_changed

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

sig_dataframe_changed

int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Type:

pyqtSignal(*types, name

Type:

str = …, revision

debug(msg='', level=1)[source]

Add debug message to the reborn logger. For historical reasons, the PADView debug levels are:

  • 1: Ordinary debug message (e.g. change mask).

  • 2: Verbose debug message (e.g. PAD ImageItem transformations).

  • 3: Very verbose debug (e.g. mouse movement).

These levels differ from standard Python logging debug level. The above values map to Python logging as follows:

  • 1: logging.DEBUG = 10

  • 2: logging.DEBUG - 2 = 8

  • 3: logging.DEBUG - 4 = 6

Parameters:
  • msg (str) – The desired debug message

  • level (int) – Specify level of verbosity required to log the message

get_pad_geometry() PADGeometryList[source]

Return the currently displayed PADGeometryList

set_pad_geometry(geom)[source]
get_dataframe() DataFrame[source]

Return the currently shown DataFrame instance.

set_dataframe(data)[source]
get_beam() Beam[source]

Return the currently displayed Beam

set_beam(beam: (None, <class 'reborn.source.Beam'>))[source]
get_mask(as_list=False) ndarray[source]

Return the currently displayed mask

set_mask(mask: (None, <class 'numpy.ndarray'>))[source]
get_pad_display_data(as_list=False) -> (<class 'list'>, <class 'numpy.ndarray'>)[source]
set_pad_display_data(data)[source]
set_title(title=None, fixed=False)[source]

Set the title of the main window.

set_shortcut(key_sequence, function, allow_auto_repeat=False)[source]

Setup one keyboard shortcut so it connects to some function, assuming no arguments are needed.

set_colormap(preset=None)[source]

Change the colormap to one of the presets configured in pyqtgraph. Right-click on the colorbar to find out what values are allowed.

get_levels()[source]

Get the minimum and maximum levels of the current image display.

set_levels(levels=None, percentiles=None, colormap=None)[source]

This method handles setting levels (i.e. mapping the upper and lower bounds of detector pixel values to the span of the color table).

If no arguments are provided, the default settings are used.

Level setting is a somewhat complicated matter. For both the upper and lower bounds, there are 5 ways that we presently set the levels of the display data. In order of priority, highest first:

  1. Set the level to the particular value specified in the levels keyword argument of this method.

  2. Set the level to the value corresponding to the Nth percentile of the current display data, using the percentiles keyword argument.

  3. Leave the levels alone; keep the previous levels.

An additional option is to mirror the levels: i.e. set the levels to range from [-x, +x]. This is controlled via the “mirror_levels” attribute.

When determining levels from percentiles, it is possible to ignore masked pixels. This is controlled by the attribute “levels_ignore_masked”.

Parameters:
  • levels (tuple of floats) – Fixed-value levels. Default is (None, None).

  • percentiles (tuple of floats) – Percentiles for determining levels. Values should be 0-100. Default is (None, None)

  • colormap – For convenience, you may also specify a new colormap. This is passed to “set_colormap”.

add_rectangle_roi(pos=(0, 0), size=None, movable=True)[source]

Adds a pyqtgraph RectROI

add_circle_roi(pos=(0, 0), radius=None, moveable=True)[source]
show_rois()[source]
hide_rois()[source]
toggle_rois()[source]
show_coordinate_axes()[source]
hide_coordinate_axes()[source]
toggle_coordinate_axes()[source]
show_fast_scan_directions()[source]
hide_fast_scan_directions()[source]
toggle_fast_scan_directions()[source]
show_pad_labels(as_indices=False)[source]
hide_pad_labels()[source]
toggle_pad_labels(as_indices=False)[source]
show_pad_indices()[source]
hide_pad_indices()[source]
toggle_pad_indices()[source]
choose_mask_color()[source]
get_mask_color()[source]
set_mask_color(color)[source]
update_masks(masks=None)[source]

Update the mask that is displayed.

Note

As a side effect, the current dataframe will be updated with the provided mask

hide_masks()[source]
show_masks()[source]
toggle_masks()[source]
save_masks()[source]

Save list of masks in pickle or reborn mask format.

load_masks()[source]

Load list of masks that have been saved in pickle or reborn mask format.

clear_masks()[source]
clear_processed_data()[source]

Clear processed data and (show raw data).

update_pads()[source]

Update only the PAD data that is displayed, including colormap. Usually you should run update_display, which will trigger this method at the appropriate time.

update_pad_geometry(pad_geometry=None)[source]

Use this when you want the display to reflect a change in the geometry. Applies Qt transforms to the PAD ImageItems. Also emits the sig_geometry_changed signal.

If you are changing an entire dataframe, use the update_display method instead as it will catch geometry changes according to the geometry policy.

Parameters:

pad_geometry (PADGeometryList) – PAD Geometry. If None, get the geometry from the current dataframe.

update_beam(beam=None)[source]

Use this when you want the display to reflect a change in the beam properties. Affects e.g. the q values shown in the statusbar. Also emits the sig_beam_changed signal.

If you are changing an entire dataframe, use the update_display method instead as it will catch beam changes according to the beam policy.

Parameters:

beam (Beam) – Beam info. If None, get the beam from the current dataframe.

update_dataframe(dataframe, _run_preprocessor=False)[source]

Change the dataframe. If need be, this will trigger calls to the update_beam method, the update_pad_geometry method, and the update_mask method.

Parameters:
  • dataframe (DataFrame) – The new dataframe

  • _run_preprocessor (bool) – Run the pre-processors on the dataframe. This should only be done by methods such as get_next_frame.

update_display(dataframe=None, data_changed=True, beam_changed=True, geom_changed=True, mask_changed=True)[source]

Update display, e.g. when moving to next frame. The PAD data will always be updated, and will reflect the data in the current DataFrame unless it is explicitly provided in the method call. The Beam, PADGeometryList, and mask will be updated but optionally these updates may be skipped using the relevant options.

Side effects: self.dataframe might be modified, if a DataFrame is provided. When updating

Parameters:

dataframe (DataFrame) – Optional input dataframe. Will use self.dataframe otherwise.

save_pad_geometry()[source]

Save list of pad geometry specifications in json format.

load_pad_geometry()[source]

Load list of pad geometry specifications in json format.

save_beam()[source]

Save beam specifications in json format.

load_beam()[source]

Load beam specifications in json format.

static vector_to_view_coords(vec)[source]

If you have a vector (or vectors) pointing in some direction in space, this function provides the point at which it intercepts with the view plane (the plane that is 1 meter away from the origin).

get_pad_coords_from_view_coords(view_coords)[source]

Get PAD coordinates (slow-scan index, fast-scan index, PAD index) from view coordinates. The view coordinates correspond to the plane that is 1 meter away from the origin.

get_pad_coords_from_mouse_pos()[source]

Maps mouse cursor position to view coordinates, then maps the view coords to PAD coordinates.

get_view_coords_from_mouse_pos()[source]

Map the current mouse cursor position to the display plane situated 1 meter from the interaction point.

get_view_bounding_rect()[source]

Bounding rectangle of everything presently visible, in view (i.e real-space, 1-meter plane) coordinates.

mouse_moved(evt)[source]

Updates the status string with info about mouse position (e.g. data value under cursor).

add_ring(radius=None, angle=None, q_mag=None, d_spacing=None, pen=None)[source]
update_rings()[source]

Update rings (needed if the Beam changes).

remove_rings()[source]
show_grid()[source]
hide_grid()[source]
toggle_grid()[source]
show_pad_border(n, pen=None)[source]
hide_pad_border(n)[source]
show_pad_borders(pen=None)[source]
hide_pad_borders()[source]
show_history_next()[source]
show_history_previous()[source]
show_next_frame(skip=1)[source]
show_previous_frame(skip=1)[source]
show_random_frame()[source]
show_frame(frame_number=0)[source]
show_first_frame()[source]
reload_current_frame()[source]
add_plot_item(*args, **kargs)[source]

Example: self.add_plot_item(x, y, pen=pg.mkPen(width=3, color=’g’))

add_scatter_plot(*args, **kargs)[source]
remove_scatter_plots()[source]
load_pickled_dataframe(file_name)[source]

Load data in pickle format. Should be a dictionary with keys:

mask_data, pad_display_data, beam, pad_geometry

save_pickled_dataframe(file_name)[source]

Save dataframe in pickle format. It is a dictionary with the keys:

mask_data, pad_display_data, beam, pad_geometry

load_npy_file(file_name)[source]

Load data in numpy (npy) format. Note that this format only contains the diffraction intensity data; there is no geometry or beam information.

save_npy_file(file_name)[source]

Save data in numpy (npy) format. Note that this format only contains the diffraction intensity data; there is no geometry or beam information.

open_data_file_dialog()[source]
save_data_file_dialog()[source]

Save list of masks in pickle or reborn mask format.

vector_coords_to_2d_display_coords(vecs)[source]

Convert 3D vector coords to the equivalent coords in the 2D display plane. This corresponds to ignoring the “z” coordinate, and scaling the “x,y” coordinates to that of an equivalent detector located at a distance of 1 meter from the origin. Simply put: remove the z component, divide the x,y components by the z component

panel_scatter_plot(panel_number, ss_coords, fs_coords, style=None)[source]

Scatter plot points given coordinates (i.e. indices) corresponding to a particular panel. This will take care of the re-mapping to the display coordinates.

property display_editor_widget
property mask_editor_widget
property frame_navigator_widget
property ring_editor_widget
property runstats_widget
property display_options_widget
property edit_geometry_widget
property swaxs_simulator_widget
property beam_editor_widget
import_plugin_module(module_name)[source]
run_plugin(module_name)[source]
start()[source]
stop()[source]
show()[source]
save_screenshot_dialog()[source]
save_screenshot(filename)[source]
save_file_dialog(title='Filepath', default='file', types=None)[source]
tic(msg)[source]
toc()[source]
histogram_widget(histdat, bin_range, extra={})[source]

Experimental. Opens some plots that show pixel histograms.

Parameters:
  • histdat (ndarray) – A 2D array with pixel histograms. First index is pixel index.

  • bin_range (tuple) – The first and last values corresponding to bin centers. Assumes regular binning.

reborn.viewers.qtviews.padviews.view_pad_data(data=None, pad_geometry=None, show=True, title=None, **kwargs)[source]

Convenience function that creates a PADView instance and starts it.

class reborn.viewers.qtviews.padviews.DummyFrameGetter(*args, **kwargs)[source]

Bases: FrameGetter

Makes a FrameGetter for a single DataFrame.

Ideally, a DataFrame instance is provided, which has PADGeometry, Beam, etc. information.

Alternatively, data can be provided as a single ndarray, as a list of ndarray, or, for legacy purposes, as a dictionary with the ‘pad_data’ key in it. If so, then you should at least provide the PADGeometry and Beam information, else some garbage numbers will be created for you.

Parameters:
  • dataframe

  • data

  • pad_geometry

get_data(frame_number=0)[source]

You must overrider this when making a subclass. You can do anything you want here, but you must return a valid DataFrame instance. Do not attempt to modify any private attributes of the abstract base class. Any property prefixed with an underscore is off-limits.

reborn.viewers.qtviews.padviews.show_and_raise(widget)[source]

reborn.viewers.qtviews.qtviews module

reborn.viewers.qtviews.qtviews.pens = [<PyQt5.QtGui.QPen object>, <PyQt5.QtGui.QPen object>, <PyQt5.QtGui.QPen object>, <PyQt5.QtGui.QPen object>, <PyQt5.QtGui.QPen object>, <PyQt5.QtGui.QPen object>, <PyQt5.QtGui.QPen object>, <PyQt5.QtGui.QPen object>]

This is supposed to have various viewers that use pyqtgraph. It’s mostly useless right now.

reborn.viewers.qtviews.qtviews.bright_colors(i, alpha=1)[source]

Some nice colors. Only 8 available, which loops around as the input index increments.

class reborn.viewers.qtviews.qtviews.Volumetric3D[source]

Bases: object

View a 3D density map

add_density(rho, color=None)[source]
add_grid()[source]
add_lines(r, color=None, width=None)[source]
add_rgb_axis(length=None, width=None)[source]
show(smooth=True, hold=True, kill=True)[source]
reborn.viewers.qtviews.qtviews.plot_multiple_images(images, title=None, n_rows=None, hold=True, kill=True)[source]
reborn.viewers.qtviews.qtviews.MapProjection(data, axis=None, hold=True, kill=True, title=None)[source]

View a 3D density map as a projection along selected axes (which can be a list)

reborn.viewers.qtviews.qtviews.MapSlices(data, axis=None, levels=None, hold=True, kill=True, title=None)[source]

View a 3D density map as a projection along selected axes (which can be a list)

class reborn.viewers.qtviews.qtviews.Scatter3D(title=None)[source]

Bases: object

Simple viewer for 3D scatter plots.

app = None
add_points(r, color=None, size=None)[source]

Add an Nx3 array of points r with specified color and size. Color is a 3-element Python list and size is a float scalar.

add_lines(r, color=None, width=None)[source]
add_rgb_axis(length=None, width=None)[source]
add_unit_cell(cell, width=None)[source]
set_orthographic_projection()[source]
show(hold=True, kill=True)[source]
reborn.viewers.qtviews.qtviews.scatter_plot(vecs)[source]
reborn.viewers.qtviews.qtviews.view_finite_crystal(finite_crystal)[source]

Shows the lattice points of all the symmetry partners of a finite crystal with pyqtgraph and also the atoms of one asymmetric unit

reborn.viewers.qtviews.qtviews.view_density_map(data, title=None)[source]

Module contents