glassure.utility module
- glassure.utility.calculate_f_mean_squared(composition: dict[str, float] | dict[str, int], q: ndarray, sf_source='hajdu') ndarray
Calculates the square of the mean form factor for a given composition over q.
- Parameters:
composition – dictionary with elements as key and abundances as relative numbers
q – Q value or numpy array with a unit of A^-1
sf_source – source of the scattering factors. Possible sources are ‘hajdu’ and ‘brown_hubbell’.
- glassure.utility.calculate_f_squared_mean(composition: dict[str, float] | dict[str, int], q: ndarray, sf_source: str = 'hajdu') ndarray
Calculates the mean of the squared form factors for a given composition for a given q vector.
- Parameters:
composition – dictionary with elements as key and abundances as relative numbers
q – Q value or numpy array with a unit of A^-1
sf_source – source of the scattering factors. Possible sources are ‘hajdu’ and ‘brown_hubbell’.
- Returns:
mean of the squared form factors
- glassure.utility.calculate_incoherent_scattering(composition: dict[str, float] | dict[str, int], q: ndarray, sf_source: str = 'hajdu') ndarray
Calculates compton/incoherent scattering for a given composition
- Parameters:
composition – dictionary with elements as key and abundances as relative numbers
q – Q value or numpy array with a unit of A^-1
sf_source – source of the scattering factors. Possible sources are ‘hajdu’ and ‘brown_hubbell’.
- Returns:
incoherent scattering array
- glassure.utility.calculate_s0(composition: dict[str, float] | dict[str, int], sf_source: str = 'hajdu') float
Calculates the I0 value for a given composition by extrapolating the coherent scattering factor to zero where I(Q) and the Compton scattering should have zero intensities.
- Parameters:
composition – dictionary with elements as keys and abundances as relative numbers
sf_source – source of the scattering factors. Possible sources are ‘hajdu’ and ‘brown_hubbell’.
- Returns:
I0 value
- glassure.utility.calculate_weighting_factor(composition: dict[str, float] | dict[str, int], element_1: str, element_2: str, q: ndarray, sf_source='hajdu')
Calculates the weighting factor for an element-element contribution in a given composition (e.g. for Si-O in SiO2)
- Parameters:
composition – dictionary with elements as key string and abundances as relative numbers
element_1 – string giving element 1
element_2 – string giving element 2
q – Q value or numpy array with a unit of A^-1
sf_source – source of the scattering factors. Possible sources are ‘hajdu’ and ‘brown_hubbell’.
- Returns:
weighting factor array
- glassure.utility.convert_density_to_atoms_per_cubic_angstrom(composition: dict[str, float] | dict[str, int], density: float) float
Converts densities given in g/cm3 into atoms per A^3
- Parameters:
composition – dictionary with elements as key and abundances as relative numbers
density – density in g/cm^3
- Returns:
density in atoms/A^3
- glassure.utility.convert_two_theta_to_q_space(pattern: Pattern, wavelength: float) Pattern
Returns a new pattern with the x-axis converted from two theta into q space
- glassure.utility.convert_two_theta_to_q_space_raw(two_theta: float | ndarray, wavelength: float) float | ndarray
Converts two theta values into q space
- glassure.utility.extrapolate_to_zero_linear(pattern: Pattern, y0: float = 0) Pattern
Extrapolates a pattern to (0, y0) using a linear function from the leftest point in the pattern
- Parameters:
pattern – input Pattern
y0 – y value at x = 0
- Returns:
new extrapolated Pattern (includes the original data)
- glassure.utility.extrapolate_to_zero_poly(pattern: Pattern, x_max: float, replace: bool = False, y0: float = 0) Pattern
Extrapolates a pattern to (0, y0) using a 2nd order polynomial:
\[y = a*(x-c)+b*(x-c)^2 + y0\]if the polynomial extrapolation hits the value of y0 (default=0) at an x value higher than zero all y values below this intersection will be set to y0.
- Parameters:
pattern – input pattern
x_max – defines the maximum x value within the polynomial will be fit
replace – boolean flag whether to replace the data values in the fitted region (default = False)
y0 – y value at x = 0
- Returns:
extrapolated Pattern
- glassure.utility.extrapolate_to_zero_spline(pattern: Pattern, x_max: float, smooth_factor: float | None = None, replace: bool = False, y0: float = 0) Pattern
Extrapolates a pattern to (0, y0) using a spline function. If the spline hits zero on the y-axis at an x value higher than 0 all values below this intersection will be set to zero
- Parameters:
pattern – input pattern
x_max – defines the maximum x value within the spline will be fitted to the input pattern. this parameter should be larger than the minimum of the pattern x
smooth_factor – defines the smoothing of the spline extrapolation please see numpy.UnivariateSpline manual for explanations
replace – boolean flag whether to replace the data values in the fitted region (default = False)
y0 – y value at x = 0
- Returns:
extrapolated Pattern (includes the original one)
- glassure.utility.extrapolate_to_zero_step(pattern: Pattern, y0: float = 0) Pattern
Extrapolates a pattern to (0, y0) by setting everything below the q_min of the pattern to y0 (default=0)
- Parameters:
pattern – input Pattern
y0 – y value at x = 0
- Returns:
extrapolated Pattern
- glassure.utility.normalize_composition(composition: dict[str, float] | dict[str, int]) dict[str, float]
normalizes elemental abundances to 1
- Parameters:
composition – dictionary with elements as key and abundances as relative numbers
- Returns:
normalized elemental abundances dictionary