API Reference#
datareduction#
Reduces scattering data into 2D and 1D datasets.
- nxs_analysis_tools.datareduction.load_data(path)#
Load data from a specified path.
- 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:
- data
nexusformat.nexus.NXdata
object
orndarray
The NXdata object containing the dataset to plot.
- X
NXfield
, optional The X axis values. Default is first axis of data.
- Y
NXfield
, 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.
- vmin
float
, optional The minimum value to plot in the dataset. If not provided, the minimum of the dataset will be used.
- vmax
float
, optional The maximum value to plot in the dataset. If not provided, the maximum of the dataset will be used.
- skew_angle
float
, optional The angle to shear the plot in degrees. Defaults to 90 degrees (no skewing).
- ax
matplotlib.axes.Axes
, optional An optional axis object to plot the heatmap onto.
- xlim
tuple
, optional The limits of the x-axis. If not provided, the limits will be automatically set.
- ylim
tuple
, optional The limits of the y-axis. If not provided, the limits will be automatically set.
- xticks
float
, optional The major tick interval for the x-axis. If not provided, the function will use a default minor tick interval of 1.
- yticks
float
, 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.
- cmap
str
orColormap
, optional The color map to use. Defaults to ‘viridis’.
- linthresh
float
, optional The linear threshold for the symmetrical logarithmic color scale. Defaults to 1.
- mdheading
str
, optional A string containing the Markdown heading for the plot. Default None.
- data
- Returns:
- p
matplotlib.collections.QuadMesh
A
matplotlib.collections.QuadMesh
object, to mimick behavior ofmatplotlib.pyplot.pcolormesh
.
- p
- 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) Inputnexusformat.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:
- data
nexusformat.nexus.NXdata
orNone
, optional Input NXdata. Default is None.
- center
tuple
orNone
, optional Central coordinate around which to perform the linecut. Default is None.
- window
tuple
orNone
, optional Extents of the window for integration along each axis. Default is None.
- axis
int
orNone
, optional Axis along which to perform the integration. Default is None.
- data
- set_data(data)#
Set the input NXdata.
- Parameters:
- data
nexusformat.nexus.NXdata
Input data array.
- data
- set_center(center)#
Set the central coordinate for the linecut.
- Parameters:
- center
tuple
Central coordinate around which to perform the linecut.
- center
- set_window(window)#
Set the extents of the integration window.
- Parameters:
- window
tuple
Extents of the window for integration along each axis.
- window
- get_window()#
Get the 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:
- center
float
orNone
, optional Central coordinate for the linecut. If not specified, the value from the object’s attribute will be used.
- window
tuple
orNone
, optional Integration window extents around the central coordinate. If not specified, the value from the object’s attribute will be used.
- axis
int
orNone
, optional The axis along which to perform the linecut. If not specified, the value from the object’s attribute will be used.
- center
- Returns:
- integrated_data
nexusformat.nexus.NXdata
1D linecut data after integration.
- integrated_data
- 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.
- label
str
, optional The label for the integration window plot.
- highlight_color
str
, optional The edge color used to highlight the integration window. Default is ‘red’.
- **kwargs
keyword
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:
- data
nexusformat.nexus.NXdata
Input data.
- lattice_angle
float
Angle between the two in-plane lattice axes in degrees.
- rotation_angle
float
Angle of rotation in degrees.
- rotation_axis
int
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.
- data
- Returns:
- rotated_data
nexusformat.nexus.NXdata
Rotated data as an NXdata object.
- rotated_data
- 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_template
NXdata
An NXdata object serving as a template, which provides information about axes and other metadata.
- signal_name
str
, 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:
- data
NXdata
, optional The input data to be symmetrized. If provided, the set_data method is called to set the data.
- data
- set_data(data)#
Set the input data for symmetrization.
- Parameters:
- data
NXdata
The input data to be symmetrized.
- data
- pad(padding)#
Symmetrically pads the data with zero values.
- Parameters:
- padding
tuple
The number of zero-value pixels to add along each edge of the array.
- padding
- save(fout_name=None)#
Saves the padded dataset to a .nxs file.
- Parameters:
- fout_name
str
, optional The output file name. Default is padded_(Hpadding)_(Kpadding)_(Lpadding).nxs
- fout_name
- unpad(data)#
Removes the padded region from the data.
- Parameters:
- data
ndarray
orNXdata
The padded data from which to remove the padding.
- data
- Returns:
ndarray
orNXdata
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 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 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 parameters for all line cut models.
plot_fit
([mdheadings])Plot the fit results.
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.
Plot the fit results.
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:
- folder
str
The path to the folder where the datasets are located.
- file_ending
str
, optional The file extension of the datasets to be loaded. The default is ‘hkli.nxs’.
- temperatures_list
list
ofint
orNone
, optional The list of specific temperatures to load. If None, all available temperatures are loaded. The default is None.
- folder
- set_window(window)#
Set the extents of the integration window.
- Parameters:
- window
tuple
Extents of the window for integration along each axis.
- window
- set_center(center)#
Set the central coordinate for the linecut.
- Parameters:
- center
tuple
Central coordinate around which to perform the linecut.
- center
- cut_data(center=None, window=None, axis=None)#
Perform data cutting for each temperature dataset.
- Parameters:
- 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_offset
float
, optional The vertical offset between linecuts on the plot. The default is 0.
- **kwargs
Additional keyword arguments to be passed to the plot function.
- vertical_offset
- 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:
- temperature
str
, 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.
- **kwargs
keyword
arguments
, optional Additional keyword arguments to customize the plot.
- temperature
- 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:
- temperature
str
, 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.
- **kwargs
keyword
arguments
, optional Additional keyword arguments to customize the plot.
- temperature
- 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_components
Model
or iterable ofModel
The model components to set for all line cut models.
- model_components
- 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_min
float
The minimum angle in degrees for symmetrization.
- theta_max
float
The maximum angle in degrees for symmetrization.
- lattice_angle
float
, 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_axis
int
, optional The axis along which to perform mirroring (default: 0).
- theta_min
- symmetrize_2d(data)#
Symmetrizes a 2D dataset based on the set parameters.
- Parameters:
- data
NXdata
The input 2D dataset to be symmetrized.
- data
- Returns:
- symmetrized
NXdata
The symmetrized 2D dataset.
- symmetrized
- test(data, **kwargs)#
Performs a test visualization of the symmetrization process.
- Parameters:
- Returns:
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.
Perform the symmetrization of the 3D dataset.
set_lattice_params
- __init__(data=None)#
Initialize the Symmetrizer3D object.
- Parameters:
- data
NXdata
, optional The input 3D dataset to be symmetrized.
- data
- set_data(data)#
Sets the data to be symmetrized.
- Parameters:
- data
NXdata
The input 3D dataset to be symmetrized.
- data
- symmetrize()#
Perform the symmetrization of the 3D dataset.
- Returns:
- symmetrized
NXdata
The symmetrized 3D dataset.
- symmetrized
- nxs_analysis_tools.pairdistribution.generate_gaussian(H, K, L, amp, stddev, lattice_params, coeffs=None)#
Generate a 3D Gaussian distribution.
- Parameters:
- H, K, L
ndarray
Arrays specifying the values of H, K, and L coordinates.
- amp
float
Amplitude of the Gaussian distribution.
- stddev
float
Standard deviation of the Gaussian distribution.
- lattice_params
tuple
Tuple of lattice parameters (a, b, c, alpha, beta, gamma).
- coeffs
list
, 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)
- H, K, L
- Returns:
- gaussian
ndarray
3D Gaussian distribution.
- gaussian