quicknxs.interfaces package

quicknxs.interfaces.load_ui(ui_filename, baseinstance)[source]

Subpackages

Submodules

quicknxs.interfaces.configuration. module

Application configuration, including reduction options

class quicknxs.interfaces.configuration.Configuration(settings=None)[source]

Bases: object

Hold reduction options

DELTA_KZ_VS_QZ = 3
KZI_VS_KZF = 1
QX_VS_QZ = 0
apply_deadtime = False
bck_offset = 5
property bck_roi
deadtime_tof_step = 100
deadtime_value = 4.2
do_final_rebin_global = True
final_rebin_step_global = -0.01
force_bck_roi = True
global_stitching = False
lock_direct_beam_y = False
property low_res_roi
nbr_events_min = 100
normalize_to_unity = True
paralyzable_deadtime = True
property peak_roi
polynomial_stitching = False
polynomial_stitching_degree = 3
polynomial_stitching_points = 3
sample_size = 10
classmethod setup_default_values()[source]

Only used for testing purposes

total_reflectivity_q_cutoff = 0.01
update_peak_range = False
use_constant_q = False
use_low_res_finder = False
use_peak_finder = False
use_roi = True
use_roi_bck = False
use_tight_bck = False
wl_bandwidth = 3.2
quicknxs.interfaces.configuration.get_direct_beam_low_res_roi(data_conf, direct_beam_conf)[source]

Get the direct beam low res ROI either from the data run or from the direct beam depending on the configuration lock_direct_beam_y

Parameters:
  • data_conf (Configuration) – Configuration for the data run

  • direct_beam_conf (Configuration) – Configuration for the direct beam run

Returns:

The pixel range of the direct beam ROI in the low res direction (y)

Return type:

[int, int]

quicknxs.interfaces.data_manager module

Data manager. Holds information about the current data location and manages the data cache.

class quicknxs.interfaces.data_manager.DataManager(current_directory: str)[source]

Bases: object

MAIN_REDUCTION_LIST_INDEX = 1
MAX_CACHE = 50
add_active_to_normalization()[source]

Add active data set to the direct beam list

add_active_to_reduction(peak_index=1)[source]

Add active data set to reduction list

New data sets are always added to the main reduction list. Data sets are added to secondary reduction lists by initializing from the main reduction list (button to add new data tab) or by propagating individual data sets to other tabs (right-click menu).

Parameters:

peak_index (int) – The index of the peak in peak_reduction_lists

Returns:

True if the active data set was added to the reduction list, False if it was not added

Return type:

bool

add_additional_reduction_list(tab_index: int)[source]

Add reduction list for an additional ROI/peak

Parameters:

tab_index (int) – Index of the peak in self.peak_reduction_lists

asymmetry()[source]

Determine which cross-section to use to compute asymmetry, and compute it.

calculate_gisans(nexus_data=None, progress=None)[source]

Compute GISANS for a single data set

calculate_reflectivity(configuration=None, active_only=False, nexus_data=None, specular=True)[source]

Calculate reflectivity using the current configuration

clear_cache()[source]
clear_cached_unused_data()[source]

Delete cached files that are not in the reduction list or direct beam list

clear_direct_beam_list()[source]

Remove all items from the direct beam list, and make sure to remove links to those items in the scattering data sets.

TODO: remove links from scattering data sets.

clear_reduction_lists()[source]

Resets to one empty reduction list

copy_nexus_data_to_reduction(nexus_data_to_copy: NexusData, peak_index: int)[source]

Add data set to the reduction list specified by peak_index

Parameters:
  • nexus_data_to_copy (NexusData) – Data set to copy

  • peak_index (int) – Peak (reduction list) to copy data set to

Returns:

True if the data set was added successfully, otherwise False

Return type:

bool

property current_event_files: List[str]

@brief Sorted list of event files in the current directory @details return only file names with pattern ‘event.nxs’ or ‘.nxs.h5’

property current_file
property data_sets

Reduced cross sections

Returns:

dictionary of cross sections

Return type:

dict

determine_asymmetry_states()[source]

Determine which cross-section to use to compute asymmetry.

extract_meta_data(file_path=None)[source]

Return the current q-value at the center of the wavelength range of the current data set. If a file path is provided, the mid q-value will be extracted from that data file.

find_active_data_id()[source]

Look for the active data in the reduction list. Return the index within the reduction list or none.

find_active_direct_beam_id()[source]

Look for the active data in the direct beam list. Return the index within the direct beam list or none.

find_best_direct_beam()[source]

Find the best direct beam in the direct beam list for the active data Returns a run number. Returns True if we have updated the data with a new normalization run.

find_data_in_direct_beam_list(nexus_data)[source]

Look for the given data in the direct beam list. Return the index within the direct beam list or none. :param NexusData: data set object

find_data_in_reduction_list(nexus_data)[source]

Look for the given data in the reduction list. Return the index within the reduction list or none. :param NexusData: data set object

find_run_number_in_reduction_list(run_number: int, reduction_list: list[NexusData])[source]

Look for the given run number in the reduction list.

Parameters:
  • run_number (int) – Run number to look for

  • reduction_list (list[NexusData]) – The reduction list to search

Returns:

The index in the reduction list or None

Return type:

int | None

get_active_direct_beam()[source]

Return the direct beam data object for the active data

get_cachesize()[source]
get_trim_values()[source]

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

is_active(data_set)[source]

Returns True of the given data set is the active data set. :param NexusData: data set object

is_gisans_available(active_only=True)[source]

Verify that all data sets and all cross-sections have calculated GISANS data available.

is_nexus_data_compatible(nexus_data: NexusData, reduction_list: list)[source]

Determine if the data set is compatible with the data sets in the reduction list.

A data set is compatible if the polarization cross-section states matches those of the first run in the reduction list, both the same number of states and the same states.

Parameters:
  • nexus_data (NexusData) – The data set to check if compatible with reduction list

  • reduction_list (list[NexusData]) – The reduction list

Return type:

bool

is_offspec_available()[source]

Verify that all data sets and all cross-sections have calculated off-specular data available.

load(file_path: str, configuration: Configuration, force: bool | None = False, update_parameters: bool | None = True, progress: ProgressReporter | None = None) bool[source]

@brief Load one ore more Nexus data files @param file_path: absolute path to one or more files. If more than one, files are concatenated with the merge symbol ‘+’. @param configuration: configuration to use to load the data @param force: it True, existing data in the cache will be replaced by reading from file. @param update_parameters: if True, we will find peak ranges @param progress: aggregator to estimate percent of time allotted to this function @returns True if the data is retrieved from the cache of past loading events

load_data_from_reduced_file(file_path, configuration=None, progress=None)[source]

Load the information from a reduced file, the load the data. Ask the main event handler to update the UI once we are done. :param str file_path: reduced file to load :param Configuration configuration: configuration to base the loaded data on :param ProgressReporter progress: progress reporter

load_direct_beam_and_data_files(db_files, data_files, additional_peaks=None, configuration=None, progress=None, force=False, t_0=None)[source]

Load direct beam and data files and add them to the direct beam list and reduction list, respectively

Parameters:
  • db_files (list) – List of (run_number, run_file, conf) for direct beam files

  • data_files (list) – List of (run_number, run_file, conf) for data files

  • additional_peaks (list | None) – List of (peak_index, run_number, run_file, conf) for data files for additional peaks

  • configuration (Configuration) – Configuration to base the loaded data on

  • progress (ProgressReporter) – Progress reporter

  • force (bool) – If True, ignore cache and force reloading from file

  • t_0 (float) – Start time for logging data loading time

property main_reduction_list

Returns the reduction list for the first (mandatory) data tab

Returns:

The reduction list

Return type:

list[NexusData]

merge_data_sets(asymmetry=True)[source]
rebin_gisans(pol_state, wl_min=0, wl_max=100, qy_npts=50, qz_npts=50, use_pf=False)[source]

Merge all the off-specular reflectivity data and rebin.

reduce_gisans(progress=None)[source]

Since the specular reflectivity is prominently displayed, it is updated as soon as parameters change. This is not the case for GISANS, which is computed on-demand. This method goes through the data sets in the reduction list and re-calculate the GISANS.

reduce_offspec(progress=None)[source]

Since the specular reflectivity is prominently displayed, it is updated as soon as parameters change. This is not the case for the off-specular, which is computed on-demand. This method goes through the data sets in the reduction list and re-calculate the off-specular reflectivity.

reduce_spec()[source]

Calculate reflectivity for all runs in all reduction lists

property reduction_list

Returns the reduction list for the active data tab

Returns:

The reduction list

Return type:

list[NexusData]

reload_files(configuration=None, progress=None)[source]

Force reload of files in the reduction lists and direct beam list

remove_active_from_normalization()[source]

Remove the active data set from the direct beam list

remove_additional_reduction_list(tab_index: int)[source]

Remove reduction list for additional ROI/peak

Parameters:

tab_index (int) – Index of the peak in self.peak_reduction_lists

remove_from_active_reduction_list(index: int)[source]

Remove item from the active reduction list

Parameters:

index (int) – Index of the item to remove

set_active_data_from_direct_beam_list(index)[source]

Set a data set in the direct beam list as the active data set according to its index. :param int index: index in the direct beam list

set_active_data_from_reduction_list(index)[source]

Set a data set in the reduction list as the active data set according to its index. :param int index: index in the reduction list

set_active_reduction_list_index(tab_index: int)[source]

Set the active reduction list index

Parameters:

tab_index (int) – Index of the peak in self.peak_reduction_lists

set_channel(index)[source]

Set the current channel to the specified index, or zero if it doesn’t exist.

Parameters:

index (int) – channel index

Return type:

bool

stitch_data_sets(normalize_to_unity=True, q_cutoff=0.01, global_stitching=False, poly_degree=None, poly_points=3)[source]

Determine scaling factors for each data set :param bool normalize_to_unity: If True, the reflectivity plateau will be normalized to 1. :param float q_cutoff: critical q-value below which we expect R=1 :param bool global_stitching: If True, use data from all cross-sections to calculate scaling factors :param int poly_degree: if not None, find the scaling factor by simultaneously fitting a polynomial and scaling factor to the curves :param int poly_points: number of additional points on each end of the overlap region to include in the fit

strip_overlap()[source]

Remove overlapping points in the reflecitviy, cutting always from the lower Qz measurements.

update_active_reduction_list(tab_index: int)[source]

Updates the active reduction list and run

Parameters:

tab_index (int) – Index of the peak in self.peak_reduction_lists

update_configuration(configuration, active_only: bool = False, nexus_data: NexusData | None = None)[source]

Update configuration

quicknxs.interfaces.main_window module

Main application window

class quicknxs.interfaces.main_window.MainWindow[source]

Bases: QMainWindow

Main application window

addDataTable()[source]

Add data tab for additional peaks/ROI:s

addRefList()[source]

Signal handling

add_data_tab_by_index(tab_index: int)[source]

Add/update a specific data tab

apply_offspec_crop()[source]
autoRef()[source]
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_channel(is_checked)[source]

The overview and reflectivity channel was changed. This updates the run information and plots in the Overview area

The toggled() signal is emitted from both radio buttons whose states were changed, therefore, use the bool value to only perform channel 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

clearNormList()[source]

Signal handling

clearRefList()[source]

Signal handling

closeEvent(event)[source]

Close UI event

cutPoints()[source]

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

direct_beam_cell_activated(row, col)[source]

Select a data set when the user double-clicks on a run number (col 0). in the direct beam table. :param int row: row index :param int col: column index

direct_beam_table_right_click(pos)[source]

Handle right-click on the direct beam table. :param QPoint pos: mouse position

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]

@brief Read a set of congruent file data sets. @details Select a list of event or histogram files, check their metadata is compatible, and read-in.

getNorm()[source]

TODO: deal with this This is supposed to retrieve the normalization data for the active reflectivity data so that we can 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_intensity_plot

Signal to initiate the intensity plot.

initiate_projection_plot

Signal to initiate the projection plot.

initiate_reflectivity_plot

Signal to initiate the reflectivity 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

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_manager

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

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_cell_activated(row, col)[source]

Select a data set when the user double-clicks on a run number (col 0). in the reduction table. :param int row: row index :param int col: column index

reduction_table_right_click(pos)[source]

Handle right-click on the reduction table. :param QPoint pos: mouse position

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

removeRefList()[source]

Signal handling

remove_normalization()[source]

Signal handling

replotProjections()[source]

Signal handling

reset_data_tabs()[source]

Reset UI to one visible data tab

setCurrentReductionTable(tab_index: int)[source]

Update the state for active data set and the UI

setNorm()[source]

Signal handling

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

Remove overlapping points in the reflecitviy, cutting always from the lower Qz measurements.

toggleColorbars()[source]

Refresh plots because of a color or scale change

toggleFinalRebinGlobal(state)[source]

Signal handling

toggleFinalRebinRun(state)[source]

Signal handling

toggle_smoothing()[source]
update_gisans_viewer

Signal to update the GISANS viewer.

update_off_specular_viewer

Signal to update the off-specular viewer.

update_offspec_qz_bin_width(value=None)[source]
update_specular_viewer

Signal to update the specular viewer.

quicknxs.interfaces.plotting module

class quicknxs.interfaces.plotting.PlotManager(main_window)[source]

Bases: object

plot_gisans()[source]

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

plot_intensity(preserve_lim=False)[source]

Calculate and display the direct beam intensity from the current dataset.

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

Create an offspecular plot for all channels 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 channel.

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_refl(preserve_lim=False)[source]

Calculate and display the reflectivity from the current dataset and any dataset stored. Intensities from direct beam measurements can be used for normalization.

plot_xtof()[source]

X vs. ToF plots for all channels.

plot_xy()[source]

X vs. Y plots for all channels.

quicknxs.interfaces.reduction_dialog module

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

class quicknxs.interfaces.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.interfaces.result_viewer module

Dialog to show final reduced data.

class quicknxs.interfaces.result_viewer.ResultViewer(parent, data_manager)[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=False)[source]

Update the results viewer with the latest GISANS calculations :param bool crop: if True, all the plots will be cropped to the ++ cross-section

update_off_specular(crop=False)[source]

Update the result viewer with the latest off-specular calculations. :param bool crop: if True, all the plots will be cropped to the ++ cross-section

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

quicknxs.interfaces.smooth_dialog module

Dialog to let the user select smoothing options This code was taken as-is from QuickNXS v1

class quicknxs.interfaces.smooth_dialog.SmoothDialog(parent, data_manager)[source]

Bases: QDialog

Dialog to define smoothing parameters.

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

Plot the unsmoothed data.

drawing = False
plotSelect(event)[source]

Plot for y-projection has been clicked.

updateGrid()[source]
updateSettings()[source]
update_output_options(output_options)[source]

Update a dict with smoothing options :param dict: dictionary object