quicknxs.views package

QuickNXS Views/Visual components.

quicknxs.views.load_ui(ui_filename: str, base_instance: Q) Q[source]

Submodules

quicknxs.views.compare module

class quicknxs.views.compare.CompareDialog(*args, **kwargs)[source]

Bases: QDialog

A simple dialog window with a CompareWidget.

class quicknxs.views.compare.CompareWidget(parent)[source]

Bases: QWidget

Widget to compare different reflectivities.

changing_table = False
clear_item()[source]

Remove all current plotted data.

clear_plot()[source]

Remove all current plotted data.

draw()[source]

Draw data.

edit_cell(row, column)[source]

Cell editing call-back. Deal with color picking.

open_file()[source]

Show Open-File dialog.

read_file(file_path: str)[source]

Read a data file.

refl_preview(checked=True)[source]

Call-back method for when the user toggles the preview check box.

update_preview()[source]

Update the preview data.

quicknxs.views.deadtime_entry module

class quicknxs.views.deadtime_entry.DeadTimeEntryPoint(title='Dead Time Correction')[source]

Bases: QGroupBox

Group box for dead-time correction settings.

class VerifyChangeCheckBox(*args, **kwargs)[source]

Bases: QCheckBox

Checkbox for applying dead-time correction.

Intercepts the state change to ask user to confirm the change in dead-time settings, since it requires reloading all files

ask_user_ok_to_reload_files()[source]

Shows dialog asking user to confirm reloading all files.

mousePressEvent(self, e: QMouseEvent | None)[source]
initUI()[source]
reload_files_signal

Signal emitted when files should be reloaded.

toggleSettingsButton(state)[source]

quicknxs.views.deadtime_settings module

class quicknxs.views.deadtime_settings.DeadTimeSettingsView(parent: QWidget)[source]

Bases: QDialog

Dialog to choose the dead time correction options.

accept()[source]

Read in the options on the form when the OK button is clicked and update the global configuration.

ask_user_ok_to_reload_files()[source]

Shows dialog asking user to confirm reloading all files.

check_values_changed()[source]

Check if the dialog settings entries have been changed by the user.

Returns:

bool

  • False if dialog values are the same as the global configuration

Return type:

  • True if dialog values are different from the global configuration

reload_files_signal

Signal emitted when files should be reloaded.

set_state_from_global_config()[source]

Populate the form with the current global configuration.

quicknxs.views.diagnostic_widget module

class quicknxs.views.diagnostic_widget.DiagnosticWidget(parent=None)[source]

Bases: object

Standalone widget for displaying diagnostic information when cross-sections cannot be loaded.

Initialize the diagnostic widget.

Parameters:

parent – Parent widget (typically the main window)

show(diag_data: DiagnosticData)[source]

Show diagnostic dialog with run information.

Parameters:

diag_data – DiagnosticData containing information from the run

quicknxs.views.load_ui module

Python interface for the Qt UI files.

class quicknxs.views.load_ui.Q

Generic type for QMainWindow, QDialog, or QWidget.

alias of TypeVar(‘Q’, ~PyQt5.QtWidgets.QMainWindow, ~PyQt5.QtWidgets.QDialog, ~PyQt5.QtWidgets.QWidget)

quicknxs.views.load_ui.load_ui(ui_filename: str, base_instance: Q) Q[source]

quicknxs.views.main_window module

class quicknxs.views.main_window.MainWindow[source]

Bases: QMainWindow

Main application window.

Initialization.

addDataTable()[source]

Add data tab for additional peaks/ROIs.

addRefl()[source]

Signal handling to add a new reflectivity data set.

add_data_tab_by_index(tab_index: int)[source]

Add/update a specific data tab.

add_direct_beam()[source]
apply_offspec_crop()[source]
autoRef()[source]

Signal handling to run automated file selection.

changeRegionValues()[source]

Called when the reflectivity extraction region has been changed.

Sets up a trigger to replot the reflectivity with a delay so a subsequent change can occur without several replots.

change_active_cross_section(is_checked: bool)[source]

Update the run info and overview plots when the active cross section is changed.

The toggled() signal is emitted from both radio buttons whose states were changed, therefore, use the bool value to only perform update actions once.

Parameters:

is_checked (bool) – The state of the radio button that emitted the signal.

change_gisans_colorscale()[source]
change_offspec_colorscale()[source]

Change the intensity limits for the color scale of the off-specular plots.

clearRefList()[source]

Signal handling to clear the reflectivity data set list.

clear_direct_beam_list()[source]

Signal handling.

closeEvent(event)[source]

Close UI event.

current_table_changed(tab_index: int)[source]

Update the state for active data set and the UI.

cutPoints()[source]

Cut the start and end of the active data set to 5% of its maximum intensity.

direct_beam_table_changed(item: QTableWidgetItem)[source]
direct_beam_table_right_click(pos: QPoint)[source]

Handle right-click on the direct beam table.

file_loaded()[source]

Update UI after a file is loaded.

file_loaded_signal

Signal emitted when a file is loaded.

file_open_dialog()[source]

Show a dialog to open a new file.

file_open_from_list()[source]

Called when a new file is selected from the file list. This is an event call.

file_open_sum_dialog()[source]

Read a set of congruent file data sets.

Select a list of event or histogram files, check their metadata is compatible, and read-in.

get_direct_beam()[source]

Retrieve the direct beam data for the active reflectivity data.

This is used to normalize the distributions we are plotting. See plotting.plot_xtof and plotting.plot_overview

global_reflectivity_config_changed()[source]

Perform action upon change in global reflectivity configuration.

handle_roi_checkbox(state)[source]

Handle the ROI checkbox state change.

hide_data_table()[source]
hide_run_data()[source]
hide_sidebar()[source]
hide_unsupported()[source]

Hide what we don’t support.

initialize_instrument()[source]

Initialize instrument according to the instrument and saved parameters.

initiate_projection_plot(bool)

Signal to initiate the projection plot.

initiate_reflectivity_or_intensity_plot

Signal to initiate the reflectivity or intensity plot.

keyPressEvent(event)[source]

UI event.

keyReleaseEvent(event)[source]

UI event.

loadExtraction()[source]
match_direct_beam_clicked()[source]

Find the best direct beam run for the activate data set and compute the reflectivity as needed.

normalizeTotalReflection()[source]

Stitch the reflectivity parts and normalize to 1.

openByNumber()[source]

Signal handling to open a file by run number.

open_advanced_background()[source]
open_deadtime_settings()[source]

Show the dialog for dead-time options.

Update global configuration parameters upon closing the dialog.

open_polarization_window()[source]
open_rawdata_dialog()[source]
plotActiveTab()[source]

Select the appropriate function to plot all visible images.

plot_view

Setting auto_change_active = True bypasses execution of: - MainWindow.file_open_from_list() - MainWindow.changeRegionValues() - MainHandler.reduction_table_changed() - MainHandler.direct_beam_table_changed()

propagate_binning_options_to_runs()[source]

Apply the binning options in the global reflectivity extraction panel to all runs.

reduceDatasets()[source]

Open a dialog to select reduction options for the current list of reduction items.

reductionTableChanged(item)[source]

Perform action upon change in data reduction list.

reduction_table_right_click(pos: QPoint)[source]

Handle right-click on the reduction table.

refresh_file_list()[source]
refresh_offspec()[source]

Refresh / recalculate the off-specular plots.

reload_all_files()[source]

Reload all previously loaded files upon change in loading configuration.

reload_file()[source]

Reload the file that is currently selected form the list.

removeDataTable()[source]

Remove last data tab for additional peaks/ROI:s

removeRefl()[source]

Signal handling to remove a reflectivity data set.

remove_direct_beam()[source]

Signal handling.

replotProjections()[source]

Signal handling to replot the projections.

reset_data_tabs()[source]

Reset UI to one visible data tab.

set_active_direct_beam(checked: bool, row: int)[source]

Select a data set when the user changes the active run radio button (col 0) in the direct beam table.

set_active_reduction_data(checked: bool, row: int)[source]

Select a data set (when checking the active box in the normalization/reduction table).

show_results()[source]
stripOverlap()[source]

Remove overlapping points in the reflectivity.

Cutting is done from the lower Qz measurements.

toggleColorbars()[source]

Refresh plots because of a color or scale change.

update_gisans_viewer

Signal to update the GISANS viewer.

update_off_specular_viewer

Signal to update the off-specular viewer.

update_specular_viewer

Signal to update the specular viewer.

quicknxs.views.main_window.disabled_widget(widget: QWidget)[source]

Temporarily disable a widget for the duration of the context.

Restores the enabled state of the widget when the context exits.

quicknxs.views.offspec_slice_dialog module

Dialog to let the user configure off-specular Qz slice parameters.

class quicknxs.views.offspec_slice_dialog.OffSpecSliceDialog(parent, data_manager: DataManager)[source]

Bases: QDialog

Dialog to define off-specular Qz slice parameters with plot preview.

INTENSITY_MAX = 1.0
INTENSITY_MIN = 1e-06
accept()[source]

Override accept to save settings before closing.

draw_plot()[source]

Draw the off-specular data with the configured region overlay.

drawing = False
get_parameters()[source]

Get the slice parameters as a dictionary.

Returns:

Dictionary containing off-specular slice parameters

Return type:

dict

load_settings()[source]

Load parameter values from QSettings.

on_coordinate_system_changed()[source]

Handle coordinate system change - update visibility and redraw plot.

save_settings()[source]

Save parameter values to QSettings.

update_qz_range_visibility()[source]

Hide Qz range controls when ki_z vs kf_z is selected (no Qz axis).

update_region()[source]

Update the horizontal lines showing the Qz slice region.

update_slice_width()[source]

Calculate and display the Qz slice width based on current settings.

quicknxs.views.plotting module

class quicknxs.views.plotting.PlotView(main_window)[source]

Bases: object

PlotView is responsible for plotting the data in the main window.

plot_gisans()[source]

Create GISANS plots of the current dataset with Qy-Qz maps.

plot_offspec(recalc=True, crop=False)[source]

Plot off-specular data.

Create an offspecular plot for all cross sections of the datasets in the reduction list. The user can define upper and lower bounds for the plotted intensity and select the coordinates to be either kiz-kfz vs. Qz, Qx vs. Qz or kiz vs. kfz.

plot_overview()[source]

X vs. Y and X vs. Tof for main xs.

plot_projections(preserve_lim=False)[source]

Create projections of the data on the x and y axes.

The x-projection can also be done be means of quantile calculation, which means that the ToF intensities are calculation which are exceeded by a certain number of points. This can be helpful to better separate the specular reflection from bragg-sheets

plot_reflectivity_or_intensity()[source]

Plot reflectivity data or intensity, depending on the type of the active run.

If the active run is a direct beam run (natively labeled as direct beam OR selected from the direct beam table), the intensity vs ToF (or wavelength) in the region-of-interest (ROI) is plotted.

If the active run is selected from the reduction/data table, the reflectivity of all datasets is plotted, even if that same run also exists in the direct beam table.

This allows users to compare different ROIs by adding the same run to both tables, with the plot type determined by which table the user is currently viewing from.

Return type:

True if the plot was successful, False otherwise

plot_xtof()[source]

X vs. ToF plots for all xss.

plot_xy()[source]

X vs. Y plots for all xss.

quicknxs.views.reduction_dialog module

Modal dialog for reduction options.

Dialog to select reduction options to choose which outputs are needed and in which formats to write them.

class quicknxs.views.reduction_dialog.ReductionDialog(parent)[source]

Bases: QDialog

Reduction dialog.

accept()[source]

Save the current options and close dialog.

change_directory()[source]

Change the output directory.

default_template = '{instrument}_{numbers}_{peak}_{item}_{state}.{type}'
get_options()[source]

Return the reduction options as a dict.

reset_filename_template()[source]

Reset the filename template to the default.

save_settings() None[source]

Save reduction options in QSettings.

quicknxs.views.result_viewer module

Dialog to show final reduced data.

class quicknxs.views.result_viewer.ResultViewer(parent, data_manager: DataManager)[source]

Bases: QDialog

Reduction dialog.

apply_gisans_crop()[source]
apply_offspec_crop()[source]
default_template = '{instrument}_{numbers}_{peak}_{item}_{state}.{type}'
reset_gisans_crop()[source]
reset_offspec_crop()[source]
update_active_tab()[source]
update_gisans(crop: bool = False)[source]

Update the results viewer with the latest GISANS calculations.

Parameters:

crop – If True, all the plots will be cropped to the ++ cross-section

update_off_specular(crop: bool = False)[source]

Update the result viewer with the latest off-specular calculations.

Parameters:

crop – If True, all the plots will be cropped to the ++ cross-section

update_specular()[source]
quicknxs.views.result_viewer.clear_layout(layout)[source]

quicknxs.views.smooth_dialog module

Dialog to configure off-specular parameters (smoothing and/or binning).

class quicknxs.views.smooth_dialog.OffSpecParametersDialog(parent, data_manager: DataManager, show_smoothing: bool = False, show_binning: bool = False)[source]

Bases: QDialog

Combined dialog for off-specular smoothing and binning parameters.

Initialize the combined off-specular parameters dialog.

Parameters:
  • parent (QWidget) – Parent widget

  • data_manager (DataManager) – Data manager instance

  • show_smoothing (bool) – Whether to show smoothing parameters

  • show_binning (bool) – Whether to show binning parameters

GRID_OFFSET = 0.05
INTENSITY_MAX = 1.0
INTENSITY_MIN = 1e-06
accept()[source]

Override accept to save settings before closing.

draw_plot()[source]

Draw the off-specular data with the configured region overlay.

drawing = False
get_parameters()[source]

Get the parameters as a dictionary.

Returns:

Dictionary containing off-specular parameters

Return type:

dict

load_settings()[source]

Load parameter values from QSettings.

on_coordinate_system_changed()[source]

Handle coordinate system radio button changes - recalculate ranges from data.

plot_select(event)[source]

Handle plot clicks to adjust the selection region.

save_settings()[source]

Save parameter values to QSettings.

update_bin_width()[source]

Calculate and display the Qz bin width based on current settings.

update_region()[source]

Update the rectangle overlay showing the region.

update_settings()[source]

Update smoothing sigma visualization (only called when smoothing is enabled).

update_sigma_coupling()[source]

Update sigma coupling state and UI element states.

quicknxs.views.status_bar module

class quicknxs.views.status_bar.StatusBar(status_bar: QStatusBar)[source]

Bases: object

Status bar handler class.

Initialize the status message handler.

show_message(message: str, msecs: int = 10000)[source]

Show a message in the status bar for a specified duration.

quicknxs.views.widgets.accept_reject_dialog module

Zoo for customized simple widgets.

class quicknxs.views.widgets.accept_reject_dialog.AcceptRejectDialog(parent=None, title='', message='')[source]

Bases: QDialog

Customized widget for user to accept or reject a state.

Refer to: https://www.mfitzp.com/tutorials/pyqt-dialogs/

accept(self)[source]
is_accepted()[source]
reject(self)[source]

quicknxs.views.widgets.active_radio_button module

Miscellaneous custom Qt widgets for QuickNXS.

class quicknxs.views.widgets.active_radio_button.ActiveDataRadioButton(parent: MainHandler | None = None, is_active: bool = False, idx: int | None = None, is_direct_beam: bool = False)[source]

Bases: QWidget

A QWidget that represents the active data selection.

initUI()[source]

Initialize the UI components.

set_checked_block_signals(checked: bool) None[source]

Set radio button state without emitting signals.

quicknxs.views.widgets.binning_type_combobox module

class quicknxs.views.widgets.binning_type_combobox.BinningTypeSelection(on_change_handler=None, row=None, parent=None)[source]

Bases: QComboBox

Combo box for binning types.

Initialize the BinningTypeSelection combo box.

Parameters:
  • on_change_handler (Callable | None) – A function to be called when the selection changes. It should accept two arguments: the new index and the row identifier.

  • row (int | None) – An identifier for the row associated with this combo box, useful when the combo box is used in a table or list context.

  • parent (QWidget | None) – The parent widget.

quicknxs.views.widgets.mplwidget module

Plotting widget taken from QuickNXS.

#TODO: refactor this or replace it with a standard solution

class quicknxs.views.widgets.mplwidget.MPLWidget(parent=None, with_toolbar=True, coordinates=False)[source]

Bases: QWidget

A widget for displaying matplotlib plots, with a navigation toolbar.

adjust(**adjustment)[source]
cbar = None
clear()[source]
clear_fig()[source]
cplot = None
draw()[source]

Convenience to redraw the graph.

errorbar(*args, **opts)[source]

Convenience wrapper for self.canvas.ax.errorbar.

get_config()[source]
imshow(data, log=False, imin=None, imax=None, update=True, **opts)[source]

Convenience wrapper for self.canvas.ax.plot.

leaveEvent(event)[source]

Make sure the cursor is reset to it’s default when leaving the widget.

In some cases the zoom cursor does not reset when leaving the plot.

legend(*args, **opts)[source]
pcolormesh(datax, datay, dataz, log=False, imin=None, imax=None, update=False, **opts)[source]

Convenience wrapper for self.canvas.ax.plot.

plot(*args, **opts)[source]

Convenience wrapper for self.canvas.ax.plot.

semilogy(*args, **opts)[source]

Convenience wrapper for self.canvas.ax.semilogy.

set_config(config)[source]
set_title(new_title, fontsize=None)[source]
set_xlabel(label, fontsize=None)[source]
set_xscale(scale)[source]
set_xticks_fontsize(fontsize)[source]
set_ylabel(label, fontsize=None)[source]
set_yscale(scale)[source]
set_yticks_fontsize(fontsize)[source]
sync_toolbar_view(clear_history=False)[source]

Ensure navigation toolbar state matches the current plot.

update(self)[source]
update(self, a0: QRect) None
update(self, a0: QRegion) None
update(self, ax: int, ay: int, aw: int, ah: int) None
class quicknxs.views.widgets.mplwidget.MplCanvas(parent=None, width=3, height=3, dpi=100, sharex=None, sharey=None, adjust={})[source]

Bases: FigureCanvasQTAgg

A canvas for matplotlib figures, used in the MPLWidget.

format_labels()[source]
get_default_filetype()[source]

Return the default file type for saving figures ('png').

minimumSizeHint(self) QSize[source]
sizeHint(self) QSize[source]
class quicknxs.views.widgets.mplwidget.NavigationToolbar(canvas, parent, coordinates=False)[source]

Bases: NavigationToolbar2QT

A small change to the original navigation toolbar.

coordinates: should we show the coordinates on the right?

print_figure()[source]

Save the plot to a temporary png file and show a preview dialog also used for printing.

save_data()[source]

Save the current plot data to file (.dat, .npz, or .pkl).

save_figure(*args)[source]

Save the current figure.

class quicknxs.views.widgets.mplwidget.NavigationToolbarGeneric(canvas, parent, coordinates=False)[source]

Bases: NavigationToolbar

A navigation toolbar for a generic plot.

coordinates: should we show the coordinates on the right?

toggle_log(*args)[source]
class quicknxs.views.widgets.mplwidget.NavigationToolbarReflectivity(canvas, parent, coordinates=False)[source]

Bases: NavigationToolbar

A navigation toolbar for reflectivity plots created using matplotlib’s errorbar function.

coordinates: should we show the coordinates on the right?

toggle_lines(*args)[source]

Toggle lines between points in the plot.

toggle_rq4_scale(*args)[source]

Toggle between plotting R and R * Q^4.

toggle_xlog(*args)[source]

Toggle between linear and logarithmic x-axis.

toggle_ylog(*args)[source]

Toggle between linear and logarithmic y-axis.

quicknxs.views.widgets.mplwidget.centerbins(xvals)[source]

For a given numpy array of bin edges, return the bin centers.

quicknxs.views.widgets.mplwidget.getIcon(filename: str) QIcon[source]