|
7 | 7 | import pytest |
8 | 8 | import coloredlogs |
9 | 9 |
|
10 | | - |
| 10 | +from hexrd.core import matrixutil as mutil |
| 11 | +from hexrd.core import rotations as rot |
11 | 12 | from hexrd.hedm import config |
12 | 13 | from hexrd.hedm.fitgrains import fit_grains |
13 | 14 |
|
14 | 15 |
|
15 | | -from fit_grains_check import compare_grain_fits |
16 | | - |
17 | | - |
18 | 16 | logger = logging.getLogger(__name__) |
19 | 17 | logger.setLevel(logging.INFO) |
20 | 18 |
|
@@ -73,6 +71,68 @@ def test_config(single_ge_config_path, single_ge_include_path): |
73 | 71 |
|
74 | 72 | return conf |
75 | 73 |
|
| 74 | +def compare_grain_fits( |
| 75 | + fit_grain_params, ref_grain_params, mtol=1.0e-4, ctol=1.0e-3, vtol=1.0e-4 |
| 76 | +): |
| 77 | + """ |
| 78 | + Executes comparison between reference and fit grain parameters for ff-HEDM |
| 79 | + for the same initial parameters. |
| 80 | +
|
| 81 | + Parameters |
| 82 | + ---------- |
| 83 | + fit_grain_params : array_like, (n, 12) |
| 84 | + The fit grain parameters to be tested. |
| 85 | + ref_grain_params : array_like, (n, 12) |
| 86 | + The reference grain parameters (see Notes below). |
| 87 | +
|
| 88 | + Returns |
| 89 | + ------- |
| 90 | + bool |
| 91 | + True is successful comparison |
| 92 | +
|
| 93 | + Notes |
| 94 | + ----- |
| 95 | + The fitgrains action currently returns |
| 96 | + grain_id, completeness, chisq, grain_params. |
| 97 | + We will have to assume that the grain_ids are in the *same order* as the |
| 98 | + reference, which can be enforces by running the comparison using the |
| 99 | + reference orientation list. |
| 100 | + """ |
| 101 | + fit_grain_params = np.atleast_2d(fit_grain_params) |
| 102 | + ref_grain_params = np.atleast_2d(ref_grain_params) |
| 103 | + cresult = False |
| 104 | + ii = 0 |
| 105 | + for fg, rg in zip(fit_grain_params, ref_grain_params): |
| 106 | + # test_orientation |
| 107 | + quats = rot.quatOfExpMap(np.vstack([fg[:3], rg[:3]]).T) |
| 108 | + ang, mis = rot.misorientation( |
| 109 | + quats[:, 0].reshape(4, 1), quats[:, 1].reshape(4, 1) |
| 110 | + ) |
| 111 | + if ang <= mtol: |
| 112 | + cresult = True |
| 113 | + else: |
| 114 | + logger.warning(f"orientations for grain {ii} do not agree.") |
| 115 | + return cresult |
| 116 | + |
| 117 | + # test position |
| 118 | + if np.linalg.norm(fg[3:6] - rg[3:6]) > ctol: |
| 119 | + logger.warning(f"centroidal coordinates for grain {ii} do not agree.") |
| 120 | + return False |
| 121 | + |
| 122 | + # test strain |
| 123 | + vmat_fit = mutil.symmToVecMV( |
| 124 | + np.linalg.inv(mutil.vecMVToSymm(fg[6:])), scale=False |
| 125 | + ) |
| 126 | + vmat_ref = mutil.symmToVecMV( |
| 127 | + np.linalg.inv(mutil.vecMVToSymm(rg[6:])), scale=False |
| 128 | + ) |
| 129 | + if np.linalg.norm(vmat_fit - vmat_ref, ord=1) > vtol: |
| 130 | + logger.warning(f"stretch components for grain {ii} do not agree.") |
| 131 | + return False |
| 132 | + |
| 133 | + # index grain id |
| 134 | + ii += 1 |
| 135 | + return cresult |
76 | 136 |
|
77 | 137 | def test_fit_grains( |
78 | 138 | single_ge_include_path, |
|
0 commit comments