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 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. |
|
Check for angle equivalence. |
|
Sign function with specified tolerance. |
|
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.
- 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.radians_equivalent(first: float, second: float, tolerance: float = 1e-07) bool[source]¶
Check for angle equivalence.
- Parameters
first (float) – First angle value.
second (float) – Second angle value.
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