NeuXtalViz.models package#

Submodules#

NeuXtalViz.models.base_model module#

NeuXtalVizModel#

Base model for crystallographic and reciprocal lattice operations using Mantid workspaces.

This class provides methods for handling UB matrices, checking oriented lattices, and computing various crystallographic and reciprocal axes and transformations for visualization and analysis.

Attributes#

UBnp.ndarray or None

The 3x3 UB matrix for the current workspace, or None if not set.

Methods#

has_UB(ws)

Check if the oriented lattice exists on a workspace.

set_UB(UB)

Update the UB-matrix.

get_oriented_lattice_parameters()

Obtain the oriented lattice parameters (a, b, c, alpha, beta, gamma, u, v).

orientation_matrix()

Return the current UB matrix (orientation matrix).

get_transform(reciprocal)

Transformation matrix describing the reciprocal or crystal axes.

ab_star_axes(), bc_star_axes(), ca_star_axes()

Cartesian camera/upward view vectors for various axes.

ab_axes(), bc_axes(), ca_axes()

Cartesian camera/upward view vectors for reciprocal axes.

get_vector(axes_type, ind)

Vector corresponding to a particular crystallographic direction.

class NeuXtalVizModel[source]#

Bases: object

Methods

ab_axes()

\(c^*\)-direction in cartesian coordinates.

ab_star_axes()

\(c\)-direction in cartesian coordinates.

bc_axes()

\(a^*\)-direction in cartesian coordinates.

bc_star_axes()

\(a\)-direction in cartesian coordinates.

ca_axes()

\(b^*\)-direction in cartesian coordinates.

ca_star_axes()

\(b\)-direction in cartesian coordinates.

get_oriented_lattice_parameters()

Obtain the oriented lattice parameters.

get_transform([reciprocal])

Transformation matrix describing the reciprocal or crystal axes.

get_vector(axes_type, ind)

Vector corresponding to a particular crystallographic direction.

has_UB(ws)

Check if the oriented lattice exists on a workspace.

orientation_matrix()

Return the current UB matrix (orientation matrix).

set_UB(UB)

Update the UB-matrix.

ab_axes()[source]#

\(c^*\)-direction in cartesian coordinates.

Returns:
camera3 element 1d array

Cartesian camera view vector.

upward3 element 1d array

Cartesian upward view vector.

ab_star_axes()[source]#

\(c\)-direction in cartesian coordinates.

Returns:
camera3 element 1d array

Cartesian camera view vector.

upward3 element 1d array

Cartesian upward view vector.

bc_axes()[source]#

\(a^*\)-direction in cartesian coordinates.

Returns:
camera3 element 1d array

Cartesian camera view vector.

upward3 element 1d array

Cartesian upward view vector.

bc_star_axes()[source]#

\(a\)-direction in cartesian coordinates.

Returns:
camera3 element 1d array

Cartesian camera view vector.

upward3 element 1d array

Cartesian upward view vector.

ca_axes()[source]#

\(b^*\)-direction in cartesian coordinates.

Returns:
camera3 element 1d array

Cartesian camera view vector.

upward3 element 1d array

Cartesian upward view vector.

ca_star_axes()[source]#

\(b\)-direction in cartesian coordinates.

Returns:
camera3 element 1d array

Cartesian camera view vector.

upward3 element 1d array

Cartesian upward view vector.

get_oriented_lattice_parameters()[source]#

Obtain the oriented lattice parameters.

Returns:
a, b, cfloat

Lattice constants.

alpha, beta, gammafloat

Lattice angles.

u, vnp.ndarray

Normalized u and v vectors.

get_transform(reciprocal=True)[source]#

Transformation matrix describing the reciprocal or crystal axes.

Parameters:
reciprocalbool, optional

Option for the reciprocal (True) or crystal lattice axes (False). Default is True.

Returns:
T3x3 element 2d array

Normalized transformation matrix.

get_vector(axes_type, ind)[source]#

Vector corresponding to a particular crystallographic direction.

Parameters:
axes_typestr, [hkl] or [uvw]

Miller index or fractional coordinate.

ind3-element 1d array-like

Indices.

Returns:
vec3 element 1d array

Cartesian vector.

has_UB(ws)[source]#

Check if the oriented lattice exists on a workspace.

Parameters:
wsstr

Name of workspace.

Returns:
olbool

True if oriented lattice exists, False otherwise.

orientation_matrix()[source]#

Return the current UB matrix (orientation matrix).

Returns:
np.ndarray

The UB matrix.

set_UB(UB)[source]#

Update the UB-matrix.

Parameters:
UB3x3 element 2d array

UB-matrix to set for the model.

NeuXtalViz.models.crystal_structure_tools module#

class CrystalStructureModel[source]#

Bases: NeuXtalVizModel

Methods

ab_axes()

\(c^*\)-direction in cartesian coordinates.

ab_star_axes()

\(c\)-direction in cartesian coordinates.

bc_axes()

\(a^*\)-direction in cartesian coordinates.

bc_star_axes()

\(a\)-direction in cartesian coordinates.

ca_axes()

\(b^*\)-direction in cartesian coordinates.

ca_star_axes()

\(b\)-direction in cartesian coordinates.

get_oriented_lattice_parameters()

Obtain the oriented lattice parameters.

get_transform([reciprocal])

Transformation matrix describing the reciprocal or crystal axes.

get_vector(axes_type, ind)

Vector corresponding to a particular crystallographic direction.

has_UB(ws)

Check if the oriented lattice exists on a workspace.

orientation_matrix()

Return the current UB matrix (orientation matrix).

set_UB(UB)

Update the UB-matrix.

calculate_F2

calculate_UB

constrain_parameters

generate_F2

generate_atom_positions

generate_settings_from_space_group

generate_space_groups_from_crystal_system

get_chemical_formula_z_parameter

get_crystal_system

get_lattice_constants

get_lattice_system

get_periodic_table

get_point_group_name

get_scatterers

get_setting

get_space_group

get_unit_cell_transform

get_unit_cell_volume

has_crystal_structure

load_CIF

save_ins

set_crystal_structure

set_material

update_lattice_parameters

update_parameters

calculate_F2(h, k, l)[source]#
calculate_UB()[source]#
constrain_parameters()[source]#
generate_F2(d_min=0.7)[source]#
generate_atom_positions()[source]#
generate_settings_from_space_group(sg)[source]#
generate_space_groups_from_crystal_system(system)[source]#
get_chemical_formula_z_parameter()[source]#
get_crystal_system()[source]#
get_lattice_constants()[source]#
get_lattice_system()[source]#
get_periodic_table(atom)[source]#
get_point_group_name()[source]#
get_scatterers()[source]#
get_setting()[source]#
get_space_group()[source]#
get_unit_cell_transform()[source]#
get_unit_cell_volume()[source]#
has_crystal_structure()[source]#
load_CIF(filename)[source]#
save_ins(filename)[source]#
set_crystal_structure(params, space_group, scatterers)[source]#
set_material()[source]#
update_lattice_parameters(a, b, c, alpha, beta, gamma)[source]#
update_parameters(params)[source]#

NeuXtalViz.models.experiment_planner module#

class CrystalPlan(use, opt, axes, limits, wavelength, d_min, point_group, lattice_centering)[source]#

Bases: object

Genetic algorithm-based class for optimizing experiment plans in NeuXtalViz.

This class generates, recombines, and evaluates sets of orientations and settings to maximize experiment coverage and completeness.

Methods

crossover

fitness

generation

initialization

mutation

optimize

recombination

crossover(n_orient, best, selection)[source]#
fitness(peaks, n=5)[source]#
generation(i, j)[source]#
initialization(n_orient, n_indiv)[source]#
mutation(n_orient, n_indiv, mutation_rate)[source]#
optimize(n_orient, n_indiv, n_gener, n_elite, mutation_rate)[source]#
recombination(n_orient, j)[source]#
class ExperimentModel[source]#

Bases: NeuXtalVizModel

Model for managing experiment planning, instrument setup, and crystallographic calculations in NeuXtalViz.

This class provides methods for initializing instruments, handling calibration and mask files, managing sample and plan workspaces, performing peak prediction, and calculating experiment statistics.

Methods

ab_axes()

\(c^*\)-direction in cartesian coordinates.

ab_star_axes()

\(c\)-direction in cartesian coordinates.

bc_axes()

\(a^*\)-direction in cartesian coordinates.

bc_star_axes()

\(a\)-direction in cartesian coordinates.

ca_axes()

\(b^*\)-direction in cartesian coordinates.

ca_star_axes()

\(b\)-direction in cartesian coordinates.

get_oriented_lattice_parameters()

Obtain the oriented lattice parameters.

get_transform([reciprocal])

Transformation matrix describing the reciprocal or crystal axes.

get_vector(axes_type, ind)

Vector corresponding to a particular crystallographic direction.

has_UB()

Check if the oriented lattice exists on a workspace.

orientation_matrix()

Return the current UB matrix (orientation matrix).

set_UB(UB)

Update the UB-matrix.

add_mesh

add_orientation

calculate_individual_peak

calculate_statistics

copy_UB

create_plan

create_sample

crystal_plan

delete_angles

generate_axes

generate_table

get_UB

get_angles

get_axes_polarities

get_calibration_file_path

get_counting_options

get_coverage_info

get_crystal_system_point_groups

get_goniometer_axes

get_goniometers

get_instrument_name

get_modes

get_motors

get_point_group_centering

get_scan_log

get_setting

get_symmetry

get_vanadium_file_path

get_wavelength

hsl_to_rgb

individual_peak

initialize_instrument

load_UB

load_experiment

remove_instrument

save_experiment

save_plan

simultaneous_peaks

simultaneous_peaks_hkl

update_goniometer_motors

update_sample

add_mesh(mesh_angles, wavelength, d_min, rows, free_angles, all_angles)[source]#
add_orientation(angles, wavelength, d_min, rows)[source]#
calculate_individual_peak(hkl, wavelength, axes, polarities, limits, step=1)[source]#
calculate_statistics(point_group, lattice_centering, use, d_min)[source]#
copy_UB()[source]#
create_plan(table)[source]#
create_sample(instrument, mode, UB, wavelength, d_min)[source]#
crystal_plan(*args)[source]#
delete_angles(rows)[source]#
generate_axes(axes, polarities)[source]#
generate_table(row)[source]#
get_UB()[source]#
get_angles(gamma, nu)[source]#
get_axes_polarities(instrument, mode)[source]#
get_calibration_file_path(instrument)[source]#
get_counting_options(instrument)[source]#
get_coverage_info(point_group, lattice_centering, draw_all, row=None)[source]#
get_crystal_system_point_groups(crystal_system)[source]#
get_goniometer_axes(instrument, mode)[source]#
get_goniometers(instrument, mode)[source]#
get_instrument_name(instrument)[source]#
get_modes(instrument)[source]#
get_motors(instrument)[source]#
get_point_group_centering(point_group)[source]#
get_scan_log(instrument)[source]#
get_setting(free_angles, limits)[source]#
get_symmetry(point_group, centering)[source]#
get_vanadium_file_path(instrument)[source]#
get_wavelength(instrument)[source]#
has_UB()[source]#

Check if the oriented lattice exists on a workspace.

Parameters:
wsstr

Name of workspace.

Returns:
olbool

True if oriented lattice exists, False otherwise.

hsl_to_rgb(hue, saturation, lightness)[source]#
individual_peak(hkl, wavelength, axes, polarities, limits, equiv, pg, step=1)[source]#
initialize_instrument(instrument, logs, cal, gon, mask)[source]#
load_UB(filename)[source]#
load_experiment(filename)[source]#
remove_instrument()[source]#
save_experiment(filename)[source]#
save_plan(filename)[source]#
simultaneous_peaks(hkl_1, hkl_2, wavelength, axes, polarities, limits, equiv, pg, step=1)[source]#
simultaneous_peaks_hkl(hkl_1, hkl_2, wavelength, axes, polarities, limits, step=1)[source]#
update_goniometer_motors(limits, motors, cal, gon, mask)[source]#
update_sample(crytsal_system, point_group, lattice_centering)[source]#

NeuXtalViz.models.periodic_table module#

class AtomModel(atm='H')[source]#

Bases: object

Methods

generate_data

get_isotope_numbers

get_symbol_name

generate_data(iso)[source]#
get_isotope_numbers()[source]#
get_symbol_name()[source]#
class PeriodicTableModel(atom)[source]#

Bases: object

Methods

get_atom_model

get_atom_model(atm)[source]#

NeuXtalViz.models.sample_tools module#

class SampleModel[source]#

Bases: NeuXtalVizModel

Methods

ab_axes()

\(c^*\)-direction in cartesian coordinates.

ab_star_axes()

\(c\)-direction in cartesian coordinates.

bc_axes()

\(a^*\)-direction in cartesian coordinates.

bc_star_axes()

\(a\)-direction in cartesian coordinates.

ca_axes()

\(b^*\)-direction in cartesian coordinates.

ca_star_axes()

\(b\)-direction in cartesian coordinates.

get_oriented_lattice_parameters()

Obtain the oriented lattice parameters.

get_transform([reciprocal])

Transformation matrix describing the reciprocal or crystal axes.

get_vector(axes_type, ind)

Vector corresponding to a particular crystallographic direction.

has_UB(ws)

Check if the oriented lattice exists on a workspace.

orientation_matrix()

Return the current UB matrix (orientation matrix).

set_UB(UB)

Update the UB-matrix.

get_absorption_dict

get_euler_angles

get_goniometer_strings

get_material_dict

get_shape_dict

get_volume

load_UB

sample_mesh

set_sample

get_absorption_dict()[source]#
get_euler_angles(u_vector, v_vector)[source]#
get_goniometer_strings(goniometers)[source]#
get_material_dict(chemical_formula, z_parameter, volume)[source]#
get_shape_dict(shape, params, alpha=0, beta=0, gamma=0)[source]#
get_volume()[source]#
load_UB(filename)[source]#
sample_mesh()[source]#
set_sample(shape_dict, mat_dict, axes)[source]#

NeuXtalViz.models.ub_tools module#

UBModel and related utilities for crystallographic analysis in NeuXtalViz.

This module provides the UBModel class, which encapsulates methods for loading, manipulating, and analyzing crystallographic data, including peak finding, UB matrix determination, lattice refinement, and peak clustering. It interfaces with Mantid algorithms for data processing and supports both conventional and modulated structures.

Classes#

UBModel

Main model for UB matrix and peak table operations, including loading/saving, indexing, integration, and clustering.

class UBModel[source]#

Bases: NeuXtalVizModel

Model for UB matrix and peak table operations in NeuXtalViz.

Provides methods for loading, saving, and manipulating crystallographic data, including peak finding, UB matrix determination, lattice refinement, and clustering. Integrates with Mantid algorithms for data processing and supports both conventional and modulated structures.

Methods

ab_axes()

\(c^*\)-direction in cartesian coordinates.

ab_star_axes()

\(c\)-direction in cartesian coordinates.

add_peak(ind, val, horz, vert)

Add a peak to the peaks table.

bc_axes()

\(a^*\)-direction in cartesian coordinates.

bc_star_axes()

\(a\)-direction in cartesian coordinates.

ca_axes()

\(b^*\)-direction in cartesian coordinates.

ca_star_axes()

\(b\)-direction in cartesian coordinates.

calculate_clim(data[, method])

Calculate the color limits for the given data using the specified method.

calculate_fractional(mod_vec_1, mod_vec_2, ...)

Calculate the fractional coordinates from the given modulation vectors and integer coordinates.

calculate_hkl()

Calculate hkl values without rounding.

calculate_hkl_position(ind, h, k, l)

Calculate the HKL position for a given peak index and Miller indices.

calculate_instrument_view(ind, d_min, d_max)

Calculate the instrument view for a given peak index and d-spacing range.

calculate_integer(mod_vec_1, mod_vec_2, ...)

Calculate the integer coordinates from the given modulation vectors and HKL coordinates.

calculate_peaks(hkl_1, hkl_2, a, b, c, ...)

Calculate d-spacing and angle between two HKL planes.

calibrate_data(instrument, det_cal, gon_cal, ...)

Calibrate the loaded data using detector, goniometer, and tube calibration files.

centroid_peaks(peak_radius)

Re-center peak locations using centroid within given radius

clear_intensity()

Clear the intensity values of all peaks in the peaks table.

cluster_peaks(peak_info[, eps, min_samples])

Cluster peaks using DBSCAN algorithm.

convert_data(instrument, wavelength, lorentz)

Convert loaded data to Q-space using Mantid algorithms.

copy_UB_from_Q()

Copy the UB matrix from the Q workspace to the cell workspace.

copy_UB_from_peaks()

Copy the UB matrix from the peaks workspace to the cell workspace.

copy_UB_to_Q()

Copy the UB matrix from the cell workspace to the Q workspace.

copy_UB_to_peaks()

Copy the UB matrix from the cell workspace to the peaks workspace.

delete_peaks(peaks)

Remove peaks.

determine_UB_with_lattice_parameters(a, b, ...)

Determine UB with prior known lattice parameters.

determine_UB_with_niggli_cell(min_d, max_d)

Determine UB with primitive lattice using min/max lattice constant.

extract_roi(horz, vert, horz_roi, vert_roi, val)

Extract a region of interest (ROI) from the instrument view.

filter_peaks(name, operator, value)

Filter out peaks based on value and operator.

find_peaks(min_dist[, density, max_peaks, ...])

Harvest strong peak locations from Q-sample into a peaks table.

generate_lattice_transforms(cell)

Obtain possible transforms compatabile with a unit cell lattice.

get_Q_info()

Extract Q-space information from the model.

get_UB()

Retrieve the UB matrix from the oriented lattice.

get_all_goniometer_matrices(ws)

Extract all goniometer matrices.

get_calibration_file_path(instrument)

Get the calibration file path for a given instrument.

get_cluster_info()

Get cluster information for peaks based on UB and peak table.

get_goniometers(instrument)

Get goniometer settings for a given instrument.

get_has_Q_vol()

Check if the Q volume data exists.

get_instrument_name(instrument)

Get the instrument name string for a given instrument identifier.

get_lattice_constant_errors()

Get the errors in the lattice constants from the oriented lattice.

get_lattice_constants()

Get the lattice constants from the oriented lattice.

get_max_d_spacing(ws)

Obtain the maximum d-spacing from the oriented lattice.

get_number_workspaces()

Get the number of workspaces in the current Mantid session.

get_oriented_lattice_parameters()

Obtain the oriented lattice parameters.

get_peak(i)

Get a specific peak's information by index.

get_peak_info()

Extract detailed information for each peak in the current table.

get_raw_file_path(instrument)

Get the raw data file path for a given instrument.

get_sample_directions()

Get the sample directions from the UB matrix.

get_shared_file_path(instrument, ipts)

Get the shared file path for a given instrument and IPTS.

get_slice_info(U, V, W, normal, value, ...)

Get the slicing information for a given normal and value.

get_transform([reciprocal])

Transformation matrix describing the reciprocal or crystal axes.

get_vanadium_file_path(instrument)

Get the vanadium calibration file path for a given instrument.

get_vector(axes_type, ind)

Vector corresponding to a particular crystallographic direction.

get_wavelength(instrument)

Get the wavelength for a given instrument.

has_Q()

Check if the Q workspace exists in Mantid.

has_UB()

Check if the UB matrix is defined on the sample.

has_peaks()

Check if the peaks table exists in Mantid.

index_peaks([tol, sat_tol, mod_vec_1, ...])

Index the peaks and calculate the lattice parameter uncertainties.

integrate_peaks(peak_radius[, ...])

Integrate peaks using spherical or ellipsoidal regions.

is_sliced()

Check if the data has been sliced.

load_Q(filename)

Load Q file.

load_UB(filename)

Load UB from file.

load_data(instrument, IPTS, runs, exp, time_stop)

Load experimental data for a given instrument and run parameters.

load_peaks(filename)

Load peaks file.

orientation_matrix()

Return the current UB matrix (orientation matrix).

possible_conventional_cells([max_error, ...])

List possible conventional cells.

predict_modulated_peaks(d_min, lamda_min, ...)

Predict the modulated peak positions based on main peaks.

predict_peaks(centering, d_min, lamda_min, ...)

Predict peak Q-sample locations with UB and lattice centering.

predict_satellite_peaks(lamda_min, ...[, ...])

Locate satellite peaks from goniometer angles.

refine_UB_with_constraints(cell[, tol])

Refine UB with constraints corresponding to lattice system.

refine_UB_without_constraints([tol, sat_tol])

Refine UB with unconstrained lattice parameters.

refine_U_only(a, b, c, alpha, beta, gamma)

Refine the U orientation only.

remove_duplicate_peaks(peaks)

Omit duplicate peaks from different based on indexing.

renumber_runs_by_index(ws, peaks)

Re-label the runs by index based on goniometer setting.

roi_scan_to_hkl(ind, val, horz, vert)

Convert a ROI scan position to HKL coordinates.

save_Q(filename)

Save Q file.

save_UB(filename)

Save UB to file.

save_peaks(filename)

Save the current peaks table to a file.

select_cell(number[, tol])

Transform to conventional cell using form number.

set_UB(UB)

Update the UB-matrix.

set_manual_UB(constants, directions)

Set the unit cell parameters and directions manually.

set_peak(i, hkl, int_hkl, int_mnp)

Set the HKL, integer HKL, and integer MNP values for a specific peak.

simplify_vector(vec)

Simplify a vector to its primitive integer form.

sort_peaks_by_d(peaks)

Sort peaks table by descending d-spacing.

sort_peaks_by_hkl(peaks)

Sort peaks table by descending hkl values.

transform_lattice(transform[, tol])

Apply a cell transformation to the lattice.

update_UB()

Update the UB matrix on the sample and synchronize with Mantid workspaces.

avoid_aluminum_contamination

get_d_min

get_modulation_info

add_peak(ind, val, horz, vert)[source]#

Add a peak to the peaks table.

Parameters:
indint

Index of the run.

valfloat

Peak value (e.g., d-spacing or angle).

horzfloat

Horizontal coordinate (e.g., angle or hkl).

vertfloat

Vertical coordinate (e.g., angle or hkl).

avoid_aluminum_contamination(d_min, d_max, delta=0.1)[source]#
calculate_clim(data, method='normal')[source]#

Calculate the color limits for the given data using the specified method.

Parameters:
datanp.ndarray

Input data for which to calculate color limits.

methodstr, optional

Method for calculating limits (‘normal’, ‘boxplot’, or ‘manual’). Default is ‘normal’.

Returns:
tuple

Lower and upper color limits.

calculate_fractional(mod_vec_1, mod_vec_2, mod_vec_3, int_hkl, int_mnp)[source]#

Calculate the fractional coordinates from the given modulation vectors and integer coordinates.

Parameters:
mod_vec_1, mod_vec_2, mod_vec_3list

Modulation vectors.

int_hkllist

Integer HKL coordinates.

int_mnplist

Integer MNP coordinates.

Returns:
np.ndarray

Calculated fractional coordinates.

calculate_hkl()[source]#

Calculate hkl values without rounding.

calculate_hkl_position(ind, h, k, l)[source]#

Calculate the HKL position for a given peak index and Miller indices.

Parameters:
indint

Index of the peak.

h, k, lint

Miller indices.

Returns:
tuple

Calculated values (x, gamma, nu) for the given HKL.

calculate_instrument_view(ind, d_min, d_max)[source]#

Calculate the instrument view for a given peak index and d-spacing range.

Parameters:
indint

Index of the peak.

d_min, d_maxfloat

Minimum and maximum d-spacing values.

Returns:
dict

Instrument view data including d, gamma, nu, and counts.

calculate_integer(mod_vec_1, mod_vec_2, mod_vec_3, hkl)[source]#

Calculate the integer coordinates from the given modulation vectors and HKL coordinates.

Parameters:
mod_vec_1, mod_vec_2, mod_vec_3list

Modulation vectors.

hkllist

HKL coordinates.

Returns:
tuple

Best integer coordinates (int_hkl, int_mnp) that minimize the error.

calculate_peaks(hkl_1, hkl_2, a, b, c, alpha, beta, gamma)[source]#

Calculate d-spacing and angle between two HKL planes.

Parameters:
hkl_1, hkl_2list

Miller indices for the two planes.

a, b, cfloat

Lattice constants in angstroms.

alpha, beta, gammafloat

Lattice angles in degrees.

Returns:
tuple

d-spacing for the two planes and the angle between them.

calibrate_data(instrument, det_cal, gon_cal, tube_cal)[source]#

Calibrate the loaded data using detector, goniometer, and tube calibration files.

Parameters:
instrumentstr

Instrument identifier.

det_calstr

Detector calibration file.

tube_calstr

Tube calibration file.

gon_calstr

Goniometer calibration file.

centroid_peaks(peak_radius)[source]#

Re-center peak locations using centroid within given radius

Parameters:
peak_radiusfloat

Integration region radius.

clear_intensity()[source]#

Clear the intensity values of all peaks in the peaks table.

cluster_peaks(peak_info, eps=0.025, min_samples=15)[source]#

Cluster peaks using DBSCAN algorithm.

Parameters:
peak_infodict

Dictionary containing peak information (coordinates, inverse transform, etc.).

epsfloat, optional

The maximum distance between two samples for one to be considered as in the neighborhood of the other. Default is 0.025.

min_samplesint, optional

The number of samples in a neighborhood for a point to be considered as a core point. Default is 15.

Returns:
bool

True if clustering is successful, False otherwise.

convert_data(instrument, wavelength, lorentz, min_d=None)[source]#

Convert loaded data to Q-space using Mantid algorithms.

Parameters:
instrumentstr

Instrument identifier.

wavelengthfloat

Wavelength in angstroms.

lorentzbool

Whether to apply Lorentz correction.

min_dfloat, optional

Minimum d-spacing. Default is None.

copy_UB_from_Q()[source]#

Copy the UB matrix from the Q workspace to the cell workspace.

copy_UB_from_peaks()[source]#

Copy the UB matrix from the peaks workspace to the cell workspace.

copy_UB_to_Q()[source]#

Copy the UB matrix from the cell workspace to the Q workspace.

copy_UB_to_peaks()[source]#

Copy the UB matrix from the cell workspace to the peaks workspace.

delete_peaks(peaks)[source]#

Remove peaks.

Parameters:
peaksstr

Name of peaks table to be added.

determine_UB_with_lattice_parameters(a, b, c, alpha, beta, gamma, tol=0.1)[source]#

Determine UB with prior known lattice parameters.

Parameters:
a, b, cfloat

Lattice constants in angstroms.

alpha, beta, gammafloat

Lattice angles in degrees.

tolfloat, optional

Indexing tolerance. The default is 0.1.

determine_UB_with_niggli_cell(min_d, max_d, tol=0.1)[source]#

Determine UB with primitive lattice using min/max lattice constant.

Parameters:
min_dfloat

Minimum lattice parameter in ansgroms.

max_dfloat

Maximum lattice parameter in angstroms.

tolfloat, optional

Indexing tolerance. The default is 0.1.

extract_roi(horz, vert, horz_roi, vert_roi, val)[source]#

Extract a region of interest (ROI) from the instrument view.

Parameters:
horz, vertfloat

Horizontal and vertical coordinates for the ROI center.

horz_roi, vert_roifloat

Horizontal and vertical ROI sizes.

valfloat

Value at the ROI center.

Returns:
dict

Extracted ROI data including label, x, and y values.

filter_peaks(name, operator, value)[source]#

Filter out peaks based on value and operator.

Parameters:
namestr

Filter name.

operatorfloat

Filter operator.

valuefloat

The filter value.

find_peaks(min_dist, density=1000, max_peaks=50, edge_pixels=0)[source]#

Harvest strong peak locations from Q-sample into a peaks table.

Parameters:
min_distfloat

Minimum distance enforcing lower limit of peak spacing.

densityint, optional

Threshold density. The default is 1000.

max_peaksint, optional

Maximum number of peaks to find. The default is 50.

edge_pixels: int, optional

Nnumber of edge pixels to exclude. The default is 0.

generate_lattice_transforms(cell)[source]#

Obtain possible transforms compatabile with a unit cell lattice.

Parameters:
cellstr

Latttice system.

Returns:
transformsdict

Transform dictionary with symmetry operation as key.

get_Q_info()[source]#

Extract Q-space information from the model.

Returns:
dict

Dictionary containing Q-space signal, min/max limits, spacing, and optionally x, y, z coordinates.

get_UB()[source]#

Retrieve the UB matrix from the oriented lattice.

Returns:
np.ndarray

3x3 UB matrix if present, else None.

get_all_goniometer_matrices(ws)[source]#

Extract all goniometer matrices.

Parameters:
wsstr

Name of workspace with goniometer indexing.

Returns:
Rs: list

Goniometer matrices.

get_calibration_file_path(instrument)[source]#

Get the calibration file path for a given instrument.

Parameters:
instrumentstr

Instrument identifier.

Returns:
str

Calibration file path.

get_cluster_info()[source]#

Get cluster information for peaks based on UB and peak table.

Returns:
dict

Dictionary with cluster coordinates, points, numbers, translation vectors, and transforms.

get_d_min()[source]#
get_goniometers(instrument)[source]#

Get goniometer settings for a given instrument.

Parameters:
instrumentstr

Instrument identifier.

Returns:
list

List of goniometer settings.

get_has_Q_vol()[source]#

Check if the Q volume data exists.

Returns:
bool

True if Q volume data exists, False otherwise.

get_instrument_name(instrument)[source]#

Get the instrument name string for a given instrument identifier.

Parameters:
instrumentstr

Instrument identifier.

Returns:
str

Instrument name.

get_lattice_constant_errors()[source]#

Get the errors in the lattice constants from the oriented lattice.

Returns:
list

List of errors in lattice constants [error_a, error_b, error_c, error_alpha, error_beta, error_gamma].

get_lattice_constants()[source]#

Get the lattice constants from the oriented lattice.

Returns:
list

List of lattice constants [a, b, c, alpha, beta, gamma].

get_max_d_spacing(ws)[source]#

Obtain the maximum d-spacing from the oriented lattice.

Parameters:
wsstr

Workspace with UB defined on oriented lattice.

Returns:
d_maxfloat

Maximum d-spacing.

get_modulation_info()[source]#
get_number_workspaces()[source]#

Get the number of workspaces in the current Mantid session.

Returns:
int

Number of workspaces.

get_peak(i)[source]#

Get a specific peak’s information by index.

Parameters:
iint

Index of the peak.

Returns:
dict or None

Peak information dictionary or None if index is out of range.

get_peak_info()[source]#

Extract detailed information for each peak in the current table.

Returns:
list of dict

List of dictionaries with peak properties (hkl, d-spacing, intensity, etc.).

get_raw_file_path(instrument)[source]#

Get the raw data file path for a given instrument.

Parameters:
instrumentstr

Instrument identifier.

Returns:
str

File path to raw data.

get_sample_directions()[source]#

Get the sample directions from the UB matrix.

Returns:
list

List of simplified sample direction vectors.

get_shared_file_path(instrument, ipts)[source]#

Get the shared file path for a given instrument and IPTS.

Parameters:
instrumentstr

Instrument identifier.

iptsstr

IPTS number.

Returns:
str

Shared file path.

get_slice_info(U, V, W, normal, value, thickness, width)[source]#

Get the slicing information for a given normal and value.

Parameters:
U, V, Wlist

Normalized direction cosines for the slice.

normallist

Normal vector for the slice.

valuefloat

Value at which to slice.

thicknessfloat

Thickness of the slice.

widthfloat

Width of the output histogram bins.

Returns:
dict

Dictionary with slice information including extents, bins, and transform.

get_vanadium_file_path(instrument)[source]#

Get the vanadium calibration file path for a given instrument.

Parameters:
instrumentstr

Instrument identifier.

Returns:
str

Vanadium calibration file path.

get_wavelength(instrument)[source]#

Get the wavelength for a given instrument.

Parameters:
instrumentstr

Instrument identifier.

Returns:
float

Wavelength in angstroms.

has_Q()[source]#

Check if the Q workspace exists in Mantid.

Returns:
bool

True if Q workspace exists, False otherwise.

has_UB()[source]#

Check if the UB matrix is defined on the sample.

Returns:
bool

True if UB matrix is present, False otherwise.

has_peaks()[source]#

Check if the peaks table exists in Mantid.

Returns:
bool

True if peaks table exists, False otherwise.

index_peaks(tol=0.1, sat_tol=None, mod_vec_1=[0, 0, 0], mod_vec_2=[0, 0, 0], mod_vec_3=[0, 0, 0], max_order=0, cross_terms=False, round_hkl=True)[source]#

Index the peaks and calculate the lattice parameter uncertainties.

Parameters:
tolfloat, optional

Indexing tolerance. The default is 0.1.

sat_tolfloat, optional

Satellite indexing tolerance. The default is None.

mod_vec_1, mod_vec_2, mod_vec_3list, optional

Modulation vectors. The default is [0,0,0].

max_orderint, optional

Maximum order greater than zero for satellites. The default is 0.

cross_termsbool, optional

Include modulation cross terms. The default is False.

round_hklbool, optional

Round integers to integer. The default is True.

Returns:
indexinglist

Result of indexing including number indexed and errors.

integrate_peaks(peak_radius, background_inner_fact=1, background_outer_fact=1.5, method='sphere', centroid=True)[source]#

Integrate peaks using spherical or ellipsoidal regions. Ellipsoid integration adapts itself to the peak distribution.

Parameters:
peak_radiusfloat

Integration region radius.

background_inner_factfloat, optional

Factor of peak radius for background shell. The default is 1.

background_outer_factfloat, optional

Factor of peak radius for background shell. The default is 1.5.

methodstr, optional

Integration method. The default is ‘sphere’.

centroidstr, optional

Shift peak position to centroid. The default is True.

is_sliced()[source]#

Check if the data has been sliced.

Returns:
bool

True if data is sliced, False otherwise.

load_Q(filename)[source]#

Load Q file.

Parameters:
filenamestr

Name of Q file with extension .nxs.

load_UB(filename)[source]#

Load UB from file.

Parameters:
filenamestr

Name of UB file with extension .mat.

load_data(instrument, IPTS, runs, exp, time_stop)[source]#

Load experimental data for a given instrument and run parameters.

Parameters:
instrumentstr

Instrument identifier.

IPTSstr

IPTS number.

runslist

List of run numbers.

expstr

Experiment identifier.

time_stopfloat

Time to stop loading data.

load_peaks(filename)[source]#

Load peaks file.

Parameters:
filenamestr

Name of peaks file (can be .nxs or .integrate, .peaks, etc.).

possible_conventional_cells(max_error=0.2, permutations=True)[source]#

List possible conventional cells.

Parameters:
max_errorfloat, optional

Max scalar error to report form numbers. The default is 0.2.

permutationsbool, optional

Allow permutations of the lattice. The default is True.

Returns:
valslist

List of form results.

predict_modulated_peaks(d_min, lamda_min, lamda_max, mod_vec_1=[0, 0, 0], mod_vec_2=[0, 0, 0], mod_vec_3=[0, 0, 0], max_order=0, cross_terms=False)[source]#

Predict the modulated peak positions based on main peaks.

Parameters:
centeringstr

Lattice centering that provides the reflection condition.

d_minfloat

The lower d-spacing resolution to predict peaks.

lamda_min, lamda_maxfloat

The wavelength band over which to predict peaks.

mod_vec_1, mod_vec_2, mod_vec_3list, optional

Modulation vectors. The default is [0,0,0].

max_orderint, optional

Maximum order greater than zero for satellites. The default is 0.

cross_termsbool, optional

Include modulation cross terms. The default is False.

predict_peaks(centering, d_min, lamda_min, lamda_max, edge_pixels=0)[source]#

Predict peak Q-sample locations with UB and lattice centering.

Symbol

Reflection condition

P

None

I

\(h+k+l=2n\)

F

\(h,k,l\) unmixed

R

None

R(obv)

\(-h+k+l=3n\)

R(rev)

\(h-k+l=3n\)

A

\(k+l=2n\)

B

\(l+h=2n\)

C

\(h+k=2n\)

Parameters:
centeringstr

Lattice centering that provides the reflection condition.

d_minfloat

The lower d-spacing resolution to predict peaks.

lamda_min, lamda_maxfloat

The wavelength band over which to predict peaks.

edge_pixels: int, optional

Nnumber of edge pixels to exclude. The default is 0.

predict_satellite_peaks(lamda_min, lamda_max, d_min, mod_vec_1=[0, 0, 0], mod_vec_2=[0, 0, 0], mod_vec_3=[0, 0, 0], max_order=0, cross_terms=False)[source]#

Locate satellite peaks from goniometer angles.

Parameters:
d_minfloat

The lower d-spacing resolution to predict peaks.

lamda_minfloat

Minimum wavelength.

lamda_maxfloat

Maximum wavelength.

mod_vec_1, mod_vec_2, mod_vec_3list, optional

Modulation vectors. The default is [0,0,0].

max_orderint, optional

Maximum order greater than zero for satellites. The default is 0.

cross_termsbool, optional

Include modulation cross terms. The default is False.

refine_UB_with_constraints(cell, tol=0.1)[source]#

Refine UB with constraints corresponding to lattice system.

Lattice system

Lengths

Angles

Cubic

\(a=b=c\)

\(α=β=γ=90\)

Hexagonal

\(a=b\)

\(α=β=90,γ=120\)

Rhombohedral

\(a=b=c\)

\(α=β=γ\)

Tetragonal

\(a=b\)

\(α=β=γ=90\)

Orthorhombic

None

\(α=β=γ=90\)

Monoclinic

None

\(α=γ=90\)

Triclinic

None

None

Parameters:
cellfloat

Lattice system.

tolfloat, optional

Indexing tolerance. The default is 0.1.

refine_UB_without_constraints(tol=0.1, sat_tol=None)[source]#

Refine UB with unconstrained lattice parameters.

Parameters:
tolfloat, optional

Indexing tolerance. The default is 0.1.

sat_tolfloat, optional

Satellite indexing tolerance. The default is None.

refine_U_only(a, b, c, alpha, beta, gamma)[source]#

Refine the U orientation only.

Parameters:
a, b, cfloat

Lattice constants in angstroms.

alpha, beta, gammafloat

Lattice angles in degrees.

remove_duplicate_peaks(peaks)[source]#

Omit duplicate peaks from different based on indexing. Table will be sorted.

Parameters:
peaksstr

Name of peaks table.

renumber_runs_by_index(ws, peaks)[source]#

Re-label the runs by index based on goniometer setting.

Parameters:
wsstr

Name of workspace with goniometer indexing.

peaksstr

Name of peaks table.

roi_scan_to_hkl(ind, val, horz, vert)[source]#

Convert a ROI scan position to HKL coordinates.

Parameters:
indint

Index of the run.

valfloat

Peak value (e.g., d-spacing or angle).

horzfloat

Horizontal coordinate (e.g., angle or hkl).

vertfloat

Vertical coordinate (e.g., angle or hkl).

Returns:
np.ndarray

Calculated HKL coordinates.

save_Q(filename)[source]#

Save Q file.

Parameters:
filenamestr

Name of Q file with extension .nxs.

save_UB(filename)[source]#

Save UB to file.

Parameters:
filenamestr

Name of UB file with extension .mat.

save_peaks(filename)[source]#

Save the current peaks table to a file.

Parameters:
filenamestr

Name of peaks file with extension .nxs.

select_cell(number, tol=0.1)[source]#

Transform to conventional cell using form number.

Parameters:
numberint

Form number.

tolfloat, optional

Indexing tolerance. The default is 0.1.

set_manual_UB(constants, directions)[source]#

Set the unit cell parameters and directions manually.

Parameters:
constantslist

List of unit cell parameters [a, b, c, alpha, beta, gamma].

directionslist

List of direction indices [u1, u2, u3, v1, v2, v3].

set_peak(i, hkl, int_hkl, int_mnp)[source]#

Set the HKL, integer HKL, and integer MNP values for a specific peak.

Parameters:
iint

Index of the peak.

hkllist

HKL coordinates.

int_hkllist

Integer HKL coordinates.

int_mnplist

Integer MNP coordinates.

simplify_vector(vec)[source]#

Simplify a vector to its primitive integer form.

Parameters:
vecnp.ndarray

Input vector.

Returns:
np.ndarray

Simplified integer vector.

sort_peaks_by_d(peaks)[source]#

Sort peaks table by descending d-spacing.

Parameters:
peaksstr

Name of peaks table.

sort_peaks_by_hkl(peaks)[source]#

Sort peaks table by descending hkl values.

Parameters:
peaksstr

Name of peaks table.

transform_lattice(transform, tol=0.1)[source]#

Apply a cell transformation to the lattice.

Parameters:
transform3x3 array-like

Transform to apply to hkl values.

tolfloat, optional

Indexing tolerance. The default is 0.1.

update_UB()[source]#

Update the UB matrix on the sample and synchronize with Mantid workspaces.

NeuXtalViz.models.utilities module#

class ParallelTasks(function, args)[source]#

Bases: object

Methods

run_tasks

run_tasks(values, n_proc)[source]#
SaveMDToAscii(workspace, filename, exclude_integrated=True, format='%.6e')[source]#

Save an MDHistoToWorkspace to an ASCII file (column format).

workspacestr

Name of workspace as string.

filenamestr

Path to output file.

exclude_integratedbool, optional

Exclude integrated dimensions with bin size of one. Default is True.

formatstr

Column format.

NeuXtalViz.models.volume_slicer module#

VolumeSlicerModel#

Model for handling 3D volume slicing, cutting, and histogram operations using Mantid workspaces.

This class provides methods to load, process, and extract slices and cuts from multidimensional histogram workspaces. It supports saving slices/cuts, checking workspace states, and computing transformations for visualization.

Attributes#

shapetuple

Shape of the loaded volume data.

min_limnp.ndarray

Minimum bounds for each dimension.

max_limnp.ndarray

Maximum bounds for each dimension.

labelslist

Axis labels for the volume.

spacingnp.ndarray

Bin widths for each dimension.

signalslist

Downsampled signal arrays for each axis.

spacingslist

Downsampled spacings for each axis.

Methods#

load_md_histo_workspace(filename)

Load and preprocess a Mantid MD histogram workspace.

save_slice(filename)

Save the current slice to an ASCII file.

save_cut(filename)

Save the current cut to an ASCII file.

is_histo_loaded()

Check if a histogram workspace is loaded.

is_sliced()

Check if a slice workspace exists.

is_cut()

Check if a cut workspace exists.

set_B()

Set the B matrix from the workspace UB.

set_W()

Set the W matrix from the workspace log.

get_histo_info(normal)

Get histogram info for a given normal.

get_slice_info(normal, value, thickness)

Get slice info for a given normal and value.

get_cut_info(axis, value, thickness)

Get cut info for a given axis and value.

calculate_clim(trans, method)

Calculate color limits for visualization.

orientation_matrix()

Compute the orientation matrix.

get_transform(reciprocal)

Get the transformation matrix.

get_transforms()

Get projection, transform, and scale matrices.

get_normal_plane(ind)

Get the normal vector for a plane.

class VolumeSlicerModel[source]#

Bases: NeuXtalVizModel

Methods

ab_axes()

\(c^*\)-direction in cartesian coordinates.

ab_star_axes()

\(c\)-direction in cartesian coordinates.

bc_axes()

\(a^*\)-direction in cartesian coordinates.

bc_star_axes()

\(a\)-direction in cartesian coordinates.

ca_axes()

\(b^*\)-direction in cartesian coordinates.

ca_star_axes()

\(b\)-direction in cartesian coordinates.

calculate_clim(trans[, method])

Calculate color limits for visualization based on a method.

get_cut_info(axis, value[, thickness])

Get cut information for a given axis and value.

get_histo_info(normal)

Get histogram information for a given normal direction.

get_normal_plane(ind)

Get the normal vector for a plane given an index vector.

get_oriented_lattice_parameters()

Obtain the oriented lattice parameters.

get_slice_info(normal, value[, thickness])

Get slice information for a given normal and value.

get_transform([reciprocal])

Get the transformation matrix for the current UB and W matrices.

get_transforms()

Get projection, transform, and scale matrices for the current UB and W.

get_vector(axes_type, ind)

Vector corresponding to a particular crystallographic direction.

has_UB(ws)

Check if the oriented lattice exists on a workspace.

is_cut()

Check if a cut workspace exists in Mantid.

is_histo_loaded()

Check if a histogram workspace is loaded in Mantid.

is_sliced()

Check if a slice workspace exists in Mantid.

load_md_histo_workspace(filename)

Load and preprocess a Mantid MD histogram workspace from a file.

orientation_matrix()

Compute the orientation matrix for the current UB and W matrices.

save_cut(filename)

Save the current cut workspace to an ASCII file.

save_slice(filename)

Save the current slice workspace to an ASCII file.

set_B()

Set the B matrix from the UB of the loaded histogram workspace.

set_UB(UB)

Update the UB-matrix.

set_W()

Set the W matrix from the workspace log if available, otherwise identity.

calculate_clim(trans, method='normal')[source]#

Calculate color limits for visualization based on a method.

Parameters:
transnp.ndarray

Array of values to calculate limits for.

methodstr, optional

Method for calculation: ‘normal’, ‘boxplot’, or ‘minmax’.

Returns:
np.ndarray

Array with values clipped to the calculated color limits.

get_cut_info(axis, value, thickness=0.01)[source]#

Get cut information for a given axis and value.

Parameters:
axisarray-like

Axis along which to cut (e.g., [1,0,0]).

valuefloat

Position along the axis to cut.

thicknessfloat, optional

Thickness of the cut (default 0.01).

Returns:
dict

Dictionary containing x, y, e, label, value, and title.

get_histo_info(normal)[source]#

Get histogram information for a given normal direction.

Parameters:
normalarray-like

Normal vector for the slicing direction.

Returns:
dict

Dictionary containing signal, limits, spacing, labels, and transforms.

get_normal_plane(ind)[source]#

Get the normal vector for a plane given an index vector.

Parameters:
indarray-like

Index vector for the plane.

Returns:
np.ndarray

Normal vector for the plane.

get_slice_info(normal, value, thickness=0.01)[source]#

Get slice information for a given normal and value.

Parameters:
normalarray-like

Normal vector for the slicing direction.

valuefloat

Position along the normal to slice.

thicknessfloat, optional

Thickness of the slice (default 0.01).

Returns:
dict

Dictionary containing x, y, labels, signal, transform, aspect, value, and title.

get_transform(reciprocal=True)[source]#

Get the transformation matrix for the current UB and W matrices.

Parameters:
reciprocalbool, optional

If True, return reciprocal transformation; else real space.

Returns:
np.ndarray

Transformation matrix.

get_transforms()[source]#

Get projection, transform, and scale matrices for the current UB and W.

Returns:
tuple

(projection, transform, scale) matrices.

is_cut()[source]#

Check if a cut workspace exists in Mantid.

Returns:
bool

True if ‘cut’ workspace exists, False otherwise.

is_histo_loaded()[source]#

Check if a histogram workspace is loaded in Mantid.

Returns:
bool

True if ‘histo’ workspace exists, False otherwise.

is_sliced()[source]#

Check if a slice workspace exists in Mantid.

Returns:
bool

True if ‘slice’ workspace exists, False otherwise.

load_md_histo_workspace(filename)[source]#

Load and preprocess a Mantid MD histogram workspace from a file.

Parameters:
filenamestr

Path to the Mantid MD histogram file to load.

orientation_matrix()[source]#

Compute the orientation matrix for the current UB and W matrices.

Returns:
np.ndarray

Orientation matrix.

save_cut(filename)[source]#

Save the current cut workspace to an ASCII file.

Parameters:
filenamestr

Output filename for the cut.

save_slice(filename)[source]#

Save the current slice workspace to an ASCII file.

Parameters:
filenamestr

Output filename for the slice.

set_B()[source]#

Set the B matrix from the UB of the loaded histogram workspace.

set_W()[source]#

Set the W matrix from the workspace log if available, otherwise identity.

Module contents#