diffcalc.util¶
Collection of auxiliary mathematical methods.
Functions
|
Check if all object types in the input sequence are either int or float. |
|
Angle between two column vectors. |
|
Check for angle equivalence in degrees. |
|
Check the input value is in [-1, 1] range. |
|
Cross product of column vectors. |
|
Dot product of column vectors. |
|
Check if input value is 0 within tolerance. |
|
Check if the input object type is either int or float. |
|
Normalise vector array. |
|
Sign function with specified tolerance. |
|
Find valid hkl for a given h and q value. |
|
Find valid hkl for a given k and q value. |
|
Find valid hkl for a given l and q value. |
|
Rotation matrix over x axis. |
|
Rotation matrix over arbitrary axis. |
|
Rotation matrix over y axis. |
|
Rotation matrix over z axis. |
|
Round to zero if small. |
Exceptions
Error caused by user misuse of diffraction calculator. |
- diffcalc.util.x_rotation(th: float) ndarray[source]¶
Rotation matrix over x axis.
- Parameters:
th (float) – Rotation angle.
- Returns:
Rotation matrix.
- Return type:
np.ndarray
- diffcalc.util.y_rotation(th: float) ndarray[source]¶
Rotation matrix over y axis.
- Parameters:
th (float) – Rotation angle.
- Returns:
Rotation matrix.
- Return type:
np.ndarray
- diffcalc.util.z_rotation(th: float) ndarray[source]¶
Rotation matrix over z axis.
- Parameters:
th (float) – Rotation angle.
- Returns:
Rotation matrix.
- Return type:
np.ndarray
- diffcalc.util.xyz_rotation(axis: Tuple[float, float, float], angle: float) ndarray[source]¶
Rotation matrix over arbitrary axis.
- Parameters:
axis (Tuple[float, float, float]) – Rotation axis coordinates
angle (float) – Rotation angle.
- Returns:
Rotation matrix.
- Return type:
np.ndarray
- exception diffcalc.util.DiffcalcException[source]¶
Error caused by user misuse of diffraction calculator.
- diffcalc.util.cross3(x: ndarray, y: ndarray) ndarray[source]¶
Cross product of column vectors.
- Parameters:
x (np.ndarray) – Column vector represented as NumPy (3,1) array.
y (np.ndarray) – Column vector represented as NumPy (3,1) array.
- Returns:
Cross product column vector as as NumPy (3,1) array.
- Return type:
np.ndarray
- diffcalc.util.dot3(x: ndarray, y: ndarray) float[source]¶
Dot product of column vectors.
- Parameters:
x (np.ndarray) – Column vector represented as NumPy (3,1) array.
y (np.ndarray) – Column vector represented as NumPy (3,1) array.
- Returns:
Dot product of column vectors.
- Return type:
float
- diffcalc.util.angle_between_vectors(x: ndarray, y: ndarray) float[source]¶
Angle between two column vectors.
- Parameters:
x (np.ndarray) – Column vector represented as NumPy (3,1) array.
y (np.ndarray) – Column vector represented as NumPy (3,1) array.
- Returns:
Angle between the vectors in degrees.
- Return type:
float
- diffcalc.util.bound(x: float) float[source]¶
Check the input value is in [-1, 1] range.
Rounds input value to +/-1 if |x| - 1 < SMALL.
- Parameters:
x (float) – Input value to be checked
- Returns:
Value in [-1, 1] range.
- Return type:
float
- Raises:
AssertionError – Input value outside [-1, 1] range.
- diffcalc.util.angles_equivalent(first: float, second: float, tolerance: float = 1e-07) bool[source]¶
Check for angle equivalence in degrees.
- Parameters:
first (float) – First angle value in degrees.
second (float) – Second angle value in degrees.
tolerance (float, default = SMALL) – Absolute tolerance for the angle difference.
- Returns:
True is angles are equivalent.
- Return type:
bool
- diffcalc.util.isnum(o: Any) bool[source]¶
Check if the input object type is either int or float.
- Parameters:
o (Any) – Input object to be checked.
- Returns:
If object type is either int or float.
- Return type:
bool
- diffcalc.util.allnum(lst: Sequence[Any]) bool[source]¶
Check if all object types in the input sequence are either int or float.
- Parameters:
o (Sequence[Any]) – Input object sequence to be checked.
- Returns:
If all object types in th sequence are either int or float.
- Return type:
bool
- diffcalc.util.is_small(x, tolerance=1e-07) bool[source]¶
Check if input value is 0 within tolerance.
- Parameters:
x (float) – Input value to be checked.
tolerance (float, default = SMALL) – Absolute tolerance.
- Returns:
True is the value is 0 within tolerance.
- Return type:
bool
- diffcalc.util.sign(x: float, tolerance: float = 1e-07) int[source]¶
Sign function with specified tolerance.
- Parameters:
x (float) – Function argument.
tolerance (float, default = SMALL) – Absolute tolerance.
- Returns:
1 for positive, -1 for negative values and 0 if argument equals 0 within tolerance.
- Return type:
int
- diffcalc.util.normalised(vector: ndarray) ndarray[source]¶
Normalise vector array.
Return normalised vector coordinates.
- Parameters:
vector (ndarray) – The vector to be normalised.
- Returns:
Normalised vector.
- Return type:
ndarray
- diffcalc.util.zero_round(num)[source]¶
Round to zero if small.
This is useful to get rid of erroneous minus signs resulting from float representation close to zero.
- Parameters:
num (number) – The value to be checked for rounding.
- Returns:
The rounded input value.
- Return type:
number
- diffcalc.util.solve_h_fixed_q(h: float, qval: float, B: ndarray, a: float, b: float, c: float, d: float) List[Tuple[float, float, float]][source]¶
Find valid hkl for a given h and q value.
- Coefficients are used to constrain solutions as:
a*h + b*k + c*l = d
- Parameters:
h (float) – value of h to use
qval (float) – norm of the scattering vector squared
B (np.ndarray) – 3x3 matrix, usually the UB matrix
a (float) – a coefficient to constrain the resulting hkl
b (float) – a coefficient to constrain the resulting hkl
c (float) – a coefficient to constrain the resulting hkl
d (float) – a coefficient to constrain the resulting hkl
- Returns:
list of possible hkl solutions
- Return type:
List[Tuple[float, float, float]]
- Raises:
DiffcalcException – If the divisor is 0, or the discriminant is negative. The first of these occurs if both b and c are equal to 0.
- diffcalc.util.solve_k_fixed_q(k: float, qval: float, B: ndarray, a: float, b: float, c: float, d: float) List[Tuple[float, float, float]][source]¶
Find valid hkl for a given k and q value.
- Coefficients are used to constrain solutions as:
a*h + b*k + c*l = d
- Parameters:
k (float) – value of k to use
qval (float) – norm of the scattering vector squared
B (np.ndarray) – 3x3 matrix, usually the UB matrix
a (float) – a coefficient to constrain the resulting hkl
b (float) – a coefficient to constrain the resulting hkl
c (float) – a coefficient to constrain the resulting hkl
d (float) – a coefficient to constrain the resulting hkl
- Returns:
list of possible hkl solutions
- Return type:
List[Tuple[float, float, float]]
- Raises:
DiffcalcException – If the divisor is 0, or the discriminant is negative. The first of these occurs if both a and c are equal to 0.
- diffcalc.util.solve_l_fixed_q(l: float, qval: float, B: ndarray, a: float, b: float, c: float, d: float) List[Tuple[float, float, float]][source]¶
Find valid hkl for a given l and q value.
- Coefficients are used to constrain solutions as:
a*h + b*k + c*l = d
- Parameters:
l (float) – value of l to use
qval (float) – norm of the scattering vector squared
B (np.ndarray) – 3x3 matrix, usually the UB matrix
a (float) – a coefficient to constrain the resulting hkl
b (float) – a coefficient to constrain the resulting hkl
c (float) – a coefficient to constrain the resulting hkl
d (float) – a coefficient to constrain the resulting hkl
- Returns:
list of possible hkl solutions
- Return type:
List[Tuple[float, float, float]]
- Raises:
DiffcalcException – If the divisor is 0, or the discriminant is negative. The first of these occurs if both a and b are equal to 0.