API Reference#

datareduction#

Reduces scattering data into 2D and 1D datasets.

nxs_analysis_tools.datareduction.load_data(path)#

Load data from a specified path.

Parameters:
pathstr

The path to the data file.

Returns:
datanxdata object

The loaded data stored in a nxdata object.

nxs_analysis_tools.datareduction.plot_slice(data, X=None, Y=None, transpose=False, vmin=None, vmax=None, skew_angle=90, ax=None, xlim=None, ylim=None, xticks=None, yticks=None, cbar=True, logscale=False, symlogscale=False, cmap='viridis', linthresh=1, title=None, mdheading=None, cbartitle=None, **kwargs)#
Parameters:
datanexusformat.nexus.NXdata object or ndarray

The NXdata object containing the dataset to plot.

XNXfield, optional

The X axis values. Default is first axis of data.

YNXfield, optional

The y axis values. Default is second axis of data.

transposebool, optional

If True, tranpose the dataset and its axes before plotting. Default is False.

vminfloat, optional

The minimum value to plot in the dataset. If not provided, the minimum of the dataset will be used.

vmaxfloat, optional

The maximum value to plot in the dataset. If not provided, the maximum of the dataset will be used.

skew_anglefloat, optional

The angle to shear the plot in degrees. Defaults to 90 degrees (no skewing).

axmatplotlib.axes.Axes, optional

An optional axis object to plot the heatmap onto.

xlimtuple, optional

The limits of the x-axis. If not provided, the limits will be automatically set.

ylimtuple, optional

The limits of the y-axis. If not provided, the limits will be automatically set.

xticksfloat, optional

The major tick interval for the x-axis. If not provided, the function will use a default minor tick interval of 1.

yticksfloat, optional

The major tick interval for the y-axis. If not provided, the function will use a default minor tick interval of 1.

cbarbool, optional

Whether to include a colorbar in the plot. Defaults to True.

logscalebool, optional

Whether to use a logarithmic color scale. Defaults to False.

symlogscalebool, optional

Whether to use a symmetrical logarithmic color scale. Defaults to False.

cmapstr or Colormap, optional

The color map to use. Defaults to ‘viridis’.

linthreshfloat, optional

The linear threshold for the symmetrical logarithmic color scale. Defaults to 1.

mdheadingstr, optional

A string containing the Markdown heading for the plot. Default None.

Returns:
pmatplotlib.collections.QuadMesh

A matplotlib.collections.QuadMesh object, to mimick behavior of matplotlib.pyplot.pcolormesh.

class nxs_analysis_tools.datareduction.Scissors#

Scissors class provides functionality for reducing data to a 1D linecut using an integration window.

Attributes

data

(nexusformat.nexus.NXdata or None) Input nexusformat.nexus.NXdata.

center

(tuple or None) Central coordinate around which to perform the linecut.

window

(tuple or None) Extents of the window for integration along each axis.

axis

(int or None) Axis along which to perform the integration.

data_cut

(ndarray or None) Data array after applying the integration window.

integrated_axes

(tuple or None) Indices of axes that were integrated.

linecut

(nexusformat.nexus.NXdata or None) 1D linecut data after integration.

window_plane_slice_obj

(list or None) Slice object representing the integration window in the data array.

Methods

set_data(data)

Set the input nexusformat.nexus.NXdata

get_data()

Get the input nexusformat.nexus.NXdata.

set_center(center)

Set the central coordinate for the linecut.

set_window(window)

Set the extents of the integration window.

get_window()

Get the extents of the integration window.

cut_data(axis=None)

Reduce data to a 1D linecut using the integration window.

show_integration_window(label=None)

Plot the integration window highlighted on a 2D heatmap of the full dataset.

plot_window()

Plot a 2D heatmap of the integration window data.

__init__(data=None, center=None, window=None, axis=None)#

Initializes a Scissors object.

Parameters:
datanexusformat.nexus.NXdata or None, optional

Input NXdata. Default is None.

centertuple or None, optional

Central coordinate around which to perform the linecut. Default is None.

windowtuple or None, optional

Extents of the window for integration along each axis. Default is None.

axisint or None, optional

Axis along which to perform the integration. Default is None.

set_data(data)#

Set the input NXdata.

Parameters:
datanexusformat.nexus.NXdata

Input data array.

get_data()#

Get the input data array.

Returns:
ndarray or None

Input data array.

set_center(center)#

Set the central coordinate for the linecut.

Parameters:
centertuple

Central coordinate around which to perform the linecut.

set_window(window)#

Set the extents of the integration window.

Parameters:
windowtuple

Extents of the window for integration along each axis.

get_window()#

Get the extents of the integration window.

Returns:
tuple or None

Extents of the integration window.

cut_data(center=None, window=None, axis=None)#

Reduces data to a 1D linecut with integration extents specified by the window about a central coordinate.

Parameters:
centerfloat or None, optional

Central coordinate for the linecut. If not specified, the value from the object’s attribute will be used.

windowtuple or None, optional

Integration window extents around the central coordinate. If not specified, the value from the object’s attribute will be used.

axisint or None, optional

The axis along which to perform the linecut. If not specified, the value from the object’s attribute will be used.

Returns:
integrated_datanexusformat.nexus.NXdata

1D linecut data after integration.

highlight_integration_window(data=None, label=None, highlight_color='red', **kwargs)#

Plots integration window highlighted on the three principal cross sections of the first temperature dataset.

Parameters:
dataarray_like, optional

The 2D heatmap dataset to plot. If not provided, the dataset stored in self.data will be used.

labelstr, optional

The label for the integration window plot.

highlight_colorstr, optional

The edge color used to highlight the integration window. Default is ‘red’.

**kwargskeyword arguments, optional

Additional keyword arguments to customize the plot.

plot_integration_window(**kwargs)#

Plots the three principal cross-sections of the integration volume on a single figure.

Parameters:
**kwargskeyword arguments, optional

Additional keyword arguments to customize the plot.

nxs_analysis_tools.datareduction.rotate_data(data, lattice_angle, rotation_angle, rotation_axis, printout=False)#

Rotates 3D data around a specified axis.

Parameters:
datanexusformat.nexus.NXdata

Input data.

lattice_anglefloat

Angle between the two in-plane lattice axes in degrees.

rotation_anglefloat

Angle of rotation in degrees.

rotation_axisint

Axis of rotation (0, 1, or 2).

printoutbool, optional

Enables printout of rotation progress. If set to True, information about each rotation slice will be printed to the console, indicating the axis being rotated and the corresponding coordinate value. Defaults to False.

Returns:
rotated_datanexusformat.nexus.NXdata

Rotated data as an NXdata object.

nxs_analysis_tools.datareduction.array_to_nxdata(array, data_template, signal_name='counts')#

Create an NXdata object from an input array and an NXdata template, with an optional signal name.

Parameters:
arrayarray_like

The data array to be included in the NXdata object.

data_templateNXdata

An NXdata object serving as a template, which provides information about axes and other metadata.

signal_namestr, optional

The name of the signal within the NXdata object. If not provided, the default signal name ‘counts’ is used.

Returns:
NXdata

An NXdata object containing the input data array and associated axes based on the template.

class nxs_analysis_tools.datareduction.Padder#

A class to pad and unpad datasets with a symmetric region of zeros.

Methods

pad(padding)

Symmetrically pads the data with zero values.

save([fout_name])

Saves the padded dataset to a .nxs file.

set_data(data)

Set the input data for symmetrization.

unpad(data)

Removes the padded region from the data.

__init__(data=None)#

Initialize the Symmetrizer3D object.

Parameters:
dataNXdata, optional

The input data to be symmetrized. If provided, the set_data method is called to set the data.

set_data(data)#

Set the input data for symmetrization.

Parameters:
dataNXdata

The input data to be symmetrized.

pad(padding)#

Symmetrically pads the data with zero values.

Parameters:
paddingtuple

The number of zero-value pixels to add along each edge of the array.

save(fout_name=None)#

Saves the padded dataset to a .nxs file.

Parameters:
fout_namestr, optional

The output file name. Default is padded_(Hpadding)_(Kpadding)_(Lpadding).nxs

unpad(data)#

Removes the padded region from the data.

Parameters:
datandarray or NXdata

The padded data from which to remove the padding.

Returns:
ndarray or NXdata

The unpadded data, with the symmetric padding region removed.

Notes

This method removes the symmetric padding region that was added using the pad method. It returns the data without the padded region.

chess#

This module provides classes and functions for analyzing scattering datasets collected at CHESS (ID4B) with temperature dependence. It includes functions for loading data, cutting data, and plotting linecuts.

class nxs_analysis_tools.chess.TempDependence#

Class for analyzing scattering datasets collected at CHESS (ID4B) with temperature dependence.

Methods

clear_datasets()

Clear the datasets stored in the TempDependence instance.

cut_data([center, window, axis])

Perform data cutting for each temperature dataset.

fit()

Fit the line cut models.

get_folder()

Get the folder path where the datasets are located.

guess()

Make initial parameter guesses for all line cut models.

highlight_integration_window([temperature])

Displays the integration window plot for a specific temperature, or for the first temperature if none is provided.

load_datasets(folder[, file_ending, ...])

Load scattering datasets from the specified folder.

make_params()

Make parameters for all line cut models.

plot_fit([mdheadings])

Plot the fit results.

plot_initial_guess()

Plot the initial guess for all line cut models.

plot_integration_window([temperature])

Plots the three principal cross-sections of the integration volume on a single figure for a specific temperature, or for the first temperature if none is provided.

plot_linecuts([vertical_offset])

Plot the linecuts obtained from data cutting.

print_fit_report()

Plot the fit results.

print_initial_params()

Print the initial parameter values for all line cut models.

set_center(center)

Set the central coordinate for the linecut.

set_model_components(model_components)

Set the model components for all line cut models.

set_param_hint(*args, **kwargs)

Set parameter hints for all line cut models.

set_window(window)

Set the extents of the integration window.

__init__()#

Initialize TempDependence class.

get_folder()#

Get the folder path where the datasets are located.

Returns:
str:

The folder path.

clear_datasets()#

Clear the datasets stored in the TempDependence instance.

load_datasets(folder, file_ending='hkli.nxs', temperatures_list=None)#

Load scattering datasets from the specified folder.

Parameters:
folderstr

The path to the folder where the datasets are located.

file_endingstr, optional

The file extension of the datasets to be loaded. The default is ‘hkli.nxs’.

temperatures_listlist of int or None, optional

The list of specific temperatures to load. If None, all available temperatures are loaded. The default is None.

set_window(window)#

Set the extents of the integration window.

Parameters:
windowtuple

Extents of the window for integration along each axis.

set_center(center)#

Set the central coordinate for the linecut.

Parameters:
centertuple

Central coordinate around which to perform the linecut.

cut_data(center=None, window=None, axis=None)#

Perform data cutting for each temperature dataset.

Parameters:
centertuple

The center point for cutting the data.

windowtuple

The window size for cutting the data.

axisint or None, optional

The axis along which to perform the cutting. If None, cutting is performed along the longest axis in window. The default is None.

Returns:
list

A list of linecuts obtained from the cutting operation.

plot_linecuts(vertical_offset=0, **kwargs)#

Plot the linecuts obtained from data cutting.

Parameters:
vertical_offsetfloat, optional

The vertical offset between linecuts on the plot. The default is 0.

**kwargs

Additional keyword arguments to be passed to the plot function.

highlight_integration_window(temperature=None, **kwargs)#

Displays the integration window plot for a specific temperature, or for the first temperature if none is provided.

Parameters:
temperaturestr, optional

The temperature at which to display the integration window plot. If provided, the plot will be generated using the dataset corresponding to the specified temperature. If not provided, the integration window plots will be generated for the first temperature.

**kwargskeyword arguments, optional

Additional keyword arguments to customize the plot.

plot_integration_window(temperature=None, **kwargs)#

Plots the three principal cross-sections of the integration volume on a single figure for a specific temperature, or for the first temperature if none is provided.

Parameters:
temperaturestr, optional

The temperature at which to plot the integration volume. If provided, the plot will be generated using the dataset corresponding to the specified temperature. If not provided, the integration window plots will be generated for the first temperature.

**kwargskeyword arguments, optional

Additional keyword arguments to customize the plot.

set_model_components(model_components)#

Set the model components for all line cut models.

This method sets the same model components for all line cut models in the analysis. It iterates over each line cut model and calls their respective set_model_components method with the provided model_components.

Parameters:
model_componentsModel or iterable of Model

The model components to set for all line cut models.

set_param_hint(*args, **kwargs)#

Set parameter hints for all line cut models.

This method sets the parameter hints for all line cut models in the analysis. It iterates over each line cut model and calls their respective set_param_hint method with the provided arguments and keyword arguments.

Parameters:
*args

Variable length argument list.

**kwargs

Arbitrary keyword arguments.

make_params()#

Make parameters for all line cut models.

This method creates the parameters for all line cut models in the analysis. It iterates over each line cut model and calls their respective make_params method.

guess()#

Make initial parameter guesses for all line cut models.

This method generates initial parameter guesses for all line cut models in the analysis. It iterates over each line cut model and calls their respective guess method.

print_initial_params()#

Print the initial parameter values for all line cut models.

This method prints the initial parameter values for all line cut models in the analysis. It iterates over each line cut model and calls their respective print_initial_params method.

plot_initial_guess()#

Plot the initial guess for all line cut models.

This method plots the initial guess for all line cut models in the analysis. It iterates over each line cut model and calls their respective plot_initial_guess method.

fit()#

Fit the line cut models.

This method fits the line cut models for each temperature in the analysis. It iterates over each line cut model, performs the fit, and prints the fitting progress.

plot_fit(mdheadings=False, **kwargs)#

Plot the fit results.

This method plots the fit results for each temperature in the analysis. It iterates over each line cut model, calls their respective plot_fit method, and sets the xlabel, ylabel, and title for the plot.

print_fit_report()#

Plot the fit results.

This method plots the fit results for each temperature in the analysis. It iterates over each line cut model, calls their respective plot_fit method, and sets the xlabel, ylabel, and title for the plot.

pairdistribution#

Tools for generating single crystal pair distribution functions.

class nxs_analysis_tools.pairdistribution.Symmetrizer2D#

A class for symmetrizing 2D datasets.

Methods

set_parameters(theta_min, theta_max[, ...])

Sets the parameters for the symmetrization operation.

symmetrize_2d(data)

Symmetrizes a 2D dataset based on the set parameters.

test(data, **kwargs)

Performs a test visualization of the symmetrization process.

__init__(**kwargs)#
set_parameters(theta_min, theta_max, lattice_angle=90, mirror=True, mirror_axis=0)#

Sets the parameters for the symmetrization operation.

Parameters:
theta_minfloat

The minimum angle in degrees for symmetrization.

theta_maxfloat

The maximum angle in degrees for symmetrization.

lattice_anglefloat, optional

The angle in degrees between the two principal axes of the plane to be symmetrized (default: 90).

mirrorbool, optional

If True, perform mirroring during symmetrization (default: True).

mirror_axisint, optional

The axis along which to perform mirroring (default: 0).

symmetrize_2d(data)#

Symmetrizes a 2D dataset based on the set parameters.

Parameters:
dataNXdata

The input 2D dataset to be symmetrized.

Returns:
symmetrizedNXdata

The symmetrized 2D dataset.

test(data, **kwargs)#

Performs a test visualization of the symmetrization process.

Parameters:
datandarray

The input 2D dataset to be used for the test visualization.

**kwargsdict

Additional keyword arguments to be passed to the plot_slice function.

Returns:
figFigure

The matplotlib Figure object that contains the test visualization plot.

axesarrndarray

The numpy array of Axes objects representing the subplots in the test visualization.

Notes

This method uses the symmetrize_2d method to perform the symmetrization on the input data and visualize the process.

The test visualization plot includes the following subplots: - Subplot 1: The original dataset. - Subplot 2: The symmetrization mask. - Subplot 3: The wedge slice used for reconstruction of the full symmetrized dataset. - Subplot 4: The symmetrized dataset.

Example usage: ` s = Scissors() s.set_parameters(theta_min, theta_max, skew_angle, mirror) s.test(data) `

class nxs_analysis_tools.pairdistribution.Symmetrizer3D#

A class to symmetrize 3D datasets.

Methods

save([fout_name])

Save the symmetrized dataset to a file.

set_data(data)

Sets the data to be symmetrized.

symmetrize()

Perform the symmetrization of the 3D dataset.

set_lattice_params

__init__(data=None)#

Initialize the Symmetrizer3D object.

Parameters:
dataNXdata, optional

The input 3D dataset to be symmetrized.

set_data(data)#

Sets the data to be symmetrized.

Parameters:
dataNXdata

The input 3D dataset to be symmetrized.

symmetrize()#

Perform the symmetrization of the 3D dataset.

Returns:
symmetrizedNXdata

The symmetrized 3D dataset.

save(fout_name=None)#

Save the symmetrized dataset to a file.

Parameters:
fout_namestr, optional

The name of the output file. If not provided, the default name ‘symmetrized.nxs’ will be used.

nxs_analysis_tools.pairdistribution.generate_gaussian(H, K, L, amp, stddev, lattice_params, coeffs=None)#

Generate a 3D Gaussian distribution.

Parameters:
H, K, Lndarray

Arrays specifying the values of H, K, and L coordinates.

ampfloat

Amplitude of the Gaussian distribution.

stddevfloat

Standard deviation of the Gaussian distribution.

lattice_paramstuple

Tuple of lattice parameters (a, b, c, alpha, beta, gamma).

coeffslist, optional

Coefficients for the Gaussian expression, including cross-terms between axes. Default is [1, 0, 1, 0, 1, 0], corresponding to (1*H**2 + 0*H*K + 1*K**2 + 0*K*L + 1*L**2 + 0*L*H)

Returns:
gaussianndarray

3D Gaussian distribution.