srxraylib.util package
Submodules
srxraylib.util.chemical_formula module
Utilities for parsing and computing properties of chemical formulas.
- class srxraylib.util.chemical_formula.Element(symbol, name, atomicnumber, molweight)[source]
Bases:
object
- class srxraylib.util.chemical_formula.ElementInFormula(element, atomic_number, n_atoms, molecular_weight)[source]
Bases:
object
srxraylib.util.custom_distribution module
Custom probability distribution sampler via inverse CDF.
- class srxraylib.util.custom_distribution.CustomDistribution(pdf, sort=False, interpolation=False, transform=<function CustomDistribution.<lambda>>, seed=0)[source]
Bases:
objectdraws samples from a one dimensional probability distribution, by means of inversion of a discrete inverstion of a cumulative density function
the pdf can be sorted first to prevent numerical error in the cumulative sum this is set as default; for big density functions with high contrast, it is absolutely necessary, and for small density functions, the overhead is minimal
a call to this distibution object returns indices into density array
- property ndim
- property sum
cached sum of all pdf values; the pdf need not sum to one, and is imlpicitly normalized
srxraylib.util.data_structures module
Utility to mimic IGOR-like vector and matrix classes and functions.
- class srxraylib.util.data_structures.ScaledArray(np_array=array([], dtype=float64), scale=array([], dtype=float64))[source]
Bases:
objectStores a 1D array and the abscissas information. Constructor.
- Parameters:
np_array (numpy array) – The array to be stored.
scale (float) – The scale values (np_array and scale must have the same dimension).
- get_scale_value(index)[source]
Returns the scale at a particular index.
- Parameters:
index (int) –
- Return type:
float
- get_value(index)[source]
Gets the value for a given index.
- Parameters:
index (int) –
- Return type:
float
- classmethod initialize(np_array=array([], dtype=float64))[source]
Initializes a ScaledArray instance.
- Parameters:
np_array (numpy array) – The array to be stored.
- Return type:
ScaledArray instance
- classmethod initialize_from_range(np_array, min_scale_value, max_scale_value)[source]
- Parameters:
np_array (numpy array) – The array to be stored.
min_scale_value (float) –
max_scale_value (float) –
- Return type:
ScaledArray instance
- classmethod initialize_from_steps(np_array, initial_scale_value, scale_step)[source]
- Parameters:
np_array (numpy array) – The array to be stored.
initial_scale_value (float) –
scale_step (float) –
- Return type:
A ScaledArray instance.
- interpolate_scale_value(value)[source]
Interpolate only for monotonic np_array.
- Parameters:
value (float) –
- Return type:
float
- interpolate_value(scale_value)[source]
Get the interpolated value for a given scale or abscissas value.
- Parameters:
scale_value (int) –
- Return type:
float
- interpolate_values(scale_values)[source]
Get the interpolated values for given scale or abscissas values.
- Parameters:
scale_values (numpy array) –
- Return type:
numpy array
- set_scale_from_range(min_scale_value, max_scale_value)[source]
Equivalent to the IGOR command: SetScale /I (wave, min value, max value).
- Parameters:
min_scale_value (float) –
max_scale_value (float) –
- set_scale_from_steps(initial_scale_value, scale_step)[source]
Equivalent to the IGOR command: SetScale /P (wave, offset, step).
- Parameters:
initial_scale_value (float) –
scale_step (float) –
- class srxraylib.util.data_structures.ScaledMatrix(x_coord=array([], dtype=float64), y_coord=array([], dtype=float64), z_values=array([], shape=(0, 0), dtype=float64), interpolator=False)[source]
Bases:
objectScaledMatrix stores a 2D array and its axes. Constructor.
- Parameters:
x_coord (numpy array) – the array for X.
y_coord (numpy array) – the array for Y.
z_values (numpy array) – the 2D array for Z.
interpolator (boolean, optional) – True means that the interpolator has been calculates and it is ready. False means that is not ready. interpolator=True means that the interpolator is up to date and stored in the interpolated value. interpolator must be changed to False when something of the data is changed. When interpolation is required, compute_interpolator() is called. Withouth loss of generality, Wavefront2D can always be initialize with interpolator=False. Then it will be switched on when needed. It has been implemented for saving time: the interpolator is recomputed only if needed.
- get_x_value(index)[source]
Returns the X value for a given index.
- Parameters:
index (int) –
- Return type:
float
- get_y_value(index)[source]
Returns the Y value for a given index.
- Parameters:
index (int) –
- Return type:
float
- get_z_value(x_index, y_index)[source]
Returns the Z (2D array) value for given X,Y indices.
- Parameters:
x_index (int) – The index for axis 0.
y_index (int) – The index for axis 1.
- Return type:
float
- classmethod initialize(np_array_z=array([], shape=(0, 0), dtype=float64), interpolator=False)[source]
Initialize a ScaledMatrix instance from a 2D array. :param np_array_z: The 2D array. :type np_array_z: numpy array :param interpolator: True means that the interpolator has been calculates and it is ready. False means that is not ready. :type interpolator: boolean, optional
- Return type:
ScaledMatrix instance
- classmethod initialize_from_range(np_array, min_scale_value_x, max_scale_value_x, min_scale_value_y, max_scale_value_y, interpolator=False)[source]
Initializes a ScaledMatrix instance from a 2D array and the range of the axes.
- Parameters:
np_array (numpy array) – The 2D array.
min_scale_value_x (float) –
max_scale_value_x (float) –
min_scale_value_y (float) –
max_scale_value_y (float) –
interpolator (boolean, optional) – True means that the interpolator has been calculates and it is ready. False means that is not ready.
- Return type:
ScaledMatrix instance
- classmethod initialize_from_steps(np_array, initial_scale_value_x, scale_step_x, initial_scale_value_y, scale_step_y, interpolator=False)[source]
Initializes a ScaledMatrix instance from a 2D array and the steps of the axes.
- Parameters:
np_array (numpy array) – The 2D array.
initial_scale_value_x (float) –
scale_step_x (float) –
initial_scale_value_y (float) –
scale_step_y (float) –
interpolator (boolean, optional) – True means that the interpolator has been calculates and it is ready. False means that is not ready.
- Return type:
ScaledMatrix instance
- interpolate_value(x_coord, y_coord)[source]
Gives the Z value interpolated at given coordinates (x_coord, y_coord).
- Parameters:
x_coord (float) – The coordinate at axis 0.
y_coord (float) – The coordinate at axis 1.
- Return type:
float
- is_complex_matrix()[source]
Returns True if the data stored is of complex type.
- Return type:
boolean
- set_scale_from_range(axis, min_scale_value, max_scale_value)[source]
Equivalent to the IGOR command: SetScale /I (wave, min value, max value).
- Parameters:
axis (int) –
min_scale_value (float) –
max_scale_value (float) –
- set_scale_from_steps(axis, initial_scale_value, scale_step)[source]
Equivalent to the IGOR command: SetScale /P (wave, min value, max value).
- Parameters:
axis (int) –
initial_scale_value (float) –
scale_step (float) –
- set_z_value(x_index, y_index, z_value)[source]
Sets a given Z value at given indices.
- Parameters:
x_index (int) – The index for axis 0.
y_index (int) – The index for axis 1.
z_value (float) – The value to be stored.
- set_z_values(new_value)[source]
Sets a given 2D array.
- Parameters:
new_value (numpy array) – The 2D array.
- x_coord = None
- y_coord = None
- z_values = None
srxraylib.util.h5_simple_writer module
srxraylib.util.histograms module
Histogram utilities for beam and profile data analysis.
srxraylib.util.inverse_method_sampler module
Classes for creating random points following a given numeric distribution using the inverse method. Covers 1D, 2D and 3D sampling.
See tests for examples of use.
- class srxraylib.util.inverse_method_sampler.Sampler1D(pdf, pdf_x=None, cdf_interpolation_factor=1)[source]
Bases:
objectConstructor.
- Parameters:
pdf (numpy array) – 1D input probability distrubution function.
pdf_x (numpy array) – the abscissas of the odf.
cdf_interpolation_factor (float, optional) – interpolation factor for calculating the cdf (1 makes no interpolation)/
- abscissas()[source]
Gets the abscissas array.
- Returns:
The abscissas array (referenced, not copied).
- Return type:
numpy array
- cdf()[source]
Gets the cumulative distribution function (cdf).
- Returns:
The cdf (referenced, not copied).
- Return type:
numpy array
- cdf_abscissas()[source]
Gets the abscissas of the cumulative distribution function (cdf).
- Returns:
The cdf abscissas (referenced, not copied).
- Return type:
numpy array
- get_n_sampled_points(npoints, seed=None)[source]
Returns a given number points sampled points sampled with the pdf.
- Parameters:
npoints (int) – The number of points.
seed (int, optional) – The seed (numpy generator is initialized with numpy.random.default_rng(seed))
- Returns:
The sampled points.
- Return type:
numpy array
- get_n_sampled_points_and_histogram(npoints, bins=51, range=None, seed=None)[source]
Returns a given number points sampled points sampled with the pdf and the histogram.
- Parameters:
npoints (int) – The number of points.
seed (int, optional) – The seed (numpy generator is initialized with numpy.random.default_rng(seed))
bins (int, optional) – Number of bins
range (list or tuple) – [min, max] the histogram limits.
- Returns:
(s1, h, bin_edges) s1: the points sampled with the current pdf. The number of points is equal to the dimension of random_in_0_1, h: the array with the histogram values at the bin edges, bin_edges: the bin edges.
- Return type:
tuple
- get_sampled(random_in_0_1)[source]
Return an array with sampled points.
- Parameters:
random_in_0_1 (float or numpy array) – Points sampled in a uniform interval.
- Returns:
the points sampled with the current pdf. The number of points is equal to the dimension of random_in_0_1.
- Return type:
numpy array
- get_sampled_and_histogram(random_in_0_1, bins=51, range=None)[source]
Return an array with sampled points and the histogram.
- Parameters:
random_in_0_1 (float or numpy array) –
Points sampled in a uniform interval. bins : int, optional
Number of bins
- rangelist or tuple
[min, max] the histogram limits.
- Returns:
(s1, h, bin_edges) s1: the points sampled with the current pdf. The number of points is equal to the dimension of random_in_0_1, h: the array with the histogram values at the bin edges, bin_edges: the bin edges.
- Return type:
tuple
- class srxraylib.util.inverse_method_sampler.Sampler2D(pdf, pdf_x0=None, pdf_x1=None)[source]
Bases:
objectConstructor.
- Parameters:
pdf (numpy array) – the 2D pdf.
pdf_x0 (numpy array) – A 1D array with the abscissas for axis 0.
pdf_x1 (numpy array) – A 1D array with the abscissas for axis 1.
- abscissas()[source]
Gets the abscisas arrays.
- Returns:
(x0, x1) The arrays for axes 0 and 1.
- Return type:
tuple
- cdf()[source]
Gets the array with cumulated distribution function (cdf).
- Returns:
The cdf array (referenced, not copied).
- Return type:
numpy array
- get_n_sampled_points(npoints, seed=None)[source]
Samples n points (two coordinates) following the given pdf.
- Parameters:
npoints (int) – The number of points.
seed (int, optional) – The seed (numpy generator is initialized with numpy.random.default_rng(seed))
- Returns:
(x,y) the coordinates x (float or array) and y (float or array) of the sampled point(s).
- Return type:
tuple
- get_n_sampled_points_x2(npoints, seed=None)[source]
Samples n points (two coordinates, two times the second axis) following the given pdf.
- Parameters:
npoints (int) – The number of points.
seed (int, optional) – The seed (numpy generator is initialized with numpy.random.default_rng(seed))
- Returns:
(x, y0, y1) the coordinates x (float or array) on the axis 0 and and y0, y1 (float or array) of the sampled point(s) on axis 1.
- Return type:
tuple
- get_sampled(random0, random1)[source]
Samples a point or multiple points in 2D (two coordinates) following the given pdf.
- Parameters:
random0 (float or numpy array) – The 1D array with values unifiormly samples in [0,1]
random1 (float or numpy array) – The 1D array with values unifiormly samples in [0,1]
- Returns:
(x,y) the coordinates x (float or array) and y (float or array) of the sampled point(s).
- Return type:
tuple
- get_sampled_x2(random0, random10, random11)[source]
Samples a point or multiple points in 2D (two coordinates) following the given pdf. It samples one point in axis 0 and two points on the axis 1.
- Parameters:
random0 (float or numpy array) – The 1D array with values unifiormly samples in [0,1]
random10 (float or numpy array) – The 1D array with values unifiormly samples in [0,1]
random11 (float or numpy array) – The 1D array with values unifiormly samples in [0,1]
- Returns:
(x, y0, y1) the coordinates x (float or array) on the axis 0 and and y0, y1 (float or array) of the sampled point(s) in axis 1.
- Return type:
tuple
- class srxraylib.util.inverse_method_sampler.Sampler3D(pdf, pdf_x0=None, pdf_x1=None, pdf_x2=None)[source]
Bases:
objectConstructor.
- Parameters:
pdf (numpy array) – The 3D pdf.
pdf_x0 (numpy array) – The abscissas for axis 0.
pdf_x1 (numpy array) – The abscissas for axis 1.
pdf_x2 (numpy array) – The abscissas for axis 2.
- abscissas()[source]
Gets the arrays with the abscissas.
- Returns:
(x0, x1, x2) The arrays with the abscissas for axes 1, 2, and 3.
- Return type:
tuple
- cdf()[source]
Gets the array with cumulative distribution function (cdf).
- Returns:
The cdf array (referenced, not copied).
- Return type:
numpy array
- get_n_sampled_points(npoints, seed=None)[source]
Get a given number of sampled 3D points.
- Parameters:
npoints (int) – The number of points.
seed (int, optional) – The seed (numpy generator is initialized with numpy.random.default_rng(seed))
- Returns:
(x,y,z) the coordinates x (float or array), y (float or array) and z (float or array) of the sampled point(s).
- Return type:
tuple
- get_sampled(random0, random1, random2)[source]
Get sampled 3D points.
- Parameters:
random0 (float or numpy array) – The points or points sampled uniformly in a [0,1] interval.
random1 (float or numpy array) – The points or points sampled uniformly in a [0,1] interval.
random2 (float or numpy array) – The points or points sampled uniformly in a [0,1] interval.
- Returns:
(x0,x1,x2) the coordinates (float or array) of the sampled points.
- Return type:
tuple
srxraylib.util.random_distributions module
Random number generation with arbitrary probability distributions.
- class srxraylib.util.random_distributions.Container3D(width, height, depth)[source]
Bases:
Container
- class srxraylib.util.random_distributions.Distribution2D(prob_matrix, min_corner, max_corner)[source]
Bases:
object
- class srxraylib.util.random_distributions.Grid1D(dims, initial_item=None)[source]
Bases:
Container1D,PrincipleContainer
- class srxraylib.util.random_distributions.Grid2D(dims, initial_item=None)[source]
Bases:
Container2D,PrincipleContainer
- class srxraylib.util.random_distributions.Grid3D(dims, initial_item=None)[source]
Bases:
Container3D,PrincipleContainer
- class srxraylib.util.random_distributions.GridBar3D(grid, x, y, z)[source]
Bases:
Container1D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridCol2D(grid, col, row_slice)[source]
Bases:
Container1D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridCol3D(grid, x, y, z)[source]
Bases:
Container1D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridRow2D(grid, col_slice, row)[source]
Bases:
Container1D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridRow3D(grid, x, y, z)[source]
Bases:
Container1D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridSliceXY(grid, x, y, z)[source]
Bases:
Container2D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridSliceXZ(grid, x, y, z)[source]
Bases:
Container2D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridSliceYZ(grid, x, y, z)[source]
Bases:
Container2D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridWindow1D(grid, col_slice)[source]
Bases:
Container1D,AuxiliaryContainer
- class srxraylib.util.random_distributions.GridWindow2D(grid, x, y)[source]
Bases:
Container2D
- class srxraylib.util.random_distributions.GridWindow3D(grid, x, y, z)[source]
Bases:
Container3D,AuxiliaryContainer
- class srxraylib.util.random_distributions.ResponseCurve(inputMin, inputMax, outputSamples)[source]
Bases:
object
- class srxraylib.util.random_distributions.XYResponseCurve(inputSamples, outputSamples)[source]
Bases:
object
srxraylib.util.threading module
Threading utilities for parallel calculations.